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

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

问题描述

我使用script_fields"生成自定义字段.我想使用该字段为文档生成分数.我怎样才能在弹性搜索中实现这一点.如果有人可以发布示例查询,那就太好了.

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.

推荐答案

这实际上是不可能的,因为在计算文档的分数时还没有计算脚本字段值.搜索请求通常分两个阶段执行:queryfetch.在查询阶段计算分数并选择最重要的文档进行检索.然后在 fetch 阶段使用顶级文档的列表来检索文档.在此检索过程中,计算脚本字段.

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.

换句话说,为了使用脚本对文档进行评分,您需要在查询阶段使用此脚本,将其放入function_score 查询,例如

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

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

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