# How to index json data into elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-index-json-data-into-elasticsearch/107035>\
**Category:** Logstash\
**Created:** [November 9, 2017, 11:41am UTC](https://discuss.elastic.co/t/how-to-index-json-data-into-elasticsearch/107035 "2017-11-09T11:41:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhanunjayavarma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dhanunjayavarma/32/140130_2.png) [@dhanunjayavarma](https://discuss.elastic.co/u/dhanunjayavarma)\
**Post date:** [November 9, 2017, 11:41am UTC](https://discuss.elastic.co/t/how-to-index-json-data-into-elasticsearch/107035/1 "2017-11-09T11:41:32Z")

</div>

let say I have json file with this type of data  
{  
"\_id":1,  
"cid":3067,  
"name":"Tech Mahindra",  
"type":[  
"Information Technology and Services"  
],  
"empSize":99704,  
"empSizeInfo":[  
{  
"on":1507141800,  
"size":99704  
}  
],  
"domain":"[http://www.techmahindra.com/theme/DAVID.html](http://www.techmahindra.com/theme/DAVID.html)",  
"loc":{  
"ct":"Maharashtra",  
"cy":"in",  
"pCode":"411004"  
},  
"followers":370803,  
"ctdOn":1507141800,  
"status":0,  
"updtdOn":1507141800,  
"cmptd":1  
}  
how to index data using logstash?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 9, 2017, 2:17pm UTC](https://discuss.elastic.co/t/how-to-index-json-data-into-elasticsearch/107035/2 "2017-11-09T14:17:16Z")

</div>

Does each file contain more than one such JSON object?

---

<div class="post-metadata">

**Author:** ![dhanunjayavarma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dhanunjayavarma/32/140130_2.png) [@dhanunjayavarma](https://discuss.elastic.co/u/dhanunjayavarma)\
**Post date:** [November 10, 2017, 4:34am UTC](https://discuss.elastic.co/t/how-to-index-json-data-into-elasticsearch/107035/3 "2017-11-10T04:34:51Z")

</div>

yes it will have a file like this  
{  
"\_id":1,  
"cid":2013,  
"name":"nextGo",  
"loc":{  
"ct":"Maharashtra",  
"cy":"in",  
"pCode":"411004"  
}  
}{  
"\_id":2,  
"cid":2014,  
"name":"DealDollor",  
"loc":{  
"ct":"Andhra",  
"cy":"in",  
"pCode":"411034"  
}  
}  
The file will be having multiple JSON objects ..

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 10, 2017, 5:54am UTC](https://discuss.elastic.co/t/how-to-index-json-data-into-elasticsearch/107035/4 "2017-11-10T05:54:34Z")

</div>

Okay. Logstash reads files line by line so you'll have to use a multiline codec to selectively join lines that are part of the same JSON object. This is going to be a bit tricky because of the `}{` lines. I don't have time to give an example.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 8, 2017, 5:54am UTC](https://discuss.elastic.co/t/how-to-index-json-data-into-elasticsearch/107035/5 "2017-12-08T05:54:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
