ElasticSearch:如何检查文档 from/goes 到哪个 node/replica?

ElasticSearch: How to check which node/replica does the document comes from/goes to?

假设我有 5 个数据节点。然后我保存一个 Person 文档。现在有几个问题:

  1. 如何找到保存文档保存到哪个节点?

  2. 在将一个 Person 文档保存到具有两个副本的节点后,我如何查询此 Person 并获取 replica/node 结果答案的信息来自?

  3. 如何检查文档在一个节点的两个副本中的可用速度?

编辑

使用案例如下: 通常如何在主分片写入新数据但数据尚未与副本同步的情况下确保一致性。同时,正在查询副本以获取在查询副本时仅存在于主分片中的新数据。我非常想知道 DETAILS 在最后一段 of the distributed read documentation ===> but on the other hand here the doc says about query phase 中描述的情况的一致性,即查询每个主副本和副本并构建 优先级队列 稍后合并,因此主分片的结果将包含在基于全局排序结果集的合并队列中,该结果集是在协调节点的所有优先级队列中构建的。


也就是说。 我想确保我的分布式 ES 集群中的数据一致性。现在我想测试是否可以发生以下情况。假设我有一个包含 5 个节点的集群,并且数据只放在一个节点上(例如 node2 主分片)。在数据有时间复制到剩余的副本之前,我向 node3 查询了这个新数据,理论上应该有数据的副本,但在 node2 更改后还没有得到它.因此,在这种情况下,提交给 node3 请求新数据的查询不会 return 新数据,即使它们已被放入 'node2'。

How can I find which node is the saved document saved to?

更正确的问题是文档保存在哪个分片上,因为分片可以在集群中移动。您可以使用 _search_shards API 并提供文档的 ID:

GET /index/type/_search_shards?routing=4

After saving one Person document to a node with two replicas how can I query for this Person and get info which replica/node does the resulting answer comes from?

我认为你做起来并不容易。您可以降低 slowlogs 的阈值并检查搜索请求的特定 fetch 阶段的慢速日志文件,以查看某个节点是否记录了该阶段。如果您在慢速日志中找到 fetch,这意味着结果(如果它只是一个文档)来自该节点的碎片。

How can I check how fast the document is available in two replicas of a node?

您从 运行 索引操作返回的响应时间是包括分片所有副本(主副本及其副本)的索引的时间:https://www.elastic.co/guide/en/elasticsearch/guide/current/distrib-write.html#distrib-write

If this might happen how can I control the replication phases/state so that I can tell if the replication is complete?

认为你可以尝试使用consistency: allhttps://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-consistency)这意味着索引操作return只有当所有其他分片副本已将文档编入索引。但我认为这不会停止在正确的时间对仍在从主数据库索引文档的副本之一进行的查询。

How can I tell if the replica is consistent with the primary shard or not that's difficult.

我认为只有在分片的那两个副本上查询数据,您才能看到副本是否不同步。

If I can't control this replication flow and data consistency how can I eliminate potential inconsistencies

如果您发现不一致,我认为唯一的选择是将您的副本数设置为 0(删除副本),然后恢复为初始值。基本上,从主副本重新创建副本。