我是elasticsearch的新手,目前正在查询query_string结果的距离查询:这是我的代码:
doc = {
"query": {
"query_string": {
"query": term,
"fields": ['name', 'business_name', 'email', 'city',
'state', 'zip_code', 'business_keywords', 'phone_number',
'address', 'country'
],
},
"filter": {
"geo_distance": {
"distance": radius,
"distance_unit": "km",
"distance_type": "arc",
"location": {
"lat": latitude,
"lon": longitude
}
}
}
}
}
search_response = client.search(index="b",body=doc)
但是我收到以下错误:
RequestError:TransportError(400,u'search_phase_execution_exception',你无法解析搜索源。预期字段名称但得到[START_OBJECT]') 有什么想法??
答案 0 :(得分:2)
您需要将query_string
和geo_distance
个查询合并到一个bool查询中。
doc = {
"query": {
"bool": {
"must": {
"query_string": {
"query": term,
"fields": ['name', 'business_name', 'email', 'city',
'state', 'zip_code', 'business_keywords', 'phone_number',
'address', 'country'
],
}
},
"filter": {
"geo_distance": {
"distance": radius,
"distance_unit": "km",
"distance_type": "arc",
"location": {
"lat": latitude,
"lon": longitude
}
}
}
}
}