快速检查一个弹性搜索索引是否会返回搜索命中 [英] quick check whether an elasticsearch index will return search hits

查看:138
本文介绍了快速检查一个弹性搜索索引是否会返回搜索命中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们针对弹性搜索源针对几个索引运行命令,如下所示:

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

大部分时间都能运行得很好,我们可以解析我们需要的结果。



但是当索引处于坏状态时 - 也许索引有一个滞后,或者某些碎片正在起作用 - 上面的查询将不会返回任何结果,因为没有匹配的记录或索引在某种程度上不稳定是不可能的。



我一直在看,但有点不知所措。有没有一些我可以运行的查询,会给出一个是/否答案,可以依赖这些索引进行搜索吗?

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



1)您可以使用群集健康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,
initializi ng_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,
ocating_shards:0,
initializing_shards:0,
unassigned_shards:5
}
}
}

2)如果你想有一个较少的详细的答案,或仅仅过滤某些具体的信息,你可以依靠 _ cat API,允许您自定义输出。但是,输出不再是JSON。



例如,如果只想要索引的名称和运行状况,以下请求将会执行以下操作: / p>

  GET _cat / indices / my_index?h = index,health& v 
pre>

通过输出:

  index health 
my_index yellow

请注意,列标题仅由于详细标志(

要获得有关可用列的完整列表,请使用帮助参数:

  GET _cat / indices?help 


We're running commands against an elasticsearch source against a few indices like so:

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

Works great most of the time, and we can parse the results we need.

However when the indices are in a bad state-- maybe there's been a lag in indexing, or some shards are acting up-- the query above will return no results, and it's impossible to know whether it's because there's no matching records or the index is unstable in some way.

I've been looking at the elastic search indices recovery API but am a bit overwhelmed. Are there some queries I can run that will give a yes/no answer to 'can a search against these indices be relied upon at the moment?'

解决方案

You have multiple ways to get this information.

1) You can use the cluster health API at the indices level like this :

GET _cluster/health/my_index?level=indices

This will output the status of the cluster, with information about status and shards of the index 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) If you want to have a less verbose answer, or to filter only on some specific information, you can rely on the _cat API, which allows you to customize the output. However, the output is no longer a JSON.

For example, if you want only the name and health status of the indices, the following request will do the trick :

GET _cat/indices/my_index?h=index,health&v

by outputting this :

index    health 
my_index yellow

Note that the column headers are shown only because of the verbose flag (v GET parameter in the previous request).

To have a complete list of what columns are available, use the help parameter :

GET _cat/indices?help

这篇关于快速检查一个弹性搜索索引是否会返回搜索命中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆