- Exploring Your Cluster
探索你的集群
The rest api
rest 风格的 api
Now that we have our node (and cluster) up and running, the next step is to understand how to
现在 我们已经将我们自己的节点(和集群) 启动并运行着, 下一个步骤是知道如何
communicate with it. Fortunately, Elasticsearch provides a very comprehensive and powerful
和它交流. 幸运的是, elatsicsearch 提供了一套非常 全面 和 能力强大
REST API that you can use to interact with your cluster. Among the few things that can be done
的rest 风格的api 让你可以使用它用来和你的集群交互, 我们可以使用api 做一些事情 如下:
with the API are as follows:
- Check your cluster, node, and index health, status, and statistics
- 检查 你的集群 ,节点,和索引健康度,状态及统计
- Administer your cluster, node, and index data and metadata
- 管理你的集群,节点和索引数据及元数据
- Perform CRUD (Create, Read, Update, and Delete) and search operations against your indexes
- 执行 CRUD(创建,读取,更新 和 删除) 和 针对你的索引进行搜索操作
- Execute advanced search operations such as paging, sorting, filtering, scripting, aggregations, and many others
- 执行高级搜索操作比如 分页,排序,过滤, 脚本执行,聚合,及很多其他的操作
集群健康度
- Cluster Health
Let’s start with a basic health check, which we can use to see how our cluster is doing. We’ll be
让我们从一个基本的健康检查开始,我们可以用来看下我们的集群的运行情况, 我们可以使用
using curl to do this but you can use any tool that allows you to make HTTP/REST calls. Let’s
curl 来做这个,但是你也可以使用其他任何允许你使用http/rest发起请求的工具, 让我们
assume that we are still on the same node where we started Elasticsearch on and open another
假设 我们仍然在启动es 的节点上 并打开另外一个
command shell window.
shell命令 窗口
To check the cluster health, we will be using the _cat API. You can run the command below in
我们将通过使用_cat api 来检查集群的健康情况 。 你可以在 kibana 的控制台通过点击 "VIEW
Kibana’s Console by clicking "VIEW IN CONSOLE" or with curl
by clicking the "COPY AS CURL"
IN CONSOLE"执行以下命令, 或者 通过点击 下方的链接 "COPY AS CURL" 并复制到 控制台使
link below and pasting it into a terminal.
用 curl 进行 检查
And the response:
然后我们可以看到响应:
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1475247709 17:01:49 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
We can see that our cluster named "elasticsearch" is up with a green status.
我们可以看到我们名叫"elasticsearch"的集群正在以一个绿色的状态运行着
Whenever we ask for the cluster health, we either get green, yellow, or red.
无论啥时候 我们 询问集训健康度 ,我们不就是得到 绿色, 黄色 不就是 红色
- Green - everything is good (cluster is fully functional)
- 绿色,一切正常(集群提供全部功能)
- Yellow - all data is available but some replicas are not yet allocated (cluster is fully functional)
- 黄色 - 所有的数据都可用但是有一部分分片还没被分配(集群功能齐全)
- Red - some data is not available for whatever reason (cluster is partially functional)
- 红色-部分数据由于 某种原因 不可用(集群提供部分功能)
Note: When a cluster is red, it will continue to serve search requests from the available shards
注意: 当集群是红色, 他将继续 从可用的分片提供查询请求服务 ,
but you will likely need to fix it ASAP since there are unassigned shards.
但是你 可能需要尽快修复它 因为 有没有被分配的分片
Also from the above response, we can see a total of 1 node and that we have 0 shards since we
从以上响应,我们也可以看出总共有一个节点 并且我们只有0个分片 因为我们
have no data in it yet. Note that since we are using the default cluster name (elasticsearch) and
还没数据在里面,,,,, 注意因为我们使用默认的集群 名字(elasticsearch) 而且
since Elasticsearch uses unicast network discovery by default to find other nodes on the same
因为 Elasticsearch 默认使用单播 网络发现 用来 发现其他节点在同一个
machine, it is possible that you could accidentally start up more than one node on your computer
机器, 所以有可能你不小心启动了超过一个节点在你的电脑上
and have them all join a single cluster. In this scenario, you may see more than 1 node in the
并且 让他们都加入一个单一集群中。 在这种情况下, 你可以在以上响应中看到超过一个节点
above response.
We can also get a list of nodes in our cluster as follows:
我们也可以像下面一样得到我们集群中的节点列表
并且得到响应:
Here, we can see our one node named "PB2SGZY", which is the single node that is currently in our cluster.
这里,我们可以看到我们一个名叫"PB2SGZY"的节点, 现在是我们集群中的单个节点