Elasticsearch-PHP reindex not working as expected

Documentation on reindex API: https://www.elastic.co/guide/en/elasticsearch/client/php-api/6.0/ElasticsearchPHP_Endpoints.html#Elasticsearch_Clientreindex_reindex

/*
$params['refresh']             = (boolean) Should the effected indexes be refreshed?
       ['timeout']             = (time) Time each individual bulk request should wait for shards that are unavailable
       ['consistency']         = (enum) Explicit write consistency setting for the operation
       ['wait_for_completion'] = (boolean) Should the request should block until the reindex is complete
       ['requests_per_second'] = (float) The throttle for this request in sub-requests per second. 0 means set no throttle
       ['body']                = (array) The search definition using the Query DSL and the prototype for the index request (Required)
       ['body']  = (array) Request body
*/

$params = [
    // ...
];

$client = ClientBuilder::create()->build();
$response = $client->reindex($params);

The following ['body'] is not that clear.

['body'] = (array) The search definition using the Query DSL and the prototype for the index request (Required)

Elasticsearch version is 5.6.13.

I was attempting to reindex a source index to a destination index using the PHP client's reindex API above. The sourceIndex has only 1 document.

Request:

$params = [
    'body' => [
        'source' => [
            'index'  => 'sourceIndex',
        ],
        'dest' => [
            'index' => 'destIndex'
        ]
    ]
];
$response = $client->reindex($params);

Response:

(
    [took] => 2
    [timed_out] =>
    [total] => 0
    [updated] => 0
    [created] => 0
    [deleted] => 0
    [batches] => 0
    [version_conflicts] => 0
    [noops] => 0
    [retries] => Array
        (
            [bulk] => 0
            [search] => 0
        )

    [throttled_millis] => 0
    [requests_per_second] => -1
    [throttled_until_millis] => 0
    [failures] => Array
        (
        )

)

As you can see, the document reindexed is 0 ([total] => 0).

It works just fine when done using Kibana's DevTool, but not elasticsearch-php client.

POST _reindex
{
  "source": {
    "index": "sourceIndex"
  },
  "dest": {
    "index": "destIndex"
  }
}

Any help is appreciated. If you need more details to help answer this question, let me know.

FYI - In case someone happens to face the same issue. The issue was that the source index had refresh_interval set to -1. For reindex operation to work, just refresh the source index prior to calling the _reindex API.

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