Elasticsearch中,有时需要人工指定分片和副本数量,那么这个在PHP中如何处理呢?

官方示例:

$client = ClientBuilder::create()->build();
$params = [
'index' => 'my_index',
'body' => [
'settings' => [
'number_of_shards' => 3,
'number_of_replicas' => 2
],
'mappings' => [
'my_type' => [
'_source' => [
'enabled' => true
],
'properties' => [
'first_name' => [
'type' => 'string',
'analyzer' => 'standard'
],
'age' => [
'type' => 'integer'
]
]
]
]
]
];


// Create the index with mappings and settings now
$response = $client->indices()->create($params);

重点是settings部分。可以看出,这数量要在创建索引的时候设置好。

参考资料:Index management operations



与《Elasticsearch-PHP 设置分片和副本数量的方法》相关的博文:

留言