gpt4 book ai didi

python - elasticsearch —获取正确的查询字符串

转载 作者:行者123 更新时间:2023-12-03 00:52:43 25 4
gpt4 key购买 nike

我是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]')
任何的想法 ??

最佳答案

您需要将query_stringgeo_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
}
}
}
}
}

关于python - elasticsearch —获取正确的查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50579959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com