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

my php file is as below.

<?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

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

you mean, PHP client can't do it?

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

https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_indexing_documents.html#_bulk_indexing

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

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?

bulk API supports update requests.

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

HTH

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.

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