elasticsearch在查询中使用别名时查找哪些索引包含命中

vpfxa7rd  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(2)|浏览(498)

我的集群中有1000个按天(基于时间)的索引。有没有办法在es服务器端监视或找出哪些索引 contain hits 当查询使用 alias . e、 g.考虑我的客户提出的以下问题:

GET index_alias/_search?q=Product_Serial_Num:ABCD

别名 index_alias Map到所有 day-wise indices 在es 6.8.6集群中 1200 . 原因是查询是用来获取历史记录的 Product_Serial_Num . 因此,不可能事先知道哪一天的指数会有数据。这就是 index_alias 已Map到 all indices . 当客户启动上面的查询时,我想在es服务器端监视它并找出 indices 当查询命中它们时实际返回数据。有没有办法在不修改客户端任何内容的情况下确定这一点?
这样做的目的是找出“哪些指数”受到的冲击最大,比如 last-n-days (30, 60, 90) 然后相应地应用hot-warm体系结构,比如在热节点上有最近60天的索引,在热节点上休息。
或者如果有更好的方法来确定,请分享。
谢谢。

epggiuax

epggiuax1#

您应该已经在每个命中元数据中获得了有关索引的信息。请看下面的示例响应:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test_index_01",
        "_type" : "_doc",
        "_id" : "doc_id_1",
        "_score" : 1.0
      },
      {
        "_index" : "test_index_01",
        "_type" : "_doc",
        "_id" : "doc_id_5",
        "_score" : 1.0
      }
    ]
  }
}

在上面的响应中,您可以看到每个命中都包含元字段,其中一个这样的字段是 _index . 此字段的值是找到文档的索引的实际名称(不是别名)。你可以根据需要使用这些信息。
另一种查找别名当前指向哪个索引的方法是使用get alias api。

GET _alias/test_alias

样本响应:

{
  "test_index_01" : {
    "aliases" : {
      "test_alias" : { }
    }
  }
}

上面的响应提供了有关 test_alias .

fquxozlt

fquxozlt2#

完成@opster es忍者答案。您可以使用\u stats api获得所需的部分信息
在搜索部分,对于每个索引,您将能够知道wish索引是最常用的

GET my_alias/_stats
"indices" : {
    "metricbeat-7.3.1-2019.12.05-000004" : {
      "uuid" : "2Jgl5tAfRBCUC8UjhzJMXw",
      "primaries" : {
        "docs" : {
          "count" : 4536039,
          "deleted" : 0
        },
        "store" : {
          "size_in_bytes" : 1314781408,
          "reserved_in_bytes" : 0
        },
        "indexing" : {
          "index_total" : 0,
          "index_time_in_millis" : 0,
          "index_current" : 0,
          "index_failed" : 0,
          "delete_total" : 0,
          "delete_time_in_millis" : 0,
          "delete_current" : 0,
          "noop_update_total" : 0,
          "is_throttled" : false,
          "throttle_time_in_millis" : 0
        },
        "get" : {
          "total" : 0,
          "time_in_millis" : 0,
          "exists_total" : 0,
          "exists_time_in_millis" : 0,
          "missing_total" : 0,
          "missing_time_in_millis" : 0,
          "current" : 0
        },
        "search" : {
          "open_contexts" : 0,
          "query_total" : 3,
          "query_time_in_millis" : 0,
          "query_current" : 0,
          "fetch_total" : 0,
          "fetch_time_in_millis" : 0,
          "fetch_current" : 0,
          "scroll_total" : 0,
          "scroll_time_in_millis" : 0,
          "scroll_current" : 0,
          "suggest_total" : 0,
          "suggest_time_in_millis" : 0,
          "suggest_current" : 0
        },
        ...

相关问题