elasticsearch——获取正确的查询字符串
elasticsearch -- getting right query string
我是 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', u'未能解析搜索源。预期的字段名称但得到了 [START_OBJECT]')
有什么想法吗??
您需要将 query_string
和 geo_distance
查询组合成布尔查询。
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
}
}
}
}
}
我是 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', u'未能解析搜索源。预期的字段名称但得到了 [START_OBJECT]') 有什么想法吗??
您需要将 query_string
和 geo_distance
查询组合成布尔查询。
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
}
}
}
}
}