<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title><![CDATA[Mike Pellegrini - Elasticsearch Labs]]></title>
    <description><![CDATA[Articles and tutorials from the Search team at Elastic]]></description>
    <copyright><![CDATA[© 2026. Elasticsearch B.V. All Rights Reserved]]></copyright>
    <image>
      <title><![CDATA[Mike Pellegrini - Elasticsearch Labs]]></title>
      <url>https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt1121c0bf0e8a6e65/6a88da6340a1841030ef456f/search-labs-thumbnail.png</url>
      <link>https://www.elastic.co/cn/search-labs/author/mike-pellegrini</link>
    </image>
    <link>https://www.elastic.co/cn/search-labs/author/mike-pellegrini</link>
    <atom:link href="https://www.elastic.co/cn/search-labs/rss/author/mike-pellegrini.xml" rel="self" type="application/rss+xml"/>
    <language><![CDATA[cn]]></language>
    <lastBuildDate>Mon, 14 Sep 2026 05:24:27 GMT</lastBuildDate>
  <item>
    <title><![CDATA[混合搜索不头疼：用检索器简化混合搜索]]></title>
    <description><![CDATA[探索如何利用线性和 RRF 检索器的多字段查询格式简化 Elasticsearch 中的混合搜索，并在不了解 Elasticsearch 索引的情况下创建查询。]]></description>
    <content:encoded><![CDATA[<p><a href="https://www.elastic.co/what-is/hybrid-search">混合搜索</a>被公认为是一种强大的搜索方法，它将<a href="https://www.elastic.co/search-labs/blog/lexical-and-semantic-search-with-elasticsearch#lexical-search---sparse-retrieval">词法搜索</a>的精确性和速度与<a href="https://www.elastic.co/what-is/semantic-search">语义搜索</a>的自然语言能力结合在一起。不过，在实际应用中可能会很棘手，往往需要对索引有深入的了解，并通过非繁琐的配置来构建冗长的查询。在本博客中，我们将探讨<a href="https://www.elastic.co/docs/reference/elasticsearch/rest-apis/retrievers#multi-field-query-format">线性和 RRF 检索器的多字段查询格式</a>如何使混合搜索变得更简单、更易用，从而消除常见的头痛问题，让您更轻松地充分利用其强大功能。我们还将回顾多字段查询格式如何使您在不了解索引的情况下执行混合搜索查询。</p><h2>分数范围问题</h2><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt3521a6558cd477ca/6a17f174445de94d3c4d0225/c8b49153c47d2cdc233c0d2e440db04711d48ca5-1600x1600.jpg" alt="" /><p>首先，让我们回顾一下混合搜索困难的主要原因之一：不同的分数范围。我们的老朋友<a href="https://www.elastic.co/elasticon/conf/2016/sf/improved-text-scoring-with-bm25">BM25</a>会产生无限制的分数。换句话说，BM25 可以生成从接近 0 到（理论上）无穷大的分数。与此相反，针对<code>dense_vector</code> 字段的查询会产生介于 0 和 1 之间的分数。由于<code>semantic_text</code> 混淆了用于索引嵌入的字段类型，因此除非您对索引和推理端点配置有详细了解，否则很难说清查询的分数范围。这在试图交错使用词汇和语义搜索结果时会带来问题，因为即使语义结果更相关，词汇结果也可能优先于语义结果。对于这个问题，普遍接受的解决方案是在交织结果之前对分数进行归一化处理。Elasticsearch 为此提供了两种工具：<a href="https://www.elastic.co/docs/reference/elasticsearch/rest-apis/retrievers/linear-retriever">线性</a>检索器和<a href="https://www.elastic.co/docs/reference/elasticsearch/rest-apis/retrievers/rrf-retriever">RRF</a>检索器。
</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt09ed6bf3d25066bd/6a17f1750b0bedbd70dd3686/264481268c8b6ac259e3c257b85431b513f16672-1077x586.png" alt="使用线性/rrf 与不使用线性/rrf 的搜索结果比较" /><p><strong>RRF</strong>检索器采用<a href="https://www.elastic.co/docs/reference/elasticsearch/rest-apis/reciprocal-rank-fusion">RRF 算法</a>，将文档排名作为衡量相关性的标准，并舍弃分数。由于不考虑分数，因此分数范围不匹配不是问题。</p><p><strong>线性</strong>检索器使用线性组合来确定文档的最终得分。这包括获取文档中每个组件查询的得分，对其进行归一化处理，然后求和生成总分。在数学上，这一操作可以表示为</p>Total Score = 𝚺(N(Sx))<p>其中<code>N</code> 是归一化函数，SX 是查询 X 的得分。归一化功能在这里非常关键，因为它将每个查询的得分转换为使用相同的范围。您可以<a href="https://www.elastic.co/search-labs/blog/linear-retriever-hybrid-search">在这里</a>了解有关线性寻回猎犬的更多信息。</p><h2>分解</h2><p>用户可以利用这些工具实现有效的混合搜索，但需要对索引有一定的了解。让我们看一个使用线性检索器的示例，在这个示例中，我们将查询一个包含两个字段的索引：</p>PUT linear_retriever_example
{
  "mappings": {
    "properties": {
      "semantic_text_field": { &lt;1&gt;
        "type": "semantic_text",
        "inference_id": ".multilingual-e5-small-elasticsearch"
      },
      "text_field": { &lt;2&gt;
        "type": "text"
      }
    }
  }
}<p>1.<code>semantic_text_field</code> 是一个<code>semantic_text</code> 字段，使用文本嵌入模型<a href="https://www.elastic.co/docs/explore-analyze/machine-learning/nlp/ml-nlp-e5">E5</a></p><p><code>text_field</code> 是一个标准的<code>text</code> 字段</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "retrievers": [
        {
          "retriever": {
            "standard": {
              "query": {
                "match": { &lt;1&gt;
                  "semantic_text_field": "foo"
                }
              }
            }
          },
          "normalizer": "minmax"
        },
        {
          "retriever": {
            "standard": {
              "query": {
                "match": {
                  "text_field": "foo"
                }
              }
            }
          },
          "normalizer": "minmax"
        }
      ]
    }
  }
}<p>1.我们在 字段上使用 查询，我们<a href="https://www.elastic.co/search-labs/blog/semantic-search-match-knn-sparse-vector#we-made-match-happen-in-semantic-search!"> 在 Elasticsearch 8.18/9.0</a> 中添加了对<code>match</code> 该查询的 支持<code>semantic_text</code></p><p>
在构建查询时，我们需要牢记<code>semantic_text_field</code> 使用的是文本嵌入模型，因此对它的任何查询都会产生 0 到 1 之间的分数。我们还需要知道<code>text_field</code> 是一个标准的<code>text</code> 字段，因此对它的查询将产生一个无限制的分数。为了创建具有适当相关性的结果集，我们需要使用一种检索器，在合并查询得分之前将其归一化。在本例中，我们使用了<code>minmax</code> 归一化的线性检索器，它将每个查询的得分归一化为介于 0 和 1 之间的值。</p><p>本例中的查询结构相当简单，因为只涉及两个字段。然而，随着字段的增加和类型的变化，它很快就会变得复杂。这表明，要编写有效的混合搜索查询，往往需要对所查询的索引有更深入的了解，这样才能在组合之前对组件查询得分进行适当的归一化处理。这对混合搜索的广泛应用构成了障碍。</p><h3>查询分组</h3><p>让我们扩展一下示例：如果我们想查询一个<code>text</code> 字段和两个<code>semantic_text</code> 字段，该怎么办？我们可以构建这样一个查询：</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "retrievers": [
        {
          "retriever": {
            "standard": {
              "query": {
                "semantic": {
                  "field": "semantic_text_field_1",
                  "query": "foo"
                }
              }
            }
          },
          "normalizer": "minmax"
        },
        {
          "retriever": {
            "standard": {
              "query": {
                "semantic": {
                  "field": "semantic_text_field_2",
                  "query": "foo"
                }
              }
            }
          },
          "normalizer": "minmax"
        },
        {
          "retriever": {
            "standard": {
              "query": {
                "match": {
                  "text_field": "foo"
                }
              }
            }
          },
          "normalizer": "minmax"
        }
      ]
    }
  }
}<p>这表面上看起来不错，但也有潜在的问题。现在，<code>semantic_text</code> 场比赛占总分的⅔：</p>Total Score = N(semantic_text_field_1 score) + N(semantic_text_field_2 score) + N(text_field score)<p>这可能不是你想要的结果，因为这会造成分数不平衡。在只有 3 个字段的示例中，这种影响可能并不明显，但如果查询的字段较多，就会出现问题。例如，大多数索引包含的词法字段远远多于语义字段（即<code>dense_vector</code>,<code>sparse_vector</code>, 或<code>semantic_text</code>) 。如果我们使用上述模式查询一个包含 9 个词法字段和 1 个语义字段的索引呢？词性匹配将占得分的 90% ，从而削弱语义搜索的有效性。</p><p>解决这一问题的常用方法是将查询分为词汇和语义两个类别，并对两者进行平均加权。这就避免了任一类别在总分中占主导地位。</p><p>让我们付诸实践。在使用线性检索器时，本例中的分组查询方法会是怎样的？</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "retrievers": [
        {
          "retriever": {
            "linear": {
              "retrievers": [
                {
                  "retriever": {
                    "standard": {
                      "query": {
                        "semantic": {
                          "field": "semantic_text_field_1",
                          "query": "foo"
                        }
                      }
                    }
                  },
                  "normalizer": "minmax"
                },
                {
                  "retriever": {
                    "standard": {
                      "query": {
                        "semantic": {
                          "field": "semantic_text_field_2",
                          "query": "foo"
                        }
                      }
                    }
                  },
                  "normalizer": "minmax"
                }
              ]
            }
          },
          "normalizer": "minmax"
        },
        {
          "retriever": {
            "standard": {
              "query": {
                "match": {
                  "text_field": "foo"
                }
              }
            }
          },
          "normalizer": "minmax"
        }
      ]
    }
  }
}<p>哇，真是啰嗦！您甚至可能需要上下滚动多次才能查看整个查询！在这里，我们使用两级标准化来创建查询组。数学上可以表示为</p>Total Score = N(N(semantic_text_field_1 score) + N(semantic_text_field_2 score)) + N(text_field score)<p>这第二级规范化可确保<code>semantic_text</code> 字段和<code>text</code> 字段的查询权重均匀。请注意，在本例中，我们省略了<code>text_field</code> 的二级规范化，因为只有一个词法字段，这样可以避免<em>更多的</em>繁琐。</p><p>这种查询结构已经很笨重了，而且我们只查询三个字段。随着查询字段的增多，即使是经验丰富的搜索从业人员也越来越难以驾驭。</p><h2>多字段查询格式</h2><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt5d9007d279f0da29/6a17f17714d90c39cf79b6f5/dd04e1686076a574b717c1460acfe4eb79299208-1600x1600.jpg" alt="" /><p>我们在 Elasticsearch 8.19、9.1 和 无服务器 中为线性和 RRF 检索器添加了<a href="https://www.elastic.co/cloud/serverless"> </a><a href="https://www.elastic.co/docs/reference/elasticsearch/rest-apis/retrievers#multi-field-query-format">多字段查询格式</a> ，以简化所有这些操作。现在，您只需使用"...... "即可执行与上述相同的查询：</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "fields": [ "semantic_text_field_1", "semantic_text_field_2", "text_field" ],
      "query": "foo",
      "normalizer": "minmax"
    }
  }
}<p>这将查询从 55 行缩减到 9 行！Elasticsearch 自动将索引映射用于</p><ul><li><p>确定每个查询字段的类型</p></li><li><p>将每个字段归入一个词汇或语义类别</p></li><li><p>在最终得分中平均分配每个类别的权重</p></li></ul><p>这样，任何人都可以执行有效的混合搜索查询，而无需了解有关索引或所用推理端点的详细信息。</p><p>使用 RRF 时，可以省略<code>normalizer</code> ，因为排名是相关性的代表：</p>GET rrf_retriever_example/_search
{
  "retriever": {
    "rrf": {
      "fields": [ "semantic_text_field_1", "semantic_text_field_2", "text_field" ],
      "query": "foo"
    }
  }
}<h2>每场增强</h2><p>在使用线性检索器时，您可以应用每个字段增强功能来调整某些字段中匹配的重要性。例如，假设您要查询四个字段：两个<code>semantic_text</code> 字段和两个<code>text</code> 字段：</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "fields": [ "semantic_text_field_1", "semantic_text_field_2", "text_field_1", "text_field_2" ],
      "query": "foo",
      "normalizer": "minmax"
    }
  }
}<p>默认情况下，每个字段在其组（词法或语义）中的权重相同。比分细目如下</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltdc6e197e5ff7b68d/6a17f179505ac32834ad8c46/ba31c76189e3a1e5b1638437ccf0528aafec2598-1600x549.png" alt="查询组和领域得分的比较" /><p>换句话说，每个字段占总分的 25% 。</p><p>我们可以使用<code>field^boost</code> 语法为任何字段添加每个字段的提升。让我们将<code>semantic_text_field_1</code> 和<code>text_field_1</code> 提升 2：</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "fields": [ "semantic_text_field_1^2", "semantic_text_field_2", "text_field_1^2", "text_field_2" ]
      "query": "foo",
      "normalizer": "minmax"
    }
  }
}<p>现在的比分是这样的</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltccc9ed7d6e865a5e/6a17f17abe6086a31d004882/de20e555d52f914bf483a048d056f54f4fece757-1600x549.png" alt="通过 ref 和混合搜索更改字段权重" /><p>每个查询组的权重仍然相同，但组内字段的权重发生了变化：</p><ul><li><p><code>semantic_text_field_1</code> 是语义查询组得分的 66% ，是总分的 33% </p></li><li><p><code>text_field_1</code> 是词法查询组得分的 66% ，是总分的 33% </p></li></ul><p>ℹ️ 请注意，在按字段提升时，总分范围不会改变。这是分数标准化的预期副作用，可确保词法和语义查询分数保持直接可比性。</p><p>ℹ️ 在 Elasticsearch 9.2+ 中，每个字段的提升也可与 RRF 检索器一起使用</p><h3>通配符分辨率</h3><p>您可以在<code>fields</code> 参数中使用<code>*</code> 通配符来匹配多个字段。继续上面的例子，这个查询在功能上等同于明确查询<code>emantic_text_field_1</code>,<code>semantic_text_field_2</code>, 和<code>text_field_1</code> ：</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "fields": [ "semantic_text_field_*", "*_field_1" ],
      "query": "foo",
      "normalizer": "minmax"
    }
  }
}<p>值得注意的是，<code>*_field_1</code> 模式同时匹配<code>text_field_1</code> 和<code>semantic_text_field_1</code> 。查询将自动执行，就像明确查询每个字段一样。<code>semantic_text_field_1</code> 同时匹配两种模式也没有问题；在执行查询之前，所有匹配的字段名称都会被去除重复。</p><p>您可以通过多种方式使用通配符：</p><ul><li><p>前缀匹配（例如：<code>*_text_field</code>)</p></li><li><p>内联匹配 (ex:<code>semantic_*_field</code>)</p></li><li><p>后缀匹配（例如：<code>semantic_text_field_*</code>)</p></li></ul><p>您还可以使用多个通配符来应用上述组合，例如<code>*_text_field_*</code> 。</p><h3>默认查询字段</h3><p>多字段查询格式还允许您查询您一无所知的索引。如果省略<code>fields</code> 参数，它将查询由<a href="https://www.elastic.co/docs/reference/elasticsearch/index-settings/index-modules">index.query.default_field 索引设置</a>指定的所有字段：</p>GET linear_retriever_example/_search
{
  "retriever": {
    "linear": {
      "query": "foo",
      "normalizer": "minmax"
    }
  }
}<p>默认情况下，<code>index.query.default_field</code> 设置为<code>*</code> 。该通配符将解析索引中支持术语查询的所有字段类型，其中大多数字段类型都支持术语查询。例外情况是</p><ul><li><p><code>dense_vector</code> 领域</p></li><li><p><code>rank_vector</code> 领域</p></li><li><p>几何领域：<code>geo_point</code>, <code>shape</code></p></li></ul><p>当你想在第三方提供的索引上执行混合搜索查询时，该功能尤其有用。多字段查询格式可让您以简单的方式执行适当的查询。只需排除<code>fields</code> 参数，就能查询所有适用字段。</p><h2>结论</h2><p>分数范围问题会让有效的混合搜索实施起来很头疼，尤其是在对所查询的索引或所使用的推理端点了解有限的情况下。线性和 RRF 检索器的多字段查询格式将基于查询分组的自动混合搜索方法打包到简单易用的应用程序接口中，从而减轻了这种痛苦。附加功能（如按字段增强、通配符解析和默认查询字段）扩展了功能，涵盖了多种使用情况。</p><h2>立即试用多字段查询格式</h2><p>您可以通过<a href="https://www.elastic.co/docs/deploy-manage/deploy/elastic-cloud/create-serverless-project"> 免费试用</a> ，在完全托管的 Elasticsearch<a href="https://www.elastic.co/cloud/serverless"> Serverless 项目中使用多字段查询格式检查线性检索器和</a> RRF 检索器。它还提供从 8.19&amp; 9.1 开始的堆栈版本。</p><p>只需一条命令，几分钟即可在本地环境中开始使用：</p>curl -fsSL https://elastic.co/start-local | sh<p></p>]]></content:encoded>
    <link>https://www.elastic.co/search-labs/blog/hybrid-search-multi-field-query-retrievers-elasticsearch</link>
    <guid isPermaLink="true">https://www.elastic.co/search-labs/blog/hybrid-search-multi-field-query-retrievers-elasticsearch</guid>
    <category><![CDATA[混合搜索]]></category>
    <category><![CDATA[相关性]]></category>
    <dc:creator><![CDATA[Mike Pellegrini]]></dc:creator>
    <enclosure url="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt89e066372c549595/6a17f17c3e9e457c38ba1583/4494f98ae3958bbdbc6171df9677fc4d65ec5640-1536x1024.png" length="0" type="image/png"/>
    <pubDate>Thu, 27 Nov 2025 00:00:00 GMT</pubDate>
  </item>
  </channel>
</rss>