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


(tanimoto) #1

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


(David Pilato) #2

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


(tanimoto) #3

you mean, PHP client can't do it?


(tanimoto) #4

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


(David Pilato) #5

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


(tanimoto) #6

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


(tanimoto) #7

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?


(David Pilato) #8

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


(tanimoto) #9

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.


(system) #10

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