我遇到的场景是,在我的弹性集群中,我有超过 500 个索引。我想要索引名称以“Analytics”开头或索引名称中包含“accounts”的所有索引的文档计数。我该如何编写查询?
我正在使用 ES 7.17
您可以使用
_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
}
}
}
}