# Bulk insertion is too slow using php

**URL:** <https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547>\
**Category:** Elasticsearch\
**Created:** [November 21, 2017, 10:48am UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547 "2017-11-21T10:48:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shemilr](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@shemilr](https://discuss.elastic.co/u/shemilr)\
**Post date:** [November 21, 2017, 10:48am UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/1 "2017-11-21T10:48:42Z")

</div>

Hi,

I am creating the index using bulk insertion and mapping created before inserting the data. I have more than 20 lakhs of data with in one index and one type. After inserting the 2 of 3 lakhs of data bulk insertion becoming slow. For the first 1 lakhs of data insertion is much faster and after that the process is becoming slow.

Is there any tips for speed up the insertion.

Currently using elasticsearch-5.6.3 version.

Already did following this for speed up the process :

1. Index id is not added in the insertion data.
2. Set refresh\_interval = -1
3. Tested with bulk insertion with 2500 rows of data.
4. All other setting as default

---

<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:** [November 21, 2017, 11:36am UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/2 "2017-11-21T11:36:17Z")

</div>

What is the specification of your Elasticsearch cluster?

What does CPU and disk I/O look like while indexing?

How many parallel processes do you have indexing into Elasticsearch?

---

<div class="post-metadata">

**Author:** ![shemilr](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@shemilr](https://discuss.elastic.co/u/shemilr)\
**Post date:** [November 21, 2017, 12:47pm UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/3 "2017-11-21T12:47:43Z")

</div>

I am using php sdk and I am running only one process for inserting the whole data. PHP is not supporting threading, thats why I am using the single process.

I am able to insert the whole data, but taking to much time for inserting. Also I am setting php memory as 512 MB throuogh my php code.

---

<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:** [November 21, 2017, 12:57pm UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/4 "2017-11-21T12:57:22Z")

</div>

It is generally recommended to use several parallel workers, so it might be worth partitioning up the data and try using multiple PHP process. You can also use Logstash, which supports parallelism out of the box.

---

<div class="post-metadata">

**Author:** ![shemilr](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@shemilr](https://discuss.elastic.co/u/shemilr)\
**Post date:** [November 21, 2017, 1:10pm UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/5 "2017-11-21T13:10:54Z")

</div>

ok. But I have to fetch data from different tables and merge all those values. After that only I can insert to elasticsearch. Thats why I am not able to use logstash.

Now it is talking around 2 hours to insert 20 lakhs of data. Do you this this is very high for elasticsearch? As application prespective its too high.

---

<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:** [November 21, 2017, 1:18pm UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/6 "2017-11-21T13:18:23Z")

</div>

In order to get better parallelism, I would recommend you try using Logstash with a JDBC input plugin to read the data. This will read data as quickly as possible and use multiple threads to process and write the data based on a single input.

The throughput you are quoting is very low, but I suspect it may primarily be due to the way you are retrieving and ingesting data and not necessarily a reflection of what Elasticsearch can handle.

Also please try to use units that are globally recognised. I believe lakhs is very particular to Asia.

---

<div class="post-metadata">

**Author:** ![shemilr](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@shemilr](https://discuss.elastic.co/u/shemilr)\
**Post date:** [November 22, 2017, 5:09am UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/7 "2017-11-22T05:09:18Z")

</div>

ok. Thank you for the information. I will do a feasibility study between logstash and my application.

But the system is getting slower after inserting 500 thousand data. I am curious to know that is the data size will affect the insertion speed or not?

---

<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 20, 2017, 5:09am UTC](https://discuss.elastic.co/t/bulk-insertion-is-too-slow-using-php/108547/8 "2017-12-20T05:09:23Z")

</div>

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