Elasticsearch Bulk Update API failing due to wrong input

Hi All,

Could you please let me if the below scenario is whether expected behaviour.

Scenario:

POST _bulk
{ "update" : { "_index" : "test", "_type" : "_doc", "_id" : "2" } }
{ "doc" : {"field2" : "value2"} }
{ "update" : { "_index" : "test", "_type" : "_doc", "_id" : "3" } }
{ "doc" : {"field2" : "value2"} }
{ "update" : { "_index" : "test", "_type" : "_doc", "_id" : "4" } }
{ "doc" : {"field2" : "value2"} ,}

When I am trying to execute above api, complete process is failing.
I was expecting like, only updating of doc with Id: 4 should be failed.
But its failing for all the other docs even.

Could someone provide some inputs on this please.

Thanks,
Ram Prasad G

Hi David,

thank you for updating format of my post, I tried while framing but it didn't worked.
Any inputs on my question will be very helpful.

Thanks,
Ram Prasad G

When you use the Bulk API, you are using a application/x-ndjson content type. You must conform with that specification.

The request is malformed so it can not be read by Elasticsearch which rejects the whole with:

$ curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@test.bulk"; echo
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character ('}' (code 125)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@c42c633; line: 1, column: 35]"}],"type":"json_parse_exception","reason":"Unexpected character ('}' (code 125)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@c42c633; line: 1, column: 35]"},"status":500}

You need to respect the specification. There's no workaround this AFAIK.

1 Like

Thank you David. It helped me.

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