Elasticsearch-PHP 命名空间

来源:互联网 发布:js 浏览新闻 不刷新 编辑:程序博客网 时间:2024/06/06 16:40

命名空间

客户端有很多命名空间,通常能够暴漏出他管理的功能。命名空间对应Elasticsearch各种管理的端点。如下是完成的命名空间的列表:

命名空间功能indices()以指数为中心的统计数据和信息nodes()以节点为中心的统计数据和信息
cluster()以集群为中心的统计数据和信息
snapshot()快照/还原您的群和指示器的方法
cat()访问Cat API(这是通常用于的独立从命令行访问
有些方法可以在不同的命名空间下使用,给你相同的信息,但是分组到不同的上下文。如果要查看这些命名空间是如何工作的,让我们来看看_stats的输出:

$client = new Elasticsearch\Client();// Index Stats// Corresponds to curl -XGET localhost:9200/_stats$response = $client->indices()->stats();// Node Stats// Corresponds to curl -XGET localhost:9200/_nodes/stats$response = $client->nodes()->stats();// Cluster Stats// Corresponds to curl -XGET localhost:9200/_cluster/stats$response = $client->cluster()->stats();

正如你所看到的,同样的 stats() 调用在三个不同的命名空间。有时候方法需要参数。这些参数的工作原理就像其它库中的方法一样。

例如我们可以请求一个特定的索引或多个索引信息的统计。

 

$client = new Elasticsearch\Client();// Corresponds to curl -XGET localhost:9200/my_index/_stats$params['index'] = 'my_index';$response = $client->indices()->stats($params);// Corresponds to curl -XGET localhost:9200/my_index1,my_index2/_stats$params['index'] = array('my_index1', 'my_index2');$response = $client->indices()->stats($params);

另一个例子,如何在现有索引中添加一个别名。

$params['body'] = array(    'actions' => array(        array(            'add' => array(                'index' => 'myindex',                'alias' => 'myalias'            )        )    ));$client->indices()->updateAliases($params);

请注意 stats 调用和 updateAlias 是如何接受一个多样化的参数,每一个都是根据特定API的需要。stats API仅仅需要一个索引名称,然而 updateAlias 需要一个body上的动作。

0 0
原创粉丝点击