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

srk

我是 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_stringgeo_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
                    }
                }
            }
        }
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章