如何从选定的索引中获取文档的数量

问题描述 投票:0回答:1

我遇到的场景是,在我的弹性集群中,我有超过 500 个索引。我想要索引名称以“Analytics”开头或索引名称中包含“accounts”的所有索引的文档计数。我该如何编写查询?

我正在使用 ES 7.17

elasticsearch
1个回答
0
投票

您可以使用

_cat/indices
带有逗号分隔索引模式的 API 调用。

GET _cat/indices/*test*,*accounts*?v&h=index,docs.count
index                 docs.count
test_history-1                 1
test_history-2                 2
test_interesting_body          1
test_doc_remove                2
test_musab                     1

如果您需要更复杂的查询,您可以使用带有

_index
字段的以下查询。

GET _all/_search
{
  "size": 0,
  "query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "_index": "*test*"
          }
        },
        {
          "wildcard": {
            "_index": "*accounts*"
          }
        }
      ]
    }
  },
  "aggs": {
    "NAME": {
      "terms": {
        "field": "_index",
        "size": 1000
      }
    }
  }
}

© www.soinside.com 2019 - 2024. All rights reserved.