# Put JSON into elasticsearch?

**URL:** <https://discuss.elastic.co/t/put-json-into-elasticsearch/178971>\
**Category:** Elasticsearch\
**Created:** [April 29, 2019, 5:42pm UTC](https://discuss.elastic.co/t/put-json-into-elasticsearch/178971 "2019-04-29T17:42:53Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Moxyze](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@Moxyze](https://discuss.elastic.co/u/Moxyze)\
**Post date:** [April 29, 2019, 7:24pm UTC](https://discuss.elastic.co/t/put-json-into-elasticsearch/178971/5 "2019-04-29T19:24:43Z")

</div>

Using [Bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/docs-bulk.html), 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"}  
}  
}  
}

---

_[View the full topic](https://discuss.elastic.co/t/put-json-into-elasticsearch/178971)._
