How to create document with dynamic schema over Java API?

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

dependencies {
implementation ‘org.opensearch.client:opensearch-rest-client: 2.7.0’
implementation ‘org.opensearch.client:opensearch-java:2.4.0’
}

Describe the issue:

List opsList = new ArrayList<>();

	for (JSONObject event : events) {
		BulkOperation op = new BulkOperation.Builder().create(o -> o
                .index(indexName.toLowerCase())
                .document(event)
        ).build();
        opsList.add(op);
	}
	
	BulkRequest bulkRequest = new BulkRequest.Builder().operations(opsList).build();
            BulkResponse bulkResponse = client.bulk(bulkRequest);

Here, I am trying to create new documents. Instead of using a customer class, I am using the json as the document input.
BulkOperation op = new BulkOperation.Builder().create(o → o.index(indexName.toLowerCase()).document(event)

The document will be created without any content.
Do I have to use a customer class here for opensearch?
For elastic search, it works fine.

Configuration:

Relevant Logs or Screenshots:

Would you be willing to open an issue here: Issues · opensearch-project/opensearch-java · GitHub
suggesting the interface that would make the most sense?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.