我正在尝试使用rawes python 绑定按日期过滤弹性搜索查询。如果我删除数据库,指定该datetime
字段是date_optional_time,在弹性搜索数据库中插入几行,然后使用字段上的范围过滤器datetime
查询它,我没有得到任何结果(见下文)。知道我做错了什么吗?
>>> result = es.delete(root_url)
>>> result = es.put(root_url+"_mapping", data={
"tweet": {
"properties": {
"datetime": {
"type": "date",
"format": "date_optional_time"
},
}
},
})
>>> result = es.post(root_url, data={
"datetime": "2012-12-20 12:00:00",
"name": "freddy",
"text": "hello world",
})
>>> result = es.post(root_url, data={
"datetime": "2012-11-20 12:00:00",
"name": "julie",
"text": "welcome to the wonderful world of cooking",
})
>>> result = es.get(root_url+"_search", data={
"query": {
"range": { # expect this to return the one result on 2012-12-20
"datetime": {
"gte":"2012-12-01", # do not append "T00:00:00"; too slow!
"lte":"2012-12-31", # do not append "T23:59:59"; too slow!
}
}
}
})
>>> pprint.pprint(result)
{u'_shards': {u'failed': 0, u'successful': 5, u'total': 5},
u'hits': {u'hits': [], u'max_score': None, u'total': 0},
u'timed_out': False,
u'took': 4}