# How to import json file to Elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976>\
**Category:** Elasticsearch\
**Created:** [December 7, 2019, 5:52pm UTC](https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976 "2019-12-07T17:52:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmet\_Kartal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmet_kartal/32/47196_2.png) [@Ahmet\_Kartal](https://discuss.elastic.co/u/Ahmet_Kartal)\
**Post date:** [December 7, 2019, 5:52pm UTC](https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976/1 "2019-12-07T17:52:21Z")

</div>

Hi, I have 1 billion json data. I want to import these data to my local elasticsearch. All the documents in one json file. What is the easiest way to do that?

I have tried this but did not work for me: `curl -XPOST http://localhost:9200/project/_doc -H "Content-Type: application/json" -d @ahmet.json`

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 8, 2019, 2:46am UTC](https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976/2 "2019-12-08T02:46:42Z")

</div>

> [@Ahmet\_Kartal](#):
>
> did not work for me

Any details about what did not work?  
May be you did not follow the bulk request pattern? I guess you are missing header for each Json.

> [@Ahmet\_Kartal](#):
>
> All the documents in one json file.

You probably need to write a script or use filebeat.  
Do you have one line per JSon?

If you have one file per document, you can otherwise try FSCrawler. It has an option to import json files.

---

<div class="post-metadata">

**Author:** ![Ahmet\_Kartal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmet_kartal/32/47196_2.png) [@Ahmet\_Kartal](https://discuss.elastic.co/u/Ahmet_Kartal)\
**Post date:** [December 8, 2019, 7:04am UTC](https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976/3 "2019-12-08T07:04:38Z")

</div>

> [@dadoonet](#):
>
> Any details about what did not work?

I just typed that cURL command and it did not send data to my localhost:9200. It returned null line.

> [@dadoonet](#):
>
> Do you have one line per JSon?

Each json seperated from each other by new line.For example like this:

```
{"type": "server", "timestamp": "2019-12-07T19:09:46,351Z", "level": "INFO", "component": "o.e.e.NodeEnvironment", "cluster.name": "docker-cluster", "node.name": "f97588749c79", "message": "heap size [989.8mb], compressed ordinary object pointers [true]" }
{"type": "server", "timestamp": "2019-12-07T19:09:46,353Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "f97588749c79", "message": "node name [f97588749c79], node ID [qJbs-xKRTxiaoIGXbrsVkg], cluster name [docker-cluster]" }

```

---

<div class="post-metadata">

**Author:** ![Ahmet\_Kartal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmet_kartal/32/47196_2.png) [@Ahmet\_Kartal](https://discuss.elastic.co/u/Ahmet_Kartal)\
**Post date:** [December 9, 2019, 10:41am UTC](https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976/4 "2019-12-09T10:41:23Z")

</div>

Anyone can help ?

---

<div class="post-metadata">

**Author:** ![vijaykriishna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijaykriishna/32/42737_2.png) [@vijaykriishna](https://discuss.elastic.co/u/vijaykriishna)\
**Post date:** [December 11, 2019, 7:12am UTC](https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976/5 "2019-12-11T07:12:25Z")

</div>

Try this.

Data format must be as follows for every json  
1. first line containing index name  
2. actual data to be inserted into the index

` sample data:`

```
{"index": {"_index": "index_name", "_type": "index_type", "_id": "doc_id"}}
{"type": "server", "timestamp": "2019-12-07T19:09:46,351Z", "level": "INFO", "component": "o.e.e.NodeEnvironment", "cluster.name": "docker-cluster", "node.name": "f97588749c79", "message": "heap size [989.8mb], compressed ordinary object pointers [true]" }
{"index": {"_index": "index_name", "_type": "index_type", "_id": "doc_id"}}
{"type": "server", "timestamp": "2019-12-07T19:09:46,353Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "f97588749c79", "message": "node name [f97588749c79], node ID [qJbs-xKRTxiaoIGXbrsVkg], cluster name [docker-cluster]" }

```

` curl -H 'Content-Type: application/json' -XPOST 'localhost:9200/{index}/{type}/_bulk?pretty' --data-binary @<file_name>.json`

---

<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:** [January 8, 2020, 7:12am UTC](https://discuss.elastic.co/t/how-to-import-json-file-to-elasticsearch/210976/6 "2020-01-08T07:12:28Z")

</div>

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