Ervin Casiguran
Ervin Casiguran

Reputation: 13

Elasticsearch / Curl won't read newline for Bulk API

I'm currently running windows 10, and using curl_7_47_1_openssl_nghttp2_x64 in cmd.exe, my problem is whenever I try to input a data using bulk API in elasticsearch, I always get this error:

Validation Failed 1: no requests added,

I have already researched how to properly send data using the bulk API (add new line for every input) but cURL won't just read my break line statement. My full command is as follows:

curl -XPOST localhost:9200/customer/external/_bulk?pretty --data-binary "{ \"index\": {\"_id\": \"1\"}} \n { \"name\": \"John Doe\" } \n {\"index\": {\"_id\": \"2\"}} \n {\"name\": \"Jane Doe\" }"

Additionally other information include: cURL doesn't read single quotes in windows and I escape the double quotes in the jSON.

Thank you

Upvotes: 1

Views: 3486

Answers (1)

Val
Val

Reputation: 217354

You have two solutions:

You can store the bulk query in a file. Make sure:

  • double quotes are NOT escaped and also
  • each line (also the last one) ends with a newline (NOT the newline character \n, but a real newline)

bulk.json:

{"index": {"_id": "1"}}
{"name": "John Doe" }
{"index": {"_id": "2"}}
{"name": "Jane Doe" }

Then you can run this command

curl -XPOST localhost:9200/customer/external/_bulk?pretty --data-binary @/path/to/your/file

The other solution is to simply inline the same data you have but send it with the -d parameter instead of --data-binary which is used to send files.

curl -XPOST localhost:9200/customer/external/_bulk?pretty -d "
{\"index\": {\"_id\": \"1\"}}
{\"name\": \"John Doe\" }
{\"index\": {\"_id\": \"2\"}}
{\"name\": \"Jane Doe\" }
"

Again make sure to include a newline after the last line

Upvotes: 3

Related Questions