gpt4 book ai didi

elasticsearch - 快速检查Elasticsearch索引是否会返回搜索结果

转载 作者:行者123 更新时间:2023-12-03 02:04:22 25 4
gpt4 key购买 nike

我们正在针对Elasticsearch源针对一些索引运行命令,如下所示:

curl -XGET 'http://es-server:9200/logstash-2015.01.28,logstash-2015.01.27/_search?pretty' -d @/a_query_file_in_json_format

大多数时候效果很好,我们可以解析所需的结果。

但是,当索引处于不良状态时-可能是索引编制滞后,或者某些分片正在工作-上面的查询将不会返回任何结果,并且无法知道是否是因为没有匹配的记录或索引在某种程度上是不稳定的。

我一直在看 elastic search indices recovery API,但有点不知所措。我是否可以运行一些查询,以给出“是/否”的答案,“目前是否可以依靠这些索引进行搜索?”

最佳答案

您有多种获取此信息的方法。

1)您可以像这样在索引级别使用cluster health API:

GET _cluster/health/my_index?level=indices

这将输出集群的状态,以及有关索引 my_index的状态和碎片的信息:
{
"cluster_name": "elasticsearch_thomas",
"status": "yellow",
"timed_out": false,
"number_of_nodes": 1,
"number_of_data_nodes": 1,
"active_primary_shards": 5,
"active_shards": 5,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 5,
"indices": {
"my_index": {
"status": "yellow",
"number_of_shards": 5,
"number_of_replicas": 1,
"active_primary_shards": 5,
"active_shards": 5,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 5
}
}
}

2)如果您希望得到更简洁的答案,或者只过滤某些特定信息,则可以依赖 _cat API,该API允许您自定义输出。但是,输出不再是JSON。

例如,如果只需要索引的名称和运行状况,则可以使用以下请求来解决:
GET _cat/indices/my_index?h=index,health&v

通过输出:
index    health 
my_index yellow

请注意,仅由于详细标志(上一个请求中的 v GET参数)而显示列标题。

要获得可用列的完整列表,请使用 help参数:
GET _cat/indices?help

关于elasticsearch - 快速检查Elasticsearch索引是否会返回搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28196759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com