# How to index an existing json file

**URL:** <https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134>\
**Category:** Elasticsearch\
**Created:** [January 8, 2014, 2:00am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134 "2014-01-08T02:00:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![IronMike](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@IronMike](https://discuss.elastic.co/u/IronMike)\
**Post date:** [January 8, 2014, 2:00am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/1 "2014-01-08T02:00:33Z")

</div>

Hi,

I am just starting with ElasticSearch, I would like to know how to index a  
simple json document "books.json" that has the following in it: Where do I  
place the document? I placed it in root directory of elastic search and in  
/bin folder..

{“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get  
rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda  
Jones”]}}

$ curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" -d @books.json

Warning: Couldn't read data from file "books.json", this makes an empty  
POST.

{"error":"MapperParsingException[failed to parse, document is  
empty]","status":400}

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 8, 2014, 2:06am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/2 "2014-01-08T02:06:01Z")

</div>

The JSON file is used by the curl command, so in your example it should be  
in the same directory in which you executed the command (current directory).

--  
Ivan

On Tue, Jan 7, 2014 at 6:00 PM, ZenMaster80 [sabdalla80@gmail.com](mailto:sabdalla80@gmail.com) wrote:

> Hi,
> 
> I am just starting with Elasticsearch, I would like to know how to index a  
> simple json document "books.json" that has the following in it: Where do I  
> place the document? I placed it in root directory of Elasticsearch and in  
> /bin folder..
> 
> {“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get  
> rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda  
> Jones”]}}
> 
> $ curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" -d @books.json
> 
> Warning: Couldn't read data from file "books.json", this makes an empty  
> POST.
> 
> {"error":"MapperParsingException[failed to parse, document is  
> empty]","status":400}
> 
> Thanks
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDg%3Du3HfBvKnQrCy6XEJ6knyrvx042j8kn7YZmMz96FhA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQDg%3Du3HfBvKnQrCy6XEJ6knyrvx042j8kn7YZmMz96FhA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![IronMike](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@IronMike](https://discuss.elastic.co/u/IronMike)\
**Post date:** [January 8, 2014, 2:10am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/3 "2014-01-08T02:10:51Z")

</div>

Great, Do you know why I am getting

{"error":"MapperParsingException[failed to parse]; nested:  
JsonParseException[Unrecognized token 'life': was expecting ('true',  
'false' or 'null')\n at [Source: [B@5c9a9d06; line: 1, column: 35]];  
","status":400}

data:

{“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get  
rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda  
Jones”}]}

On Tuesday, January 7, 2014 9:06:01 PM UTC-5, Ivan Brusic wrote:

> The JSON file is used by the curl command, so in your example it should be  
> in the same directory in which you executed the command (current directory).
> 
> --  
> Ivan
> 
> On Tue, Jan 7, 2014 at 6:00 PM, ZenMaster80 \<[sabda...@gmail.com](mailto:sabda...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > I am just starting with Elasticsearch, I would like to know how to index  
> > a simple json document "books.json" that has the following in it: Where do  
> > I place the document? I placed it in root directory of Elasticsearch and  
> > in /bin folder..
> > 
> > {“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get  
> > rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda  
> > Jones”]}}
> > 
> > $ curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" -d @books.json
> > 
> > Warning: Couldn't read data from file "books.json", this makes an empty  
> > POST.
> > 
> > {"error":"MapperParsingException[failed to parse, document is  
> > empty]","status":400}
> > 
> > Thanks
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5d15fcdf-4a0f-4d92-9dd3-f07899d915fe%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5d15fcdf-4a0f-4d92-9dd3-f07899d915fe%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 8, 2014, 7:13am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/4 "2014-01-08T07:13:53Z")

</div>

Start with a clean index:

curl -XDELETE "[http://localhost:9200/books/](http://localhost:9200/books/)"

You probably have a bad mapping (some docs already indexed?)

If you still have problems, please gist a full curl recreation. See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help/)

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 8 janv. 2014 à 03:10, ZenMaster80 [sabdalla80@gmail.com](mailto:sabdalla80@gmail.com) a écrit :

Great, Do you know why I am getting  
{"error":"MapperParsingException[failed to parse]; nested: JsonParseException[Unrecognized token 'life': was expecting ('true', 'false' or 'null')\n at [Source: [B@5c9a9d06; line: 1, column: 35]]; ","status":400}

data:

{“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda Jones”}]}

> On Tuesday, January 7, 2014 9:06:01 PM UTC-5, Ivan Brusic wrote:  
> The JSON file is used by the curl command, so in your example it should be in the same directory in which you executed the command (current directory).
> 
> --  
> Ivan
> 
> > On Tue, Jan 7, 2014 at 6:00 PM, ZenMaster80 [sabda...@gmail.com](mailto:sabda...@gmail.com) wrote:  
> > Hi,
> > 
> > I am just starting with Elasticsearch, I would like to know how to index a simple json document "books.json" that has the following in it: Where do I place the document? I placed it in root directory of Elasticsearch and in /bin folder..
> > 
> > {“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda Jones”]}}
> > 
> > $ curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" -d @books.json
> > 
> > Warning: Couldn't read data from file "books.json", this makes an empty POST.  
> > {"error":"MapperParsingException[failed to parse, document is empty]","status":400}
> > 
> > Thanks
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a5c1e37f-9472-499c-9499-1475c944f47b%40googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5d15fcdf-4a0f-4d92-9dd3-f07899d915fe%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5d15fcdf-4a0f-4d92-9dd3-f07899d915fe%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/E9FE0784-B10E-48AD-9C46-45B44B1513B9%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/E9FE0784-B10E-48AD-9C46-45B44B1513B9%40pilato.fr).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [January 8, 2014, 9:19am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/5 "2014-01-08T09:19:35Z")

</div>

Use the binary data flag or curl does not work correctly.

curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" --data-binary --data  
@books.json

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHyFm9cv6RJDZ4x-czsZQFnNgxnLhxD8unxoVwqE3wXtw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHyFm9cv6RJDZ4x-czsZQFnNgxnLhxD8unxoVwqE3wXtw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![IronMike](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@IronMike](https://discuss.elastic.co/u/IronMike)\
**Post date:** [January 9, 2014, 2:59am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/6 "2014-01-09T02:59:40Z")

</div>

Thank you for the binary flag tip. It is also in the documentation here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Tuesday, January 7, 2014 9:00:33 PM UTC-5, ZenMaster80 wrote:

> Hi,
> 
> I am just starting with Elasticsearch, I would like to know how to index a  
> simple json document "books.json" that has the following in it: Where do I  
> place the document? I placed it in root directory of Elasticsearch and in  
> /bin folder..
> 
> {“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get  
> rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda  
> Jones”]}}
> 
> $ curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" -d @books.json
> 
> Warning: Couldn't read data from file "books.json", this makes an empty  
> POST.
> 
> {"error":"MapperParsingException[failed to parse, document is  
> empty]","status":400}
> 
> Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/853a876f-c6cb-4dd5-907a-13f626b3f078%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/853a876f-c6cb-4dd5-907a-13f626b3f078%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![IronMike](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@IronMike](https://discuss.elastic.co/u/IronMike)\
**Post date:** [January 9, 2014, 3:00am UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/7 "2014-01-09T03:00:41Z")

</div>

Thank you for the binary flag tip. It is also in the documentation here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wednesday, January 8, 2014 4:19:35 AM UTC-5, Jörg Prante wrote:

> Use the binary data flag or curl does not work correctly.
> 
> curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" --data-binary --data  
> @books.json
> 
> Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4803cd61-2627-4d65-86ec-062ec864b986%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4803cd61-2627-4d65-86ec-062ec864b986%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![to\_tu](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@to\_tu](https://discuss.elastic.co/u/to_tu)\
**Post date:** [November 18, 2014, 3:18pm UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/8 "2014-11-18T15:18:24Z")

</div>

You have a syntax error in your JSON with the unbalanced sequence of  
enclosing squigglies & bracket. Compare the two ends.

Tom

On Tuesday, January 7, 2014 7:00:33 PM UTC-7, sammy wrote:

> Hi,
> 
> I am just starting with Elasticsearch, I would like to know how to index a  
> simple json document "books.json" that has the following in it: Where do I  
> place the document? I placed it in root directory of Elasticsearch and in  
> /bin folder..
> 
> {“books”:[{“name”:”life in heaven”,”author”:”Mike Smith”},{“name”:”get  
> rich”,”author”:”Joe Shmoe”},{“name”:”luxury properties”,”author”:”Linda  
> Jones”]}}
> 
> $ curl -XPUT "[http://localhost:9200/books/book/1](http://localhost:9200/books/book/1)" -d @books.json
> 
> Warning: Couldn't read data from file "books.json", this makes an empty  
> POST.
> 
> {"error":"MapperParsingException[failed to parse, document is  
> empty]","status":400}
> 
> Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6305af6b-676a-43ab-8c7c-7fc54b2764ad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6305af6b-676a-43ab-8c7c-7fc54b2764ad%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![SarahB](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@SarahB](https://discuss.elastic.co/u/SarahB)\
**Post date:** [October 25, 2016, 2:16pm UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/9 "2016-10-25T14:16:28Z")

</div>

Hi.  
If you want, you can easily manage your cluster and node elastic using this script :  
[https://github.com/SarahBourgeois/elasticsearch-Cluster-Manager](https://github.com/SarahBourgeois/elasticsearch-Cluster-Manager).

---

<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:** [July 5, 2017, 10:09pm UTC](https://discuss.elastic.co/t/how-to-index-an-existing-json-file/15134/10 "2017-07-05T22:09:58Z")

</div>


