我正在使用elasticsearch python客户端。
我的索引中有一个日期范围字段。我希望文档在中午12点到下午2点之间。所以,这是我写的查询,
query = {"query":"filter": [{"range" : { "status_time_frame" : {"gte" : "10/11/2017","lte" : "13/11/2017", "relation":"within"}}}],{"script":{"source": "doc.status_time_frame.status_time_frame.getHourOfDay() >= min && doc.status_time_frame.status_time_frame.getHourOfDay() <= max","params": {"min":12,"max":14}}}}
但是当我尝试运行它时,它会给我语法错误。
File "vehicle-report-query-elastic.py", line 3
query = {"query":{"filter": [{"range" : { "status_time_frame" : {"gte" : "10/11/2017","lte" : "13/11/2017", "relation":"within"}}}],{"script":{"source": "doc.status_time_frame.status_time_frame.getHourOfDay() >= min && doc.status_time_frame.status_time_frame.getHourOfDay() <= max","params": {"min":12,"max":14}}}}}
^
SyntaxError: invalid syntax
我做错了什么?
答案 0 :(得分:1)
正确的查询应如下所示:
{
"query": {
"filter": [
{
"range": {
"status_time_frame": {
"gte": "10/11/2017",
"lte": "13/11/2017"
}
}
},
{
"script": {
"source": "doc.status_time_frame.status_time_frame.getHourOfDay() >= min && doc.status_time_frame.status_time_frame.getHourOfDay() <= max",
"params": {
"min": 12,
"max": 14
}
}
}
]
}
}