# Best way to bulk insert?

**URL:** <https://discuss.elastic.co/t/best-way-to-bulk-insert/25102>\
**Category:** Elasticsearch\
**Created:** [July 8, 2015, 12:38am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102 "2015-07-08T00:38:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 8, 2015, 12:38am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/1 "2015-07-08T00:38:50Z")

</div>

Hello Elastic experts,

Wondering what is the best way to insert large number of records into an index?

thanks in advance,  
Lin

---

<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:** [July 8, 2015, 12:59am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/2 "2015-07-08T00:59:56Z")

</div>

Use bulk indeed.

If it's the first big initialization of your index, you could set number of replicas to 0 and restore it to 1 when the injection is over.

My 2 cents.

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 8, 2015, 1:15am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/3 "2015-07-08T01:15:45Z")

</div>

Thanks David,

Any bulk insert samples? New to this concept and want to follow what expert like you referred.

BTW, what is the benefit of "you could set number of replicas to 0 and restore it to 1 when the injection is over"?

---

<div class="post-metadata">

**Author:** ![Junheng\_Gong](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Junheng\_Gong](https://discuss.elastic.co/u/Junheng_Gong)\
**Post date:** [July 8, 2015, 2:45am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/4 "2015-07-08T02:45:12Z")

</div>

use bulk and parallel commit in time, increase server side bulk thread pool and queue size. disable refresh and replica.

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 8, 2015, 3:01am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/5 "2015-07-08T03:01:18Z")

</div>

Thanks Junheng\_Gong for the details,

I am a new user of Elastic Search and for the tactics you mentioned, any reference samples?

regards,  
Lin

---

<div class="post-metadata">

**Author:** ![Srinath\_C](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinath_c/32/48806_2.png) [@Srinath\_C](https://discuss.elastic.co/u/Srinath_C)\
**Post date:** [July 8, 2015, 3:38am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/6 "2015-07-08T03:38:51Z")

</div>

Hi @linlma,

Here what worked for me:  
1, use java bulk import API  
2, use async replication  
3, increase index.refresh\_interval to something like 10s

These factors greatly helped in enhancing our import functionality.  
You will find the links to these easily on the elasticsearch documentation.

Regards,  
Srinath.

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 8, 2015, 4:13am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/7 "2015-07-08T04:13:32Z")

</div>

Thanks Srinath\_C,

I am not sure only Java is supported? I am using Python majorly. 😄

regards,  
Lin

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 8, 2015, 5:20am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/8 "2015-07-08T05:20:11Z")

</div>

All language clients should support bulk operations, including the [official Python client](http://elasticsearch-py.readthedocs.org/en/master/helpers.html#elasticsearch.helpers.bulk), so you do not need to use Java. Here is also an [example](http://unroutable.blogspot.co.uk/2015/03/quick-example-elasticsearch-bulk-index.html) of how it is used.

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 8, 2015, 5:35am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/9 "2015-07-08T05:35:14Z")

</div>

Thanks Christian,

This is exactly what I am looking for. Do you know if there is an API to setup async replication model and increase index.refresh\_interval to something like 10s? Not sure if doable for such configuration related stuff from client side.

regards,  
Lin

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 10, 2015, 10:23pm UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/10 "2015-07-10T22:23:23Z")

</div>

Thanks Christian,

This is exactly what I am looking for. Do you know if there is an API to setup async replication model and increase index.refresh\_interval to something like 10s? Not sure if doable for such configuration related stuff from client side.

regards,  
Lin

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 11, 2015, 4:01am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/11 "2015-07-11T04:01:23Z")

</div>

A list of the index settings that can be changed through the APIs [can be found here](https://www.elastic.co/guide/en/elasticsearch/reference/1.6/indices-update-settings.html). This shows how you can change the refresh interval for bulk indexing and should be supported through all language clients. If you are performing e.g. a bulk load and want to maximise performance, an option might also be to turn the number of replicas down to 0 during indexing and then increase it once the loading has completed. This reduces the amount of network traffic and can speed up loading. The drawback is naturally that you only have a single copy of the data during the indexing which makes it less resilient.

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 11, 2015, 4:40am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/12 "2015-07-11T04:40:34Z")

</div>

Thanks for the advice, Christian!

---

<div class="post-metadata">

**Author:** ![linlma](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@linlma](https://discuss.elastic.co/u/linlma)\
**Post date:** [July 11, 2015, 4:42am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/13 "2015-07-11T04:42:57Z")

</div>

BTW, Christian, it seems async replication is deprecated? Thanks.

> [@Async replication deprecated](https://discuss.elastic.co/t/async-replication-deprecated/25355):
>
> Hello Elastic Search experts, If anyone could help to confirm, it will be great, [https://github.com/elastic/elasticsearch/issues/10114](https://github.com/elastic/elasticsearch/issues/10114)? thanks in advance, Lin

---

<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, 12:02am UTC](https://discuss.elastic.co/t/best-way-to-bulk-insert/25102/14 "2017-07-06T00:02:11Z")

</div>


