簡體   English   中英

如何使用 Elasticsearch-PHP 客戶端獲取 Elasticsearch 索引名稱列表?

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

我需要 Elasticsearch 中匹配特定模式的索引名稱列表。 使用 Kibana 我沒有問題,但我根本不知道如何使用 Elasticsearch-PHP 客戶端做同樣的事情。

示例:

Trying to get indices matching the name pattern "*.foo.bar"
With Kibana: GET /_cat/indices/*.foo.bar

有人知道嗎? 我在 Elasticsearch-PHP 文檔中沒有找到任何關於此的內容。

我通過反復試驗弄明白了。

獲取與模式匹配的索引列表的方法是:

$client = ClientBuilder::create()->build();
$indices = $client->cat()->indices(array('index' => '*.foo.bar'));

在此響應 (7.2) 時的當前文檔中,您可以找到您正在尋找的端點GET /_cat/indices/的文檔。

因此,您可以使用以下代碼獲取索引:

$params = [
    // Example of another param
    'v' => true,
    // ...
    'index' => '*.foo.bar'
];

$indices = $client->cat()->indices($params);

該文檔沒有明確說明index參數,但您可以看到如何在CatNamespace::indices()方法定義中設置CatNamespace::indices()

public function indices(array $params = [])
{
    $index = $this->extractArgument($params, 'index');
    ...
    $endpoint->setIndex($index);
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM