维基百科页面的 Elasticsearch 查询

Elasticsearch query for wikipedia pages

我已经在 elasticsearch 上索引了所有维基百科页面,现在我想根据我创建的关键字列表来搜索它们。 elasticsearch 上的文档只有三个字段:id 用于页面 ID,title 用于页面标题,content 用于页面内容(已经清除了维基百科标记)。

我的目标是使用参数 action=querylist=search 尽可能多地重现 mediawiki 查询 api。例如,给定关键字“非黎曼度量空间”,调用

https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srlimit=10&srprop=&srsearch=non%20riemannian%20metric%20spaces

列出了与这些关键字最相关的页面。

到目前为止,我一直在使用相当简单的 elasticsearch 搜索查询,例如

POST _search
{
  "query": {
    "bool" : {
      "must" : {
        "match" : {
          "content": {
            "query": "non riemannian metric spaces"
          }
        }
      },
      "should" : {
        "match" : {
          "title": {
            "query": "non riemannian metric spaces",
            "boost": x
          }
        }
      }
    }
  }
}

几个提升值,例如 120.5。这已经给出了一些不错的结果,因为我获得的页面与关键字相关,但有时它们与我使用 mediawiki api.

获得的页面不完全相同。

我很高兴听到一些关于如何 fine-tune elasticsearch 查询更准确地模仿 mediawiki api 行为的建议。甚至,由于 mediawiki api 本身是用 elasticsearch 和 cirrussearch 构建的,我想知道上面带有这些特定参数的入口点的实际 elasticsearch 查询是否公开可用。

提前致谢!

UPDATE(在 Robis Koopmans 的回答之后):看到 actual querycirrusDumpQuery 确实非常有用。然而,我确实有一些关于查询的后续问题:

  1. 该查询有一组类似的 multi_match 子句搜索我在 fields 中的关键字,如 ["title.plain^1", "title^3"]。虽然我理解 ^n 提升,但我忽略了 .plain 指的是什么。它是否与 elasticsearch 本身有关(即它是索引时从 title 派生的字段?)还是与它们使用的特定 mediawiki 映射有关?无论如何,如果能提供更多相关信息,我将不胜感激。

  2. 在查询的其他位置,有一个 {"match": {"all": {...}}} 子句。这里的 all 键到底是什么?它是文档字段吗?与match_all子句有关吗?

  3. 查询中出现的 suggest 字段是什么?在乐谱解释中,它似乎与同义词相关联。在这种情况下如何处理?

  4. 要在搜索后执行,有一个 rescore 子句和另外两个评分函数。其中之一使用维基百科页面的 popularity_score。那是什么?

  5. 最后,最终对页面进行排名的最相关分数是 sltr 子句的输出。其中,有一个"model": "enwiki-20220421-20180215-query_explorer",在乐谱解释中用LtrModel: naive_additive_decision_tree标识。我知道这个模型是一些存储的 LTR 模型。但是,由于它似乎是最终排序结果中最相关的数字,那么该模型到底是什么,是否公开可用?

请随时回答您知道答案的问题,再次感谢!

您可以将 cirrusDumpQuery 添加到您的查询中

示例:

https://en.wikipedia.org/w/index.php?title=Special:Search&cirrusDumpQuery=&search=cat+dog+chicken&ns0=1

更多信息:

https://www.mediawiki.org/wiki/Extension:CirrusSearch#API

您不能直接对 Wikipedia 进行 Elasticsearch 查询,但 CirrusSearch 可以生成 many types of queries 超越全文搜索的结果。从你的问题中不清楚你正在寻找什么类型的查询,但如果你更喜欢仅通过文本相似性而不是页面浏览量来加权结果,那么可能值得查看排序选项。

The query has a set of similar multi_match clauses searching my keywords in fields like ["title.plain^1", "title^3"]. While I understand the ^n boost, I ignore what .plain refers to. Does it have to do with elasticsearch itself (i.e. is it a field derived from title at index time?) or is it something that has to do with the specific mediawiki mapping they use? In any case, I would appreciate some more information about this.

.plain 字段是作为 elasticsearch 映射的一部分生成的。普通字段中的当前 settings and mappings are available to see how exactly they work. mediawiki.org includes a search glossary 条目也是如此。一般来说,顶级字段包含经过高度处理的文本形式,普通字段使用最少的分析。

At some other point in the query, there is a {"match": {"all": {...}}} clause. What exactly is the all key here? Is it a document field? Is it related with the match_all clause?

mediawiki.org 还包含一个(不完整的)CirrusSearch schema,它简要描述了这些字段和使用的各种分析链组件。 all 字段是针对搜索索引提供强大 first-pass 过滤器的优化。

What is the suggest field that appears in the query? In the score explanation it seems to be associated with synonyms. How are those handled in this case?

建议字段包含文章标题和重定向的 shingles(单词 ngram),本质上是 pre-calculation 短语查询。建议可能看起来像解释输出中的同义词,它们通常包含这些,但它也包括拼写错误、翻译以及编辑器创建重定向的许多其他原因。重定向匹配通常是一个很强的相关性信号。

To be performed after the search, there is a rescore clause with two other score functions. One of them uses the popularity_score of a wikipedia page. What is that?

这是转到该文章的 wiki 页面浏览量的比例。

And finally, the most relevant score that ends up ranking the pages is the output of the sltr clause. In it, there is a "model": "enwiki-20220421-20180215-query_explorer", and in the score explanation it is identified with a LtrModel: naive_additive_decision_tree. I understand that this model is some stored LTR model. However, since it seems to be the most relevant number in the final sorting of the results, what exactly is that model and is it openly available?

此模型由 mjolnir and essentially overwrites the score from the rest of the query. There is some information in wikitech (found there as it is more specific to the WMF deployment of mediawiki than mediawiki itself), also a slide deck called From Clicks to Models 生成,可能会让您深入了解该代码库中发生的事情。也许重要的是要知道 mjolnir 仅适用于词袋查询、调用短语的查询或其他专家功能跳过 ML 模型。

之前没有人问过这些模型,如果它们可能对排名插件有用 dumped the current models。这包含使用的特征定义和 xgboost 生成的决策树。

我没有找到在上面 link 的借口,但也许 CirrusSearch/Scoring 的草稿页面提到了检索和评分的一些因素,特别是对于可以查询的查询不会 运行 通过 mjolnir 模型,也可能有帮助。