# How to insert data into ElasticSearch from a json file using Java Bulk API?

**URL:** <https://discuss.elastic.co/t/how-to-insert-data-into-elasticsearch-from-a-json-file-using-java-bulk-api/90853>\
**Category:** Elasticsearch\
**Created:** [June 26, 2017, 4:29pm UTC](https://discuss.elastic.co/t/how-to-insert-data-into-elasticsearch-from-a-json-file-using-java-bulk-api/90853 "2017-06-26T16:29:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)\
**Post date:** [June 26, 2017, 4:29pm UTC](https://discuss.elastic.co/t/how-to-insert-data-into-elasticsearch-from-a-json-file-using-java-bulk-api/90853/1 "2017-06-26T16:29:15Z")

</div>

I have been looking for a definite answer but couldn't find one.  
The java bulk api example given expects us to write individual docs into index/type/id.  
How to use it to insert data directly from json file?

My json file is as follows:

```
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 26, 2017, 4:43pm UTC](https://discuss.elastic.co/t/how-to-insert-data-into-elasticsearch-from-a-json-file-using-java-bulk-api/90853/2 "2017-06-26T16:43:57Z")

</div>

If you have a file then I'd recommend using the REST Client instead and POST the file content to \_bulk endpoint.

I don't think you can do that with the Java high level client (REST or Transport).  
Might be wrong though but AFK ATM.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 24, 2017, 4:44pm UTC](https://discuss.elastic.co/t/how-to-insert-data-into-elasticsearch-from-a-json-file-using-java-bulk-api/90853/3 "2017-07-24T16:44:11Z")

</div>

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