请知悉:本文最近一次更新为 3年 前,文中内容可能已经过时。

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 设置分片和副本数量的方法》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌