我正在尝试查询弹性搜索以查找两毫秒时间戳之间的所有日志。
直接通过以下方式查询 Elasticsearch 时:
curl -XPOST <ElasticSearch> ' -d ' {"query" : { "bool" : { "must" : { "range" : { "received_at" : { "gte" : 1310325395701, "lte" : 1468933745000 } } } } } }'
我得到了想要的结果。但是,来自 Python 脚本的以下查询返回 0 个命中:
res = es.search(index="syslog-*", body={ "query" : { "bool" : { "must" : { "range" : { "received_at" : { "gte" : 1310325395701, "lte" : 1468933745000 } } } } } }, size=6000)
我也试过这个:
res = es.search(index="syslog-*", body= { "query" : { "range" : { "received_at" : { "gte" : 1310325395701, "lte" : 1468933745000 } } } }, size=6000)
但完全相同的事情也会发生。来自 python 脚本的其他类型的查询确实返回命中:
res = es.search(index="syslog-*", body={"query": {"match_all": {}}}, size=6000)
在哪里:
from elasticsearch import RequestsHttpConnection
class MyConnection(RequestsHttpConnection):
def __init__(*args, **kwargs):
proxies = kwargs.pop('proxies', {})
super(MyConnection, self).__init__(*args, **kwargs)
self.session.proxies = proxies
es = Elasticsearch([es_url], connection_class=MyConnection, proxies = {'https': 'http://user:pw@proxy.org:port'})
我究竟做错了什么?