在ElasticSearch查询中给予特定文档更多的分数

kmb7vmvb  于 2023-02-11  发布在  ElasticSearch
关注(0)|答案(1)|浏览(151)

假设我有这个全文查询:

GET /test/_search
{
  "query": {
    "match": {
      "title": "blue"
    }
  }
}

我得到了这个结果:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 4,
      "relation": "eq"
    },
    "max_score": 0.32156613,
    "hits": [
      {
        "_index": "test",
        "_id": "rQ5WIYYBUZECFnMRbIo6",
        "_score": 0.32156613,
        "_source": {
          "title": "blue chair blue desk"
        }
      },
      {
        "_index": "test",
        "_id": "qg5VIYYBUZECFnMRrorJ",
        "_score": 0.29879427,
        "_source": {
          "title": "blue bird"
        }
      },
      {
        "_index": "test",
        "_id": "qw5VIYYBUZECFnMR8IpD",
        "_score": 0.29879427,
        "_source": {
          "title": "blue sky"
        }
      },
      {
        "_index": "test",
        "_id": "rg5WIYYBUZECFnMRsoqo",
        "_score": 0.29879427,
        "_source": {
          "title": "blue automobile"
        }
      }
    ]
  }
}

你看评分是完全工作正常,但我想特别给予更多的分数与**标题的文件:“蓝天”**每当搜索是蓝色的,所以它将是我的顶部结果。有什么办法来专门增加分数的一些文件,而查询在ElasticSearch?
我认为可以通过结合匹配和正提升查询来实现,但我不能这样做

vdzxcuhz

vdzxcuhz1#

一个选项是使用boosting查询。你可以减少你不想要的评分文档。我在示例中对没有术语sky的文档应用了负boost。

{
  "query": {
    "boosting": {
      "positive": {
        "match": {
          "title": "blue"
        }
      },
      "negative": {
        "bool": {
          "must_not": [
            {
              "match": {
                "title": "sky"
              }
            }
          ]
        }
      },
      "negative_boost": 0.1
    }
  }
}

相关问题