Bulk request throws error in elasticsearch 6.1.1

2019-04-21 13:09发布

I recently upgraded to elasticsearch version 6.1.1 and now I can't bulk index documents from a json file. Wehn I do it inline, it works fine. Here are the contents of the document:

{"index" : {}}
{"name": "Carlson Barnes", "age": 34}
{"index":{}}
{"name": "Sheppard Stein","age": 39}
{"index":{}}
{"name": "Nixon Singleton","age": 36}
{"index":{}}
{"name": "Sharron Sosa","age": 33}
{"index":{}}
{"name": "Kendra Cabrera","age": 24}
{"index":{}}
{"name": "Young Robinson","age": 20}

When I run this command,

curl -XPUT 'localhost:9200/subscribers/ppl/_bulk?pretty' -H 'Content-Type: application/json' -d @customers_full.json

I get this 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

It works fine if I send the data inline and in elasticsearch 5.x. I tried adding newlines as well as the newline character to the end of the file. Doesn't seem to work.

9条回答
smile是对你的礼貌
2楼-- · 2019-04-21 13:34

I ran into the same issue and spent hours adding and removing newlines before somebody pointed out I mis-typed the file name... So note that curl will throw the same error if the file is not actually present, making this super-confusing.

查看更多
地球回转人心会变
3楼-- · 2019-04-21 13:39

The error is pretty clear:

The bulk request must be terminated by a newline [\n]

So you simply need to add a newline at the end of your customers_full.json file and you'll be ok.

查看更多
叼着烟拽天下
4楼-- · 2019-04-21 13:41

For anyone using postman to make requests to ElasticSearch

Just press enter to create an empty new line!

And voila, problem solved

查看更多
ゆ 、 Hurt°
5楼-- · 2019-04-21 13:46

Press Enter end of the line inside json file and run the command again .

curl -H "Content-Type: application/x-ndjson" -XPOST 'localhost:9200/customers/personal/_bulk?pretty&refresh' --data-binary @"generated.json"

查看更多
做个烂人
6楼-- · 2019-04-21 13:47

This worked in my local set-up.

curl -H "Content-type:application/json" -XPOST "http://localhost:9200/customer/personal/_bulk?pretty" --data-binary @"generated.json"

查看更多
成全新的幸福
7楼-- · 2019-04-21 13:50

Add empty line at the end of the JSON file and save the file and then try to run the below command

curl -XPOST localhost:9200/subscribers/ppl/_bulk?pretty --data-binary @customers_full.json -H 'Content-Type: application/json'

I hope it works fine for you.

查看更多
登录 后发表回答