【问题标题】:Elasticsearch 7.14 constant_score with two filters?Elasticsearch 7.14 constant_score 有两个过滤器?
【发布时间】:2021-08-23 16:57:58
【问题描述】:

我在 ES 7.14 中使用两个过滤器创建 constant_score 查询时遇到问题。我的查询是:

"query": {
            "constant_score": {
                "filters": [
                    {"exists": {"field": "_geopoint"}},
                    {"term": {"project_id": "123"}},
                ]
            }
        },

基本上,对于 project_id = '123',我需要文档在 _geopoint 中具有任何值的分数。但我得到了错误:

意外的令牌 [START_ARRAY]

我的映射是:

"mappings": {
            "properties": {
                "project_id": {"type": "keyword"},
                "form_id": {"type": "keyword"},
                "submission_id": {"type": "keyword"},
                "_submitted_date": {"type": "date"},
                "_xform_id_string": {"type": "keyword"},
                "_submitted_by": {"type": "keyword"},
                "_user_id": {"type": "keyword"},
                "_project_code": {"type": "keyword"},
                "_geopoint": {"type": "text"},
                "_geolocation": {"type": "geo_point"},
            }
        },

我也尝试了一个和:

"filter": {
           "and": {
               "filters": [
                  {"exists": {
                     "field": "_geopoint"
                  }},
                  {"term": {
                     "project_id": "123"
                  }}
               ]
           }
       }

但是我遇到了“和”的问题

任何想法都值得赞赏。 constant_score 的官方文档只有一个过滤器

【问题讨论】:

    标签: elasticsearch elasticsearch-query


    【解决方案1】:

    试试这个:

    {
      "query": {
        "constant_score": {
          "filter": {
            "bool": {
              "filter": [
                {"exists": {"field": "_geopoint"}},
                {"term": {"project_id": "123"}},
              ]
            }
          }
        }
      }
    }
    

    【讨论】:

    • 现在我得到“[constant_score] 查询不支持 [bool]”
    • 我的错,请再试一次
    • 很好的答案!我挣扎了一个多小时。这就像魅力!
    • @insanely_sin 太好了!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多