Elasticsearch-PHP重新索引无法正常工作

时间:2018-11-15 14:35:25

标签: php elasticsearch elasticsearch-5 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);

Elasticsearch版本是5.6.13。

我试图使用上述PHP客户端的reindex API将源索引重新索引为目标索引。 sourceIndex只有1个文档。

请求:

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

响应:

(
    [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
        (
        )

)

如您所见,重新索引的文档为0([total] => 0)。

使用Kibana的DevTool而不是elasticsearch-php客户端完成时,效果很好。

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

感谢您的帮助。如果您需要更多详细信息来帮助回答这个问题,请告诉我。

1 个答案:

答案 0 :(得分:0)

仅供参考-如果有人碰巧遇到相同的问题。问题是源索引的refresh_interval设置为-1。为了使重新索引操作起作用,只需在调用_reindex API之前刷新源索引即可。