创建索引$params = ['index' => 'test'];
$client->indices()->create($params);
这里index是必填参数,除此之外,还有两个可选参数:timeout、body。timeout是设置超时时间,body是一个数组,可以接收mappings,settings等。删除索引$client->indices()->delete(['index' => 'test']);设置索引
前面创建索引说到可以将settings等通过body传入,也可以单独调用接口设置:$params = [
'index' => 'my_index',
'body' => [
'settings' => [
'number_of_replicas' => 0,
'refresh_interval' => -1
]
]
];
$response = $client->indices()->putSettings($params);获取索引设置// 单个获取
$params = ['index' => 'my_index'];
$response = $client->indices()->getSettings($params);
// 同时获取多个
$params = [
'index' => [ 'my_index', 'my_index2' ]
];
$response = $client->indices()->getSettings($params);设置mappings
settings可以单独设置,mappings也一样可以单独设置。// Set the index and type
$params = [
'index' => 'my_index',
'body' => [
'_source' => [
'enabled' => true
],
'properties' => [
'first_name' => [
'type' => 'text',
'analyzer' => 'standard'
],
'age' => [
'type' => 'integer'
]
]
]
];
// Update the index mapping
$client->indices()->putMapping($params);获取mappings// Get mappings for all indexes
$response = $client->indices()->getMapping();
// Get mappings in 'my_index'
$params = ['index' => 'my_index'];
$response = $client->indices()->getMapping($params);
// Get mappings for two indexes
$params = [
'index' => [ 'my_index', 'my_index2' ]
];
$response = $client->indices()->getMapping($params);