【问题标题】:elasticsearch wrap bool and must around multi_matchelasticsearch wrap bool 并且必须围绕 multi_match
【发布时间】:2020-12-16 00:05:39
【问题描述】:

我有一个现有的查询,如下所示:

{
    "from": 0,
    "size": 10,
    "query": {
        "multi_match": {
            "query": "example query", "slop":10,
        "fuzziness": "AUTO"
        }
    }
}

我想添加一个过滤器,它只返回字段“service_or_company”的结果:“service”,即只返回服务而不是服务和公司。 所以我将其更新为:

{
    "from": 0,
    "size": 10,
    "query": {
        "multi_match": {
            "query": "example query", "slop":10,
        "fuzziness": "AUTO"
        }
    },
    "filter": {
        "type": "service"
    }
}

但是,根据他们的文档,我得到了“解析异常”,我需要将查询和过滤器包装在“bool”和“must”中,但是如何在保持“multi_match”查询的同时做到这一点?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    添加一个包含索引数据、搜索查询和搜索结果的工作示例

    索引数据:

    {
      "title": "exampl query",
      "service_or_company": "service"
    }
    {
      "title": "example query",
      "service_or_company": "service"
    }
    {
      "title": "hello world",
      "service_or_company": "company"
    }
    

    搜索查询:

    {
      "query": {
        "bool": {
          "must": {
            "multi_match": {
              "query": "example query",
              "slop": 10,
              "fuzziness": "AUTO"
            }
          },
          "filter": {
            "term": {                     
              "service_or_company": "service" 
            }
          }
        }
      }
    }
    

    搜索结果:

    "hits": [
          {
            "_index": "65315457",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.79850763,
            "_source": {
              "title": "example query",
              "service_or_company": "service"
            }
          },
          {
            "_index": "65315457",
            "_type": "_doc",
            "_id": "3",
            "_score": 0.6829831,
            "_source": {
              "title": "exampl query",
              "service_or_company": "service"
            }
          }
        ]
    

    【讨论】:

    • @Brian Guan 你有机会看我的回答吗,期待得到你的反馈?
    • @Brian Guan 好久不见了。我希望你做得很好?如果我的回答帮助你解决了你的问题,那么请不要忘记投票并接受答案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多