Trying to import JSON fails

I'm simply trying to get some data into ES to experiment with.

My JSON looks like this (randomly generated names):

{
"RECORDS":[
{
"fname":"Hyon",
"last":"Washko",
"addr":"18 Ratliff",
"City":"Cabot",
"State":"MN"
},
{
"fname":"Margie",
"last":"Dragovich",
"addr":"5 Liles Cp",
"City":"Idaho Fall",
"State":"NY"
},

]
}


Now, I named the file "names.json" on my Desktop folder and tried this command:

$ curl -H "Content-Type: application/json" http://localhost:9200/_bulk --data-binary @"/Users/me/Desktop/names.json"

--

Yet, I get this error:

{"error":{"root_cause":[{"type":"json_e_o_f_exception","reason":"Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 3]"}],"type":"json_e_o_f_exception","reason":"Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@743dc477; line: 1, column: 3]"},"status":500}


Baffled how to just get some data into JSON.

Can anyone tell me what's wrong with the import above?

Thanks.

You need to prefix every json document in bulk with an index command and specify index name either in the index command or on URL

names.json:

{"index": {}}
{"fname":"Hyon", "last":"Washko","addr":"18 Ratliff",  "City":"Cabot","State":"MN"}
{"index": {}}
{"fname":"Margie","last":"Dragovich","addr":"5 Liles Cp","City":"Idaho Fall","State":"NY"}

Command:

$ curl -XPOST  "http://localhost:9200/test/_doc/_bulk" -H 'Content-Type: application/json' --data-binary @"/Users/me/Desktop/names.json"

Thanks very much for your reply.

So, it sounds like I need to pre-process the JSON file programmatically to get it into the correct format.

Appreciate your note.

Yes. You can use logstash with json codec to do that.

1 Like