python - 如何在多个索引上使用 python elasticseach 模块进行查询?
问题描述
只是为了测试,我有一个包含如下索引的弹性搜索节点:
服务日志 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)
解决方案
由于您使用的是 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=...)
<披露:我维护 Python Elasticsearch 客户端并受雇于 Elastic>
推荐阅读
- vbscript - 我可以通过全局脚本消除 VBS 重复代码吗?
- angular - Angular Material:为什么控制颜色会反转?
- java - 如何将字符串中等式的这些元素分离为所需的格式?
- prometheus - Prometheus 标签上的布尔运算
- sql-server - 如何在表上执行具有交集的唯一自连接
- angular - Laravel 8、Sanctum 和 Angular 8
- cryptography - 参考 Python 密码学模块的“后端”是什么?
- c - 在 Atmega64 上写入 EEPROM 时是否存在无限循环的可能性
- r - 如何将非线性函数拟合到R中矩阵中的时间序列
- javascript - 在每次功能调用中创建新模式会影响性能吗?