Elasticsearch专题精讲—— REST APIs —— Cluster APIs —— Node specification(节点过滤)

 REST APIs —— Cluster APIs —— Node specification(节点过滤)

https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster.html#cluster-nodes 

Some cluster-level APIs may operate on a subset of the nodes which can be specified with node filters. For example, the Task Management, Nodes Stats, and Nodes Info APIs can all report results from a filtered set of nodes rather than from all nodes.

一些集群级别的API可能会针对节点的子集进行操作,这可以通过节点过滤器进行指定。例如,Task Management(任务管理)(https://www.elastic.co/guide/en/elasticsearch/reference/8.8/tasks.html)、Nodes Stats(节点统计信息)(https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster-nodes-stats.html)和Nodes Info APIs(https://www.elastic.co/guide/en/elasticsearch/reference/8.8/cluster-nodes-info.html)都可以报告来自被筛选节点的结果,而不是所有节点的结果。

Node filters are written as a comma-separated list of individual filters, each of which adds or removes nodes from the chosen subset. Each filter can be one of the following:

节点过滤器是用逗号分隔的单个过滤器列表形式,每个过滤器都会添加和删除所选子集中的节点。支持的过滤器如下所示:

节点过滤器
过滤器 描述
_all 将所有节点添加到子集中
_local 将本地节点添加到子集中
_master 将主节点添加到子集中
a node id or name 把指定的 ID 或 名称的节点添加到子集中
a an IP address or hostname 把指定 IP 或主机名称的节点添加到子集中
a pattern, using * wildcards 使用 * 通配符的模式,它将所有节点添加到名称、地址或主机名与模式匹配的子集中。
master:true, data:true, ingest:true, voting_only:true, ml:true, or coordinating_only:true master:true(添加所有合格的 master 节点)、data:true(添加所有数据节点)、ingest:true(添加所有接收节点)、voting_only:true(添加所有仅为投票目的而存在的节点)、ml:true(添加所有机器学习节点)或 coordinating_only:true(添加所有仅为协调目的而存在的节点),将它们加入到子集中。
master:false, data:false, ingest:false, voting_only:true, ml:false, or coordinating_only:false master:false(删除所有合格的 master 节点)、data:false(删除所有数据节点)、ingest:false(删除所有接收节点)、voting_only:true(删除所有非仅为投票目的而存在的节点)、ml:false(删除所有机器学习节点)或 coordinating_only:false(删除所有非仅为协调目的而存在的节点),将它们从子集中移除。
a pair of patterns, using * wildcards, of the form attrname:attrvalue 这个匹配模式使用通配符*,是形如attrname:attrvalue的模式。当名称和值匹配时,将自定义节点属性添加到子集中,所有命名和值都匹配的节点。自定义节点属性通过在配置文件中设置格式为node.attr.attrname: attrvalue的属性进行配置。

node filters run in the order in which they are given, which is important if using filters that remove nodes from the set. For example _all,master:false means all the nodes except the master-eligible ones, but master:false,_all means the same as _all because the _all filter runs after the master:false filter.

节点过滤器按给定顺序运行,如果使用可以从集合中删除节点的过滤器,则该顺序非常重要。例如,_all,master:false 表示除了主要资格节点外的所有节点,但是 master:false,_all 的含义与 _all 相同,因为 _all 过滤器在 master:false 过滤器之后运行。

我理解意思是说: 当对 Elasticsearch 的一组节点应用多个过滤器时,过滤器的应用顺序会影响结果。例如,如果使用_all,master:false过滤器,则意味着选择所有非主控节点(master-eligible)的所有节点,但如果使用master:false,_all过滤器,则选择的节点与使用_all过滤器相同,因为_all过滤器在master:false过滤器之后运行,相当于逆序执行。因此,在使用节点过滤器时,请注意各个过滤器的顺序,以确保正确的节点集被选择。

当使用 master:false,_all 过滤器时,Elasticsearch 首先会筛选出所有不是主控节点的节点,然后对这些节点再次应用 _all 过滤器来选择所有剩余的节点。由于 _all 过滤器是所有其他过滤器的默认过滤器,它不做任何过滤,所以最终选择的节点与使用 _all,master:false 过滤器时选择的节点是一样的,因为它们都选择了所有非主控节点。

if no filters are given, the default is to select all nodes. However, if any filters are given then they run starting with an empty chosen subset. This means that filters such as master:false which remove nodes from the chosen subset are only useful if they come after some other filters. When used on its own, master:false selects no nodes.

如果没有给出任何过滤器,则默认选择所有节点。然而,如果给出了任何过滤器,则它们将从一个空的被选择子集开始运行。这意味着像 master:false 这样的过滤器,可以从被选择的子集中删除节点,只有在其后面跟随其他过滤器时才有用。当单独使用 master:false 时,它不会选择任何节点。

Here are some examples of the use of node filters with the Nodes Info APIs.

下面是一些使用节点过滤器和节点信息 API 的示例。

        # If no filters are given, the default is to select all nodes (默认选择所有节点)
        curl -X GET "localhost:9200/_nodes?pretty"

        # Explicitly select all nodes(显示所有节点)
        curl -X GET "localhost:9200/_nodes/_all?pretty"

        # Select just the local node(只选取本地节点)
        curl -X GET "localhost:9200/_nodes/_local?pretty"

        # Select the elected master node(只选取主节点)
        curl -X GET "localhost:9200/_nodes/_master?pretty"

        # Select nodes by name, which can include wildcards(通过指定的 名称 选取节点,可以包含通配符 *)
        curl -X GET "localhost:9200/_nodes/node_name_goes_here?pretty"
        curl -X GET "localhost:9200/_nodes/node_name_goes_*?pretty"

        # Select nodes by address, which can include wildcards(通过指定的 IP 选取节点,可以包含通配符 *)
        curl -X GET "localhost:9200/_nodes/10.0.0.3,10.0.0.4?pretty"
        curl -X GET "localhost:9200/_nodes/10.0.0.*?pretty"
        
        # Select nodes by role(通过 node role 选取节点)
        curl -X GET "localhost:9200/_nodes/_all,master:false?pretty"
        curl -X GET "localhost:9200/_nodes/data:true,ingest:true?pretty"
        curl -X GET "localhost:9200/_nodes/coordinating_only:true?pretty"
        curl -X GET "localhost:9200/_nodes/master:true,voting_only:false?pretty"

        # Select nodes by custom attribute (e.g. with something like `node.attr.rack: 2` in the configuration file)(选择具有自定义属性的节点来执行某些操作)
        curl -X GET "localhost:9200/_nodes/rack:2?pretty"
        curl -X GET "localhost:9200/_nodes/ra*:2?pretty"
        curl -X GET "localhost:9200/_nodes/ra*:2*?pretty"
posted @ 2023-06-24 20:19  左扬  阅读(12)  评论(0编辑  收藏  举报
levels of contents