# Can I update/delete/get/index multiple data on PHP client at once?

**URL:** <https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108>\
**Category:** Elasticsearch\
**Created:** [December 28, 2016, 6:33am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108 "2016-12-28T06:33:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanimoto](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tanimoto](https://discuss.elastic.co/u/tanimoto)\
**Post date:** [December 28, 2016, 6:33am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/1 "2016-12-28T06:33:21Z")

</div>

my php file is as below.

```auto
<?php
   require_once '/usr/local/bin/composer/vendor/autoload.php';
   
   $host = ["http://localhost:9200"];
   
   $client = Elasticsearch\ClientBuilder::create()->setHosts($host)->build();
    
   $params = [
        'index' => 'my_index',
        'type' => 'my_type',
        'id' => '1'
        'body' => [
            'doc' => [
              'new_field' => 'abc'
            ]
         ]
     ];
     $response = $client->update($params);

```

Can I update/delete/get/index multiple data at once?  
Or should I loop this operation by PHP and execute `$client->update($params);` as many as needed??

It is not described here  
[https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/\_updating\_documents.html](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_updating_documents.html)

---

<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:** [December 28, 2016, 6:47am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/2 "2016-12-28T06:47:02Z")

</div>

BULK API is the way to go. Much more efficient.

---

<div class="post-metadata">

**Author:** ![tanimoto](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tanimoto](https://discuss.elastic.co/u/tanimoto)\
**Post date:** [December 28, 2016, 6:54am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/3 "2016-12-28T06:54:53Z")

</div>

you mean, PHP client can't do it?

---

<div class="post-metadata">

**Author:** ![tanimoto](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tanimoto](https://discuss.elastic.co/u/tanimoto)\
**Post date:** [December 28, 2016, 7:12am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/4 "2016-12-28T07:12:56Z")

</div>

PHP client sounds bit confusing sorry.  
I mean, `$client->update($params);` method can't update multiple data at once?

---

<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:** [December 28, 2016, 7:31am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/5 "2016-12-28T07:31:00Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/\_indexing\_documents.html#\_bulk\_indexing](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_indexing_documents.html#_bulk_indexing)

---

<div class="post-metadata">

**Author:** ![tanimoto](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tanimoto](https://discuss.elastic.co/u/tanimoto)\
**Post date:** [December 28, 2016, 7:34am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/6 "2016-12-28T07:34:32Z")

</div>

Ah, bulk api can be used through PHP client!!  
Thanks!!

---

<div class="post-metadata">

**Author:** ![tanimoto](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tanimoto](https://discuss.elastic.co/u/tanimoto)\
**Post date:** [December 28, 2016, 9:50am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/7 "2016-12-28T09:50:18Z")

</div>

But bulk seems to unable to update document partially.  
It reindex whole document.

It used to have updateByQuery but it was removed from elasticsearch-php 5.0.

Is there any other way to update multiple document specific fields?

---

<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:** [December 28, 2016, 10:23am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/8 "2016-12-28T10:23:17Z")

</div>

[bulk API supports update requests](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/docs-bulk.html#bulk-update).

about updateByQuery in PHP, I have no idea. I think it has not been added probably as it's new but I might be wrong.  
However, I guess you can perform any low level HTTP REST call using the PHP client, so may be you can do it yourself?

See REST API doc: [https://www.elastic.co/guide/en/elasticsearch/reference/5.1/docs-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/docs-update-by-query.html)

HTH

---

<div class="post-metadata">

**Author:** ![tanimoto](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tanimoto](https://discuss.elastic.co/u/tanimoto)\
**Post date:** [December 28, 2016, 10:33am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/9 "2016-12-28T10:33:00Z")

</div>

Yeah, this is the solution at the moment creating HTTP REST by my self.

I will rethink how to achieve it again.

Anyway, thanks a lot.

---

<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:** [January 25, 2017, 10:33am UTC](https://discuss.elastic.co/t/can-i-update-delete-get-index-multiple-data-on-php-client-at-once/70108/10 "2017-01-25T10:33:22Z")

</div>

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