在跨集群搜索前解析集群
Elastic Stack Serverless
您可以使用 _resolve/cluster
端点在跨集群搜索之前识别要从搜索中排除的集群或索引。
在以下情况下,您可能希望从搜索中排除集群或索引:
- 远程集群不可用,并且配置为
skip_unavailable
=false
。 在这些条件下执行跨集群搜索将导致 整个搜索失败。 - 集群没有与索引表达式匹配的索引、别名或数据流,或者您的用户没有搜索它们的权限。 例如,如果您的索引表达式是
logs*,remote1:logs*
并且remote1
集群没有匹配的索引,则如果包含在跨集群搜索中,该集群将不返回任何结果。 - 索引表达式,与您指定的任何查询参数相结合,可能会触发异常。 在这些情况下,
_resolve/cluster
响应中将存在“error”字段。 这也是显示安全性/权限错误的地方。 - 远程集群正在运行不支持您的搜索所需功能的旧版本。
GET /_resolve/cluster/my-index*,clust*:my-index*
API 返回以下响应:
{
"(local)": {
"connected": true,
"skip_unavailable": false,
"matching_indices": true,
"version": {
"number": "8.13.0",
"build_flavor": "default",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
}
},
"cluster_one": {
"connected": true,
"skip_unavailable": true,
"matching_indices": true,
"version": {
"number": "8.13.0",
"build_flavor": "default",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
}
},
"cluster_two": {
"connected": true,
"skip_unavailable": false,
"matching_indices": true,
"version": {
"number": "8.13.0",
"build_flavor": "default",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
}
}
}
- 每个集群都有自己的响应部分。 您将请求发送到的集群标记为“(本地)”。
- 查询集群尝试向每个远程集群发出请求。 如果成功,则
connected
=true
。 - 每个远程集群的
skip_unavailable
设置,如本地集群上配置的那样。 - 指示任何索引、别名或数据流是否与为该集群指定的索引表达式匹配。
- Elasticsearch 服务器版本。
以下请求显示了修改查询如何防止搜索失败的几个示例。 另请注意,发送了 5 秒的 timeout
,这设置了查询等待远程集群响应的最长时间。
GET /_resolve/cluster/not-present,clust*:my-index*,oldcluster:*?ignore_unavailable=false&timeout=5s
{
"(local)": {
"connected": true,
"skip_unavailable": false,
"error": "no such index [not_present]"
},
"cluster_one": {
"connected": true,
"skip_unavailable": true,
"matching_indices": false,
"version": {
"number": "8.13.0",
"build_flavor": "default",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
}
},
"cluster_two": {
"connected": false,
"skip_unavailable": false
},
"cluster_three": {
"connected": false,
"skip_unavailable": false,
"error": "Request timed out before receiving a response from the remote cluster"
},
"oldcluster": {
"connected": true,
"skip_unavailable": false,
"matching_indices": true
}
}
- 本地集群没有名为
not_present
的索引。 使用指定的ignore_unavailable=false
参数对其进行搜索将返回“no such index”错误。 其他类型的错误也可能出现在此处,例如当用户没有授权搜索指定的索引时的安全权限错误。 cluster_one
远程集群没有与模式my-index*
匹配的索引。 可能没有与该模式匹配的索引,或者该索引可能已关闭。(您可以使用 resolve index API 来检查这一点。)cluster_two
远程集群未连接(连接尝试失败)。 由于此集群标记为skip_unavailable=false
,因此您可能应该通过将-cluster_two:*
添加到搜索索引表达式中来将此集群从搜索中排除。- 对于
cluster_three
,错误消息指示此远程集群未在指定的 5 秒超时窗口内响应,因此它也被标记为未连接。 oldcluster
远程集群显示它具有匹配的索引,但不包括版本信息。 这表明集群版本早于 8.13.0 中引入的_resolve/cluster
API。,因此您可能希望将其从跨集群搜索中排除。(注意:端点能够判断是否存在匹配的索引,因为它退回到使用 resolve index API。)