Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

Error while uploading JSON data from local linux vm to ElasticSearch (status:400)

I have a json dataset in the given form and wish to upload it to Elastic search from my local virtual machine via curl command. enter image description here

This is a Csv file converted to Json. I now wish to import the entire file from my linux Vm to Elasticsearch and I use the following curl command.

$ curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/_bulk?pretty' --data-binary @Bank_adv.json

I end up with the following error:

{ "error" : { "root_cause" : [ { "type" : "json_e_o_f_exception", "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: (byte[])" { "CUSTOMER_ID": enter image description here

Here is the full screenshot. My elasticsearch node is up and running fine on port 9200 so i don't think it is a connection issue but a data issue. This is the only format by which I can use this Json data so if there is a way I can modify it to be able to be uploaded it would help.

question from:https://stackoverflow.com/questions/66047262/error-while-uploading-json-data-from-local-linux-vm-to-elasticsearch-status400

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You will have to properly restructure you input data file to follow elasticsearch's bulk index format.

If your curl looks like:

curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/_bulk?pretty' --data-binary @Bank_adv.json

then you will need to structure your file so that it looks like this:

{"index":{}}
{"text": "hello world"}
{"index":{}}
{"text": "goodbye"}

You need the index directive before each document. Each document must be on a single line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...