I need a list of index names from Elasticsearch that match a certain pattern. Using Kibana I've no problem doing this, but I simply can't figure out how to do the same with the Elasticsearch-PHP client.
Example:
Trying to get indices matching the name pattern "*.foo.bar"
With Kibana: GET /_cat/indices/*.foo.bar
Does anyone know? I've found nothing on this in the Elasticsearch-PHP docs.
I figured it out through trial and error.
The way to get a list of indices matching a pattern is:
$client = ClientBuilder::create()->build();
$indices = $client->cat()->indices(array('index' => '*.foo.bar'));
In the current docs at the time of this response (7.2), you can find the documentation for the endpoint GET /_cat/indices/
that you're looking for.
So you can get the indices with this code:
$params = [
// Example of another param
'v' => true,
// ...
'index' => '*.foo.bar'
];
$indices = $client->cat()->indices($params);
The documentation doesn't explicitly states about the index
param, but you can see how the index is set inside the CatNamespace::indices()
method definition.
public function indices(array $params = [])
{
$index = $this->extractArgument($params, 'index');
...
$endpoint->setIndex($index);
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With