How to POST multiple documents at a time using Elastic RestClient

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?

Endpoint should be

/myindex/mydoc/_bulk

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}

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

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