Elasticsearch [filtered] 查询不支持 [suggest]

Elasticsearch [filtered] query does not support [suggest]

我想允许我们的用户按文本和地理位置搜索对象。当通过文本搜索时,我希望它像使用普通查询和完成建议器一样建议术语。当我尝试将建议者添加到过滤后的查询时,出现错误。有什么建议吗?

我的映射:

curl -XPUT http://localhost:9200/objects/object/_mapping -d '{
  "object": {
    "properties": {
      "objectDescription": {
        "type": "string"
      },
      "suggest": {
        "type": "completion",
        "analyzer": "standard",
        "search_analyzer": "standard",
        "payloads": true
      }
    }
  }
}'

curl -X PUT http://localhost:9200/objects/object/_mapping -d '{
    "object":{"properties":{"location":{"type":"geo_point"}}}
}'

我的搜索:

{
  "query": {
    "filtered": {
      "query": {
        "fuzzy": {
          "objectDescription": {
            "value": "burger"
          }
        }
      },
      "filter": {
        "or": [
          {
            "geo_distance": {
              "distance": "15mi",
              "location": {
                "lat": 33.4255104,
                "lon": -111.94000540000002
              }
            }
          },
          {
            "bool": {
              "must": [
                {
                  "term": {
                    "administrative_area_level_1": "AZ"
                  }
                },
                {
                  "term": {
                    "addressType": "administrative_area_level_1"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
}

当我在与查询相同的级别添加建议时,就像您在没有过滤器的情况下一样,它会忽略我的过滤器。它会在搜索时找到不在经纬度附近的对象。

{
    "query":{
        "filtered":{
            "query":{
                "fuzzy":{
                    "objectDescription":{"value":"bears"}
                }
            },
            "filter":{
                "bool":{
                    "should":[
                        {
                            "geo_distance":{
                                "distance":"15mi",
                                "location":{
                                    "lat":43.6187102,
                                    "lon":-116.21460680000001
                                }
                            }
                        },
                        {
                            "bool":{
                                "must":[
                                    {
                                        "term":{"administrative_area_level_1":"ID"}
                                },{
                                        "term":{"addressType":"administrative_area_level_1"}
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    },
    "suggest":{
        "object-suggest":{
            "text":"bears",
            "completion":{
                "field":"suggest",
                "fuzzy":{"fuzziness":2}
            }
        }
    }
}

当我将正文的建议部分放在查询的位置时,出现此错误。

{
    "query":{
        "filtered":{
            "suggest":{
                "object-suggest":{
                    "text":"bears",
                    "completion":{
                        "field":"suggest",
                        "fuzzy":{"fuzziness":2}
                    }
                }
            },
            "filter":{
                "bool":{
                    "should":[
                        {
                            "geo_distance":{
                                "distance":"15mi",
                                "location":{
                                    "lat":43.6187102,
                                    "lon":-116.21460680000001
                                }
                            }
                        },
                        {
                            "bool":{
                                "must":[
                                    {
                                        "term":{"administrative_area_level_1":"ID"}
                                },{
                                        "term":{"addressType":"administrative_area_level_1"}
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    }
}

所以我的问题是我没有在 elastic.co 或 Whosebug 上找到具有这种地理定位搜索与完成建议器组合的示例。

这样试试。 suggest 块自己位于顶层:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "should": [
            {
              "geo_distance": {
                "distance": "15mi",
                "location": {
                  "lat": 43.6187102,
                  "lon": -116.21460680000001
                }
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "term": {
                      "administrative_area_level_1": "ID"
                    }
                  },
                  {
                    "term": {
                      "addressType": "administrative_area_level_1"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  },
  "suggest": {
    "object-suggest": {
      "text": "bears",
      "completion": {
        "field": "suggest",
        "fuzzy": {
          "fuzziness": 2
        }
      }
    }
  }
}

更新

对于您的精确用例,我认为您应该将 context suggester 与地理位置上下文一起使用,而不是简单的完成建议器。这肯定是您实现预期所需要的。