7

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.

Rodrigo García
  • 1,357
  • 15
  • 26
Johan Fredrik Varen
  • 3,796
  • 7
  • 32
  • 42

2 Answers2

7

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'));
Johan Fredrik Varen
  • 3,796
  • 7
  • 32
  • 42
1

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);
    ...
}
Rodrigo García
  • 1,357
  • 15
  • 26