# Elasticsearch-PHP reindex not working as expected

**URL:** <https://discuss.elastic.co/t/elasticsearch-php-reindex-not-working-as-expected/156883>\
**Category:** Elasticsearch\
**Created:** [November 15, 2018, 2:04pm UTC](https://discuss.elastic.co/t/elasticsearch-php-reindex-not-working-as-expected/156883 "2018-11-15T14:04:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhondup](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dhondup](https://discuss.elastic.co/u/dhondup)\
**Post date:** [November 15, 2018, 2:04pm UTC](https://discuss.elastic.co/t/elasticsearch-php-reindex-not-working-as-expected/156883/1 "2018-11-15T14:04:11Z")

</div>

Documentation on reindex API: [https://www.elastic.co/guide/en/elasticsearch/client/php-api/6.0/ElasticsearchPHP\_Endpoints.html#Elasticsearch\_Clientreindex\_reindex](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.

---

<div class="post-metadata">

**Author:** ![dhondup](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dhondup](https://discuss.elastic.co/u/dhondup)\
**Post date:** [November 16, 2018, 8:32pm UTC](https://discuss.elastic.co/t/elasticsearch-php-reindex-not-working-as-expected/156883/2 "2018-11-16T20:32:53Z")

</div>

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.

---

<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:** [December 14, 2018, 8:32pm UTC](https://discuss.elastic.co/t/elasticsearch-php-reindex-not-working-as-expected/156883/3 "2018-12-14T20:32:54Z")

</div>

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