# How to POST multiple documents at a time using Elastic RestClient

**URL:** <https://discuss.elastic.co/t/how-to-post-multiple-documents-at-a-time-using-elastic-restclient/135793>\
**Category:** Elasticsearch\
**Created:** [June 13, 2018, 8:53pm UTC](https://discuss.elastic.co/t/how-to-post-multiple-documents-at-a-time-using-elastic-restclient/135793 "2018-06-13T20:53:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suryatejreddy](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@Suryatejreddy](https://discuss.elastic.co/u/Suryatejreddy)\
**Post date:** [June 13, 2018, 8:53pm UTC](https://discuss.elastic.co/t/how-to-post-multiple-documents-at-a-time-using-elastic-restclient/135793/1 "2018-06-13T20:53:58Z")

</div>

I am trying to POST data into elastic search using this below code in java.

Response indexResponse = restClient.performRequest("POST",  
"/myindex/mydoc/",  
Collections.\<String, String\>emptyMap(), entity);

My entity is JSON file which is like [{...},{...},{...}].

But I am getting below error:  
{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"failed to parse"}],"type":"mapper\_parsing\_exception","reason":"failed to parse","caused\_by":{"type":"not\_x\_content\_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}},"status":400}.

I think the issue is in creating multiple documents at a time, can we do this using bulk API? how?

---

<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 14, 2018, 2:22am UTC](https://discuss.elastic.co/t/how-to-post-multiple-documents-at-a-time-using-elastic-restclient/135793/2 "2018-06-14T02:22:35Z")

</div>

Endpoint should be

```
/myindex/mydoc/_bulk
```

---

<div class="post-metadata">

**Author:** ![Suryatejreddy](https://avatars.discourse-cdn.com/v4/letter/s/e9bcb4/32.png) [@Suryatejreddy](https://discuss.elastic.co/u/Suryatejreddy)\
**Post date:** [June 14, 2018, 2:04pm UTC](https://discuss.elastic.co/t/how-to-post-multiple-documents-at-a-time-using-elastic-restclient/135793/3 "2018-06-14T14:04:35Z")

</div>

I tried this. but then I get this below error.

{"error":{"root\_cause":[{"type":"illegal\_argument\_exception","reason":"The bulk request must be terminated by a newline [\n]"}],"type":"illegal\_argument\_exception","reason":"The bulk request must be terminated by a newline [\n]"},"status":400}

---

<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 14, 2018, 3:10pm UTC](https://discuss.elastic.co/t/how-to-post-multiple-documents-at-a-time-using-elastic-restclient/135793/4 "2018-06-14T15:10:34Z")

</div>

Then you need to make sure your payload matches the definition of NDJSON. See [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)

---

<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 12, 2018, 3:10pm UTC](https://discuss.elastic.co/t/how-to-post-multiple-documents-at-a-time-using-elastic-restclient/135793/5 "2018-07-12T15:10:40Z")

</div>

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