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

tnkciper  于 2023-03-29  发布在  ElasticSearch
关注(0)|答案(1)|浏览(135)

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

oknwwptz

oknwwptz1#

您可以使用带有逗号分隔索引模式的_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
      }
    }
  }
}

相关问题