Vin*_*nce 0 python elasticsearch
只是为了测试,我有一个包含索引的 Elasticsearch 节点,例如:
服务日志-17032020 服务日志-20032020 服务日志-21032020
我正在尝试构建一个查询,用于使用 service-log-* 模式搜索所有索引。该查询与完整索引名称完美配合,我如何搜索所有索引?
index = INDEX_NAME
query_body = {
"from":0,
"size":100,
"query": {
"bool": {
"must": [
{
"match" : {
"field": "text"
}
},
{
"range": {
"@timestamp": {
"gt":str(date)
}
}
}
]
}
}
}
result = elastic_client.search(index=INDEX_NAME, body=query_body)
Run Code Online (Sandbox Code Playgroud)
由于您使用的是 Python 客户端,因此您可以执行以下操作:
from elasticsearch import Elasticsearch
es = Elasticsearch()
# Queries all indices in the cluster.
es.search(index="*", body=...)
# Queries all indices that start with 'logs-'
es.search(index="logs-*", body=...)
# Queries 'logs-1', 'logs-2', and 'logs-5'.
# Serializes to 'logs-1,logs-2,logs-5' in the URL.
es.search(index=["logs-1", "logs-2", "logs-5"], body=...)
Run Code Online (Sandbox Code Playgroud)
<披露:我维护 Python Elasticsearch 客户端并受雇于 Elastic>
| 归档时间: |
|
| 查看次数: |
1985 次 |
| 最近记录: |