0

我有三个字段,name我正在尝试搜索。我已经提升了任何排名高于. 但是,我仍然有一些情况与包含奇怪标点符号的术语不匹配,因此我想在and fields 字段上进行模糊搜索来完成我的查询。name.ngrammodel_numbernamenamename.ngramname.ngramnamemodel_number

这是我最终想要的查询。如果我删除第二个 multi_match,则查询有效,但不包括模糊搜索。

{
         explain: true,
         query:{
           function_score: { 
              "query": {
                "bool": {
                  "should": 
                    {
                      multi_match:{
                         fields: ["name^10", "name.ngram", "model_number"],
                         type: "most_fields",
                         query: "#{query}"
                       },
                       multi_match:{
                           fields: ["name", "model_number"],
                           type: "most_fields",
                           query: "#{query}",
                           fuzziness: "2"
                        }
                    },
                  "filter": {
                    "bool": { 
                      "must": filters
                    }
                  }
               }
             },field_value_factor:{
                    field: "popularity",
                    modifier: "log1p",
                    factor: 5

                 },
                 boost_mode: "sum"
             }
       },highlight: {
            fields: {
              :"*" => {}
            }
          },
        aggs: {categories: { terms: { field: "category.raw"} }} 

      } 

我想最终像处理 ngram 一样对待模糊搜索,以便非模糊匹配排名第一,模糊匹配排名第二。如何添加允许此操作的第二个 multi_match 查询?

4

1 回答 1

0

您的bool/should子句格式不正确,它应该是一个包含两个元素的数组,每个multi_match约束一个元素,如下所示:

  ...
  "should": [
    {
      "multi_match": {
        "fields": [
          "name^10",
          "name.ngram",
          "model_number"
        ],
        "type": "most_fields",
        "query": "#{query}"
      }
    },
    {
      "multi_match": {
        "fields": [
          "name",
          "model_number"
        ],
        "type": "most_fields",
        "query": "#{query}",
        "fuzziness": "2"
      }
    }
  ]
  ...
于 2019-09-17T12:08:25.623 回答