0Pricing
Elasticsearch & Full Text Search Systems · 课时

提升与相关性评分

学习使用查询提升、字段提升和自定义评分函数来影响文档相关性评分的技术。

提升与相关性评分 是 CoddyKit 上的免费 Elasticsearch & Full Text Search Systems 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Elasticsearch & Full Text Search Systems 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Why Relevancy Matters

When you search for something, you don't just want any results; you want the best results. This is where relevancy comes in!

Relevancy helps search engines, like Elasticsearch, decide which documents are most important or 'relevant' to your query and present them first.

Meet the _score

In Elasticsearch, every document that matches your search query gets a numeric value called the _score. This score represents how relevant that document is to your query.

  • A higher _score means the document is considered more relevant.
  • Elasticsearch uses algorithms (like BM25) to calculate this score, considering factors like how often a term appears and its uniqueness.

Introduction to Boosting

While Elasticsearch calculates relevancy automatically, you often want to guide it. This is where boosting comes in!

Boosting allows you to manually increase or decrease the importance of specific query clauses or fields, directly influencing the _score of matching documents.

Boosting Entire Queries

You can apply a boost parameter to an entire query clause. A boost value greater than 1.0 increases its impact, while a value less than 1.0 decreases it.

The default boost value is 1.0, meaning no special emphasis.

Query Boost in Action

Let's say you're searching for 'coding' and want matches in the description field to be twice as important as other parts of your query.

You can add "boost": 2 to that specific match clause:

GET /my_index/_search
{
  "query": {
    "match": {
      "description": {
        "query": "coding",
        "boost": 2
      }
    }
  }
}

Prioritizing Specific Fields

Often, a match in one field is inherently more valuable than a match in another. For example, finding a keyword in a document's title is usually more relevant than finding it in its content.

Field boosting lets you specify this importance directly within your query.

Field Boost Example

Using the ^ (caret) operator after a field name, you can assign a boost factor. Here, a match in title is 3 times more important than a match in description:

GET /my_index/_search
{
  "query": {
    "multi_match": {
      "query": "quick brown fox",
      "fields": [ "title^3", "description^1" ]
    }
  }
}

Beyond Simple Boosting

For even more control over relevancy, Elasticsearch offers the function_score query. This powerful query type allows you to apply custom scoring logic to documents.

You can factor in things like a document's popularity, recency, or specific numeric field values to influence its _score.

function_score Basic Example

Here's a simple function_score example. It searches for 'elastic' and then boosts the score based on the views_count field, multiplying the base score by a factor derived from views_count.

GET /my_index/_search
{
  "query": {
    "function_score": {
      "query": { "match": { "text": "elastic" } },
      "field_value_factor": {
        "field": "views_count",
        "factor": 1.2,
        "modifier": "log1p",
        "missing": 1
      },
      "boost_mode": "multiply"
    }
  }
}

Boost Your Knowledge!

Test your understanding of boosting and relevancy in Elasticsearch!

Relevancy Tuned!

Great job! You've learned how to take control of relevancy in Elasticsearch.

  • The _score dictates a document's importance.
  • Query boosting lets you emphasize entire query clauses.
  • Field boosting prioritizes matches in specific fields.
  • The function_score query provides advanced, custom relevancy adjustments.

By using these techniques, you can ensure your users always find the most relevant information first!

常见问题解答

「提升与相关性评分」课时是免费的吗?

是的 — 「提升与相关性评分」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Elasticsearch & Full Text Search Systems 课程的其余内容,请升级到 CoddyKit PRO。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。

「提升与相关性评分」这节课中我会学到什么?

学习使用查询提升、字段提升和自定义评分函数来影响文档相关性评分的技术。 你通过在浏览器中直接运行的动手代码来练习 Elasticsearch & Full Text Search Systems,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Elasticsearch & Full Text Search Systems 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Elasticsearch & Full Text Search Systems 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「提升与相关性评分」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Elasticsearch & Full Text Search Systems 课中编写并运行代码吗?

能。每节 Elasticsearch & Full Text Search Systems 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 分析器、分词器与过滤器
  2. 自定义文本分析器
  3. 提升与相关性评分
  4. 同义词与词干提取
← 返回 Elasticsearch & Full Text Search Systems