我们使用AWS管理的Elasticsearch服务,最近从1.5升级到2.3.我们在python中使用elasticsearch-dsl包来构建我们的查询并设法迁移我们的大多数查询,但无论我尝试什么,geo_distance都会被破坏.
制图:
{
'company': {
'properties': {
'id': {'type': 'integer'},
'company_number': {'type': 'string'},
'addresses': {
'type': 'nested',
'properties': {
'postcode': {'type': 'string', 'index': 'not_analyzed'},
'location': {'type': 'geo_point'}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Python代码使用elasticsearch-dsl == 0.0.11
test_location = '53.5411062377, -2.11485504709'
test_distance = "3miles"
location_filter = F("geo_distance",
location=test_location,
distance=test_distance)
query = query.filter("nested",
path="addresses",
filter=location_filter)
Run Code Online (Sandbox Code Playgroud)
库生成的查询:
{'query': {'filtered': {'filter': {'nested': {'filter': {'geo_distance': {'distance': u'3miles', 'location': '53.5411062377, -2.11485504709'}}, 'path': 'addresses'}}, 'query': {'match_all': {}}}}}
Run Code Online (Sandbox Code Playgroud)
我们使用相同的映射在新的2.3上创建了一个全新的索引.
更新到elasticsearch-dsl == 2.1.0并尝试将过滤器转换为查询后:
geo_query = Q({"bool": {
"must": [
{ …Run Code Online (Sandbox Code Playgroud)