Put JSON into elasticsearch?

Using Bulk API, i did indeed get it to work !

Here's the final document
{ "index": {"_id":"1"}}
{ "type":"train", "name":"T01", "state":"inactive", "time":"2019-12-20 08:48:12" }
{ "index" : { "_id" : "2" } }
{ "type":"train", "name":"T02", "state":"active", "time":"2019-12-20 08:48:12" }

As well as the command used to upload the file:
curl -X PUT "localhost:9200/sample_data/_bulk?pretty" -H 'Content-Type: application/x-ndjson' --data-binary @sample.json

To any future readers: notice the mandatory "index" before each document, that was the part I had trouble understanding, but after thorough reading of the doc, it's actually explained pretty well ^^'

Thanks again for the help!

EDIT: After uploading the file to ES, you might want to have your timestamp be registered as a time field. Since it doesn't recognize the string automatically, I applied a mapping before the bulk put:
PUT /sample_data
{
"mappings": {
"properties": {
"type": {"type": "keyword"},
"name": {"type": "keyword"},
"state": {"type": "keyword"},
"time": {"type": "date", "format": "yyyy-MM-dd HH:mm:ss"}
}
}
}

2 Likes