Unable to update in bulk

curl -X POST -d "{"index":{"_index":"products","type":"shoes","_id":"3"}}{"name":"Puma","size":"9","color":"black"}\n{"index":{"_index":"products","_type":"shoes","_id":"4"}}{"name":"New Balance","size":"8","color":"black"}" -X POST "http://localhost:9200/_bulk?pretty"
{
"error" : {
"root_cause" : [
{
"type" : "action_request_validation_exception",
"reason" : "Validation Failed: 1: no requests added;"
}
],
"type" : "action_request_validation_exception",
"reason" : "Validation Failed: 1: no requests added;"
},
"status" : 400
}

Read that bulk must have entries in new line hence, tried \n however, still getting the error. Kindly advise.

The first line is missing _ in the _type parameter, you need to use real new lines instead of \n characters and as it is outlined in on this documentation page

If you’re providing text file input to curl, you must use the --data-binary flag instead of plain -d. The latter doesn’t preserve newlines.

You might also find is easier to store bulk requests in a separate file, or use Kibana console to work with elasticsearch.

Hi Igor,

You are correct. Thank you for pointing that out. I had missed _ for type in the first line. Corrected the command however, still getting the same error -

curl -X POST --data-binary "{"index":{"_index":"products","_type":"shoes","_id":"3"}}{"name":"Puma","size":"9","color":"black"},{"index":{"_index":"products","_type":"shoes","_id":"4"}}{"name":"New Balance","size":"8","color":"black"}" -H "Content-type: application/json" -X POST "http://localhost:9200/_bulk?pretty"

{
"error" : {
"root_cause" : [
{
"type" : "action_request_validation_exception",
"reason" : "Validation Failed: 1: no requests added;"
}
],
"type" : "action_request_validation_exception",
"reason" : "Validation Failed: 1: no requests added;"
},
"status" : 400
}

What did this error mean? Request your advise.

Please also check the NOTE on the same doc page, you are missing new lines between commands and after the last command.

curl -X POST --data-binary '{"index":{"_index":"products","_type":"shoes","_id":"3"}}
{"name":"Puma","size":"9","color":"black"}
{"index":{"_index":"products","_type":"shoes","_id":"4"}}
{"name":"New Balance","size":"8","color":"black"}
' -H "Content-type: application/json" -X POST "http://localhost:9200/_bulk?pretty"

You are correct. I am having a trouble understanding how to introduce a newline character when I type this command from command prompt of the Windows machine -

curl -X POST --data-binary "{"index":{"_index":"products","_type":"shoes","_id":"3"}},{"name":"Puma","size":"9","color":"black"}, (<---- I need a newline character here)
{"index":{"_index":"products","_type":"shoes","_id":"4"}},(<----- I need a newline character here)
{"name":"New Balance","size":"8","color":"black"}" -H "Content-type: application/x-ndjson" -X POST "http://localhost:9200/_bulk?pretty"

I tried even using "x-ndjson" as specified in the document but it did not work. Kindly help how do I do it?

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