我有弹性簇,有数百个索引.有没有办法使用布尔查询列出(搜索)索引?例如
( index.alias:*read_index* AND doc.count:<1000 ) OR ( index.name* ) OR (index.size:<2gb) OR (index.replica:>2)
Run Code Online (Sandbox Code Playgroud)
我需要从数百个索引列表中筛选出所需的索引.
请建议.
使用普通的 elasticsearch bool 查询:),只需将 JSON 格式的cat输出存储到索引中,然后进行所需的查询,使用 cronjob 自动化收集以每 X 次收集一次,我的 python 脚本如下所示:
# install dependencies: pip install requests
import requests
import json
ES_URL = "http://localhost:9200"
res = requests.get("{}{}".format(ES_URL, "/_cat/indices"),
params={"format": "json", "bytes": "m"})
for index_info in res.json():
index_url = "{}/{}/{}/{}".format(
ES_URL, "cat_to_index", "doc", index_info["index"]
)
requests.post(
index_url,
data=json.dumps(index_info),
headers={'Content-type': 'application/json'}
)
# ready to query http://localhost:9200/cat_to_index/_search
# ready to keep up-to-date with a cronjob, as the index name is the ID new values will be overwritten.
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你。