# How to index bulk of documents all at once?

**URL:** <https://discuss.elastic.co/t/how-to-index-bulk-of-documents-all-at-once/14616>\
**Category:** Elasticsearch\
**Created:** [November 27, 2013, 1:10pm UTC](https://discuss.elastic.co/t/how-to-index-bulk-of-documents-all-at-once/14616 "2013-11-27T13:10:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [November 27, 2013, 1:10pm UTC](https://discuss.elastic.co/t/how-to-index-bulk-of-documents-all-at-once/14616/1 "2013-11-27T13:10:36Z")

</div>

I have some documents, they are all of the same index and type, and have  
the same fields, for example:  
{"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
{"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
{"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}

If I want to index them to my ES server all at once, I use the bulk  
interface like this:  
_# curl -s -XPOST localhost:9200/\_bulk --data-binary @data\_file_

the data\_file looks like:  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
{"nation" : "USA", "city" : "California", "year" : ["2012", "2014", "2015"]}  
{"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}

But it only index the first document, If I change the data\_file as the  
following:  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}

it works, but the data\_file becomes much bigger.

Is there a better way to import Json documents to ES ? Thanks very much.

--  
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/adf0a1f7-bfab-4065-9ce6-c49da1286500%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/adf0a1f7-bfab-4065-9ce6-c49da1286500%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:** [November 27, 2013, 2:29pm UTC](https://discuss.elastic.co/t/how-to-index-bulk-of-documents-all-at-once/14616/2 "2013-11-27T14:29:35Z")

</div>

I guess that the smallest data\_file you can have is:  
{"index" : { }}  
{"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
{"index" : { }}  
{"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
{"index" : { }}  
{"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}

curl -s -XPOST localhost:9200/country/city/\_bulk --data-binary @data\_file

HTH

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 27 novembre 2013 at 14:10:41, Daniel Guo ([daniel5hbs@gmail.com](mailto:daniel5hbs@gmail.com)) a écrit:

I have some documents, they are all of the same index and type, and have the same fields, for example:  
{"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
{"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
{"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}

If I want to index them to my ES server all at once, I use the bulk interface like this:

# curl -s -XPOST localhost:9200/\_bulk --data-binary @data\_file

the data\_file looks like:  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
{"nation" : "USA", "city" : "California", "year" : ["2012", "2014", "2015"]}  
{"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}

But it only index the first document, If I change the data\_file as the following:  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
{"index" : {"\_index" : "country", "\_type" : "city"}}  
{"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}

it works, but the data\_file becomes much bigger.

## Is there a better way to import Json documents to ES ? Thanks very much.

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/adf0a1f7-bfab-4065-9ce6-c49da1286500%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/adf0a1f7-bfab-4065-9ce6-c49da1286500%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/etPan.529601cf.140e0f76.3e14%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.529601cf.140e0f76.3e14%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [November 28, 2013, 1:46am UTC](https://discuss.elastic.co/t/how-to-index-bulk-of-documents-all-at-once/14616/3 "2013-11-28T01:46:13Z")

</div>

David, you provide a great improvement. Thank you!  
Is there other ways to load data from to ES server?

On Wednesday, November 27, 2013 10:29:35 PM UTC+8, David Pilato wrote:

> I guess that the smallest data\_file you can have is:
> 
> {"index" : { }}  
> {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"  
> ]}  
> {"index" : { }}  
> {"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"  
> ]}  
> {"index" : { }}  
> {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"  
> ]}
> 
> curl -s -XPOST localhost:9200/_country/city_/\_bulk --data-binary  
> @data\_file
> 
> HTH
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 27 novembre 2013 at 14:10:41, Daniel Guo ([danie...@gmail.com](mailto:danie...@gmail.com)\<javascript:\>)  
> a écrit:
> 
> I have some documents, they are all of the same index and type, and have  
> the same fields, for example:  
> {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012",  
> "2013"]}  
> {"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014",  
> "2015"]}  
> {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"  
> ]}
> 
> If I want to index them to my ES server all at once, I use the bulk  
> interface like this:  
> _# curl -s -XPOST localhost:9200/\_bulk --data-binary @data\_file_
> 
> the data\_file looks like:  
> {"index" : {"\_index" : "country", "\_type" : "city"}}  
> {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"  
> ]}  
> {"nation" : "USA", "city" : "California", "year" : ["2012", "2014",  
> "2015"]}  
> {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"  
> ]}
> 
> But it only index the first document, If I change the data\_file as the  
> following:  
> {"index" : {"\_index" : "country", "\_type" : "city"}}  
> {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"  
> ]}  
> {"index" : {"\_index" : "country", "\_type" : "city"}}  
> {"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014",  
> "2015"]}  
> {"index" : {"\_index" : "country", "\_type" : "city"}}  
> {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"  
> ]}
> 
> it works, but the data\_file becomes much bigger.
> 
> ## Is there a better way to import Json documents to ES ? Thanks very much.
> 
> 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/adf0a1f7-bfab-4065-9ce6-c49da1286500%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/adf0a1f7-bfab-4065-9ce6-c49da1286500%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/60b58840-45de-497a-aab1-870429b70c62%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/60b58840-45de-497a-aab1-870429b70c62%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:** [November 28, 2013, 5:55am UTC](https://discuss.elastic.co/t/how-to-index-bulk-of-documents-all-at-once/14616/4 "2013-11-28T05:55:55Z")

</div>

I think Bulk is the best practice.

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

Le 28 nov. 2013 à 02:46, Daniel Guo [daniel5hbs@gmail.com](mailto:daniel5hbs@gmail.com) a écrit :

David, you provide a great improvement. Thank you!  
Is there other ways to load data from to ES server?

> On Wednesday, November 27, 2013 10:29:35 PM UTC+8, David Pilato wrote:  
> I guess that the smallest data\_file you can have is:
> 
> > {"index" : { }}  
> > {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
> > {"index" : { }}  
> > {"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
> > {"index" : { }}  
> > {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}
> 
> curl -s -XPOST localhost:9200/country/city/\_bulk --data-binary @data\_file
> 
> HTH
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr
> 
> Le 27 novembre 2013 at 14:10:41, Daniel Guo ([danie...@gmail.com](mailto:danie...@gmail.com)) a écrit:
> 
> > I have some documents, they are all of the same index and type, and have the same fields, for example:  
> > {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
> > {"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
> > {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}
> > 
> > If I want to index them to my ES server all at once, I use the bulk interface like this:
> > 
> > # curl -s -XPOST localhost:9200/\_bulk --data-binary @data\_file
> > 
> > the data\_file looks like:  
> > {"index" : {"\_index" : "country", "\_type" : "city"}}  
> > {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
> > {"nation" : "USA", "city" : "California", "year" : ["2012", "2014", "2015"]}  
> > {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}
> > 
> > But it only index the first document, If I change the data\_file as the following:  
> > {"index" : {"\_index" : "country", "\_type" : "city"}}  
> > {"nation" : "China", "city" : "Tianjin", "year" : ["2011", "2012", "2013"]}  
> > {"index" : {"\_index" : "country", "\_type" : "city"}}  
> > {"nation" : "USA", "city" : "Califorlia", "year" : ["2012", "2014", "2015"]}  
> > {"index" : {"\_index" : "country", "\_type" : "city"}}  
> > {"nation" : "China", "city" : "Beijing", "year" : ["2012", "2014", "2015"]}
> > 
> > it works, but the data\_file becomes much bigger.
> > 
> > ## Is there a better way to import Json documents to ES ? Thanks very much.
> > 
> > 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/adf0a1f7-bfab-4065-9ce6-c49da1286500%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/adf0a1f7-bfab-4065-9ce6-c49da1286500%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/60b58840-45de-497a-aab1-870429b70c62%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/60b58840-45de-497a-aab1-870429b70c62%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/96920FBA-2738-4319-A4A8-2B6FDB609899%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/96920FBA-2738-4319-A4A8-2B6FDB609899%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:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:04am UTC](https://discuss.elastic.co/t/how-to-index-bulk-of-documents-all-at-once/14616/5 "2017-07-06T02:04:24Z")

</div>


