Elastic search Bulk Post testing

Getting below error when doing testing on my local environment. Please someone help me where I did the mistake.

curl -XPOST 'localhost:9014/customer/external/_bulk?pretty' -d '
{"index":{{"_id":"15"}}
{"account_number":995,"balance":21153,"firstname":"Phelps","lastname":"Parrish","age":25,"gender":"M","address":"666 Miller Place","employer":"Pearlessa","email":"phelpsparrish@pearlessa.com","city":"Brecon","state":"ME"}'
{
"error" : "JsonParseException[Unexpected character ('{' (code 123)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: [B@543fb89e; line: 1, column: 12]]",
"status" : 500
}

This error is becuase the request contains invalid JSON. Remove the extra { before "_id" and the error should be resolved.

Adding to this that you MUST add a line return after last bulk.

1 Like

Please give some example from the above data. As I tried by removing { from the command, now it failed with Validation. Then I checked with json-validator, it show some error with same { brace.

I just downloaded the json that mentioned on the elastic document page.

current error :

curl -XPOST 'localhost:9014/customer/external/_bulk?pretty' -d '
{"index":{"_id":"15"}}
{"account_number":995,"balance":21153,"firstname":"Phelps","lastname":"Parrish","age":25,"gender":"M","address":"666 Miller Place","employer":"Pearlessa","email":"phelpsparrish@pearlessa.com","city":"Brecon","state":"ME"}'
{
"error" : "ActionRequestValidationException[Validation Failed: 1: no requests added;]",
"status" : 400
}

You need to add a new line to the end of the request as mentioned by @dadoonet.

curl -XPOST 'localhost:9014/customer/external/_bulk?pretty' -d '
{"index":{"_id":"15"}}
{"account_number":995,"balance":21153,"firstname":"Phelps","lastname":"Parrish","age":25,"gender":"M","address":"666 Miller Place","employer":"Pearlessa","email":"phelpsparrish@pearlessa.com","city":"Brecon","state":"ME"}
'

Great ! Thank You . Its worked. :smile: