You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整Elastic Search搜索结果排序,让title匹配结果靠前?

Prioritize title Matches in Elasticsearch Results

Hey David, glad to hear your current query is returning solid results! To get matches on the title field to show up at the top of your results, you just need to add a boost value to the title clause in your should array. Boosting increases the relevance score of documents that match that specific clause, so they’ll naturally rise above matches on second_title.

Here’s your adjusted query:

{
  "query": {
    "bool": {
      "should": [
        {"match_phrase_prefix": {"title": {"query": keyword, "boost": 2}}},
        {"match_phrase_prefix": {"second_title": keyword}}
      ]
    }
  }
}

Quick Tips:

  • The boost value is relative—setting it to 2 means a title match contributes twice as much to the document’s overall score as a second_title match. Feel free to tweak this number (try 3, 5, etc.) depending on how strongly you want title matches to prioritize.
  • Elasticsearch sorts results by relevance score by default, so you don’t need any extra sorting parameters here. The boosted title matches will have higher scores and automatically appear first.
  • If you ever need even more control over scoring down the line, you could use a function_score query, but boosting the clause directly is the simplest, most straightforward fix for your current use case.

内容的提问来源于stack exchange,提问作者David Vann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 18:37:41