How can I get a list of Elasticsearch index names using the Elasticsearch-PHP client? How can I get a list of Elasticsearch index names using the Elasticsearch-PHP client? elasticsearch elasticsearch

How can I get a list of Elasticsearch index names using the Elasticsearch-PHP client?


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);    ...}