# Elasticsearch - How to update/index multiple documents

**URL:** <https://discuss.elastic.co/t/elasticsearch-how-to-update-index-multiple-documents/128972>\
**Category:** Elasticsearch\
**Created:** [April 21, 2018, 2:25pm UTC](https://discuss.elastic.co/t/elasticsearch-how-to-update-index-multiple-documents/128972 "2018-04-21T14:25:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thebigk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thebigk/32/10411_2.png) [@thebigk](https://discuss.elastic.co/u/thebigk)\
**Post date:** [April 21, 2018, 2:25pm UTC](https://discuss.elastic.co/t/elasticsearch-how-to-update-index-multiple-documents/128972/1 "2018-04-21T14:25:25Z")

</div>

I'm faced with a situation where I need to build an index of about 500,000 records. I'm using the official php client and wondering what should be the right way to do the update.

The only solution I can think of is to have a foreach loop and call `$response = $client->index($params);` in it.

But is that the right way to go about it or there's something I'm missing out on? Would really appreciate your responses. Thanks!

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [April 22, 2018, 12:21am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-update-index-multiple-documents/128972/2 "2018-04-22T00:21:07Z")

</div>

You should use the [Bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docs-bulk.html) for this.

---

<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:** [May 20, 2018, 12:21am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-update-index-multiple-documents/128972/3 "2018-05-20T00:21:23Z")

</div>

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