Namespaces

未匹配的标注

命名空间

客户端有很多「命名空间」,通常是一些公开可管理的功能。命名空间对应着 Elasticseach 中各种可管理的 endpoints。下面是全部的命名空间:

命名空间 功能
indices() 索引数据统计和显示索引信息
nodes() 节点数据统计和显示节点信息
cluster() 集群数据统计和显示集群信息
snapshot() 对集群和索引进行产生快照或恢复数据
cat() 执行 Cat API (通常在命令使用)

一些方法在不同的命名空间都可以使用,虽然返回相同的信息,但是却在不同的上下文环境。想知道命名空间如何运作的,请看 _stats 输出信息:

$client = ClientBuilder::create()->build();

// 索引统计
// 对应于 curl -XGET localhost:9200/_stats
$response = $client->indices()->stats();

// 节点统计
// 对应于 curl -XGET localhost:9200/_nodes/stats
$response = $client->nodes()->stats();

// 集群统计
// 对应于 -XGET localhost:9200/_cluster/stats
$response = $client->cluster()->stats();

正如你所看到的,在三种不同的命名空间中都调用了相同的 stats() 方法。有些方法需要参数,这些参数写法与其他库中的函数写法相同。

例如,我们可以请求单个索引或者多个索引的统计信息:

$client = ClientBuilder::create()->build();

// 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);

请遵循 API 来合理的调用 stats 和 updateAlias 的各种参数。  stats API 只需要一个索引名称, updateAlias 需要一个完整的行为。

本文章首发在 LearnKu.com 网站上。

本译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。

原文地址:https://learnku.com/docs/elasticsearch-p...

译文地址:https://learnku.com/docs/elasticsearch-p...

上一篇 下一篇
贡献者:3
讨论数量: 0
发起讨论 查看所有版本


暂无话题~