如何从弹性搜索中的script_fields计算分数? [英] How to compute scores from script_fields in elasticsearch?

查看:115
本文介绍了如何从弹性搜索中的script_fields计算分数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用script_fields生成自定义字段。我想使用该字段来生成文档的分数。如何在弹性搜索中实现这一点。如果有任何人可以发布示例查询,那将是很棒的。

解决方案

这不是真的可能,因为文档的分数计算脚本字段值尚未计算。搜索请求通常分两个阶段执行:查询抓取。在查询期间,计算相位分数,并选择顶级文档进行检索。然后在获取阶段中使用顶级文档的列表来检索文档。在此检索过程中,计算脚本字段。换句话说,为了使用脚本对文档进行分数,您需要在查询阶段中使用此脚本,将其放入 function_score 查询,例如


Im generating a custom field using "script_fields". And I would like to use that field to generate score for the documents. How can I achieve this in elasticsearch. It would be great if any one could post an example query.

解决方案

It's not really possible because when scores for the document are calculated the script field values are not computed yet. Search requests are typically executed in two phases: query and fetch. During the query phase scores are calculated and top documents are selected for retrieval. The list of the top documents is then used during fetch phase to retrieve the documents. During this retrieval process the script fields are calculated.

In other words in order to use script to score the documents, you need to use this script in the query phase by placing it into the function_score query, for example

这篇关于如何从弹性搜索中的script_fields计算分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆