【问题标题】:Elasticsearch : Improving multi_match resultsElasticsearch:改进 multi_match 结果
【发布时间】:2018-10-19 09:39:59
【问题描述】:

您好,我正在尝试在不同的字段中搜索值。我正在使用 multi_match 和 cross_fields 类型。 这是查询

"query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "query": "red cross",
                "type": "cross_fields",
                "fields": [
                  "name^20",
                  "keywords^12",
                  "description^1"
                ]
              }
            }
          ]
        }
      }
    }   }

上述查询得到的结果

 "results": [
        {
            "name": "CrossPurpose",
            .....
        } ,
        {
            "name": "Community Center",
            "keywords": "American Red Cross,Red Cross,Center,Blood",
            . . .
          },
          {
             "name": "Some Group",
             "description":".... red cross ..."
          },
          .......
          ....
          ..
          {
             "name" : "Red cross" ,
              .....
          }
          ]

我想改进搜索结果。

我想在第一个位置查看名称为“Red cross”的记录。 首先它应该匹配整个单词 "red cross" 然后只匹配 "red" , "cross"。

我希望优先考虑名称字段而不是关键字和描述。

请帮助我改进查询。 提前致谢。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    你需要使用 type = best_fields

    所以你的查询将是

    {
      "query": {
        "multi_match" : {
          "query":      "red cross",
          "type":       "best_fields",
          "fields":     [ "name", "keywords", "description" ],
          "tie_breaker": 0.3
        }
      }
    }
    

    【讨论】:

    • 谢谢,tie_breaker 有什么用?与在字段中使用分数有何不同
    • 它将最佳匹配子句的 _score 乘以其他每个匹配子句的分数,然后将它们加在一起。有关更多信息,您可以查看 tie_breaker:[elastic.co/guide/en/elasticsearch/guide/current/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    相关资源
    最近更新 更多