# How to create document with dynamic schema over Java API?

**URL:** <https://forum.opensearch.org/t/how-to-create-document-with-dynamic-schema-over-java-api/14620>\
**Category:** OpenSearch Client Libraries\
**Tags:** opensearch-java\
**Created:** [June 9, 2023, 5:07pm UTC](https://forum.opensearch.org/t/how-to-create-document-with-dynamic-schema-over-java-api/14620 "2023-06-09T17:07:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evan](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@Evan](https://forum.opensearch.org/u/Evan)\
**Post date:** [June 9, 2023, 5:07pm UTC](https://forum.opensearch.org/t/how-to-create-document-with-dynamic-schema-over-java-api/14620/1 "2023-06-09T17:07:49Z")

</div>

**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** :

---

<div class="post-metadata">

**Author:** ![wbeckler](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@wbeckler](https://forum.opensearch.org/u/wbeckler)\
**Post date:** [June 9, 2023, 6:29pm UTC](https://forum.opensearch.org/t/how-to-create-document-with-dynamic-schema-over-java-api/14620/2 "2023-06-09T18:29:21Z")

</div>

Would you be willing to open an issue here: [Issues · opensearch-project/opensearch-java · GitHub](https://github.com/opensearch-project/opensearch-java/issues)  
suggesting the interface that would make the most sense?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)\
**Post date:** [August 8, 2023, 6:29pm UTC](https://forum.opensearch.org/t/how-to-create-document-with-dynamic-schema-over-java-api/14620/3 "2023-08-08T18:29:50Z")

</div>

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