我正在尝试将下面的弹性搜索转换为 pyes 查询,但我找不到有关如何使用范围查询的示例(尤其是时间戳)。有人可以帮忙吗?
弹性搜索查询
{
"query": {
"bool": {
"must": [
{
"term": {
"field1": "abcd"
}
},
{
"query_string": {
"default_field": "@field2",
"query": "efgh"
}
},
{
"range": {
"timestamp": {
"gte": "2012-08-14T20:45:09.000Z"
}
}
}
],
"must_not": [
{
"term": {
"@field3": "ijkl"
}
}
]
}
},
"size": 1,
}
我的 Python 脚本(使用 pyes)来获得结果,我使用的是 pyes 0.19.1
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pyes import *
conn = ES('127.0.0.1:9200')
def main():
try:
q1= TextQuery('field1','abcd')
q2=TextQuery('@field2','efgh')
q3=Range('@timestamp','2012-08-14T20:45:09.000Z','2012-08-14T20:45:09.000Z')
q4=TextQuery('@field3','ijkl')
q = BoolQuery(must=[q1, q2,q3],must_not=[q4])
results = conn.search(q,size='1')
for r in results:
print r;
except:
pass
if __name__ == '__main__':
main()