gpt4 book ai didi

groovy - Elasticsearch-在function_score和访问字段有效负载内使用groovy脚本

转载 作者:行者123 更新时间:2023-12-03 01:04:44 24 4
gpt4 key购买 nike

我试图了解使用groovy脚本时访问有效负载的最佳方法是什么。

我想做这样的事情:

sum = 0;
categories = doc['category'].values;
for (category in categories){
sum += category.payload
}
return sum;

编辑:
感谢@Val和@Lee H,我到了现在可以实际访问有效负载的位置。但是建议的解决方案是使用_index而不是我要查找的内容,_index允许访问索引范围内的统计信息,而不是针对特定文档。

我想遍历每个文档,并获取其有效负载,然后将其乘以一些常量,比如说。

这样做时:_index ['category']。get('term',_PAYLOADS)我将获得“term”的所有有效负载的列表,这不是我想要的。

那么,有没有一种方法可以从文档范围访问字段有效负载?

最佳答案

查看有关的文档
term positions and payloads
它显示了访问字段有效负载的示例

在此复制最后一个示例:

Example: sums up all payloads for the term foo.

termInfo = _index['my_field'].get('foo',_PAYLOADS);
score = 0;
for (pos in termInfo) {
score = score + pos.payloadAsInt(0);
}
return score;

关于groovy - Elasticsearch-在function_score和访问字段有效负载内使用groovy脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32340079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com