gpt4 book ai didi

Elasticsearch scripted_metric null_pointer_exception

转载 作者:行者123 更新时间:2023-12-03 01:23:48 28 4
gpt4 key购买 nike

我正在尝试使用 scripted_metric Elasticsearch 的 aggs 和通常情况下,它与我的其他脚本完美配合

但是,使用下面的脚本,我遇到了一个名为“null_pointer_exception”的错误,但它们只是复制粘贴的脚本并且已经为 6 个模块工作

$max = 10;

{
"query": {
"match_all": {}
//omitted some queries here, so I just turned it into match_all
}
},
"aggs": {
"ARTICLE_CNT_PDAY": {
"histogram": {
"field": "pub_date",
"interval": "86400"
},
"aggs": {
"LATEST": {
"nested": {
"path": "latest"
},
"aggs": {
"SUM_SVALUE": {
"scripted_metric": {
"init_script": "
state.te = [];
state.g = 0;
state.d = 0;
state.a = 0;
",
"map_script": "
if(state.d != doc['_id'].value){
state.d = doc['_id'].value;
state.te.add(state.a);
state.g = 0;
state.a = 0;
}
state.a = doc['latest.soc_mm_score'].value;
",
"combine_script": "
state.te.add(state.a);
double count = 0;
for (t in state.te) {
count += ((t*10)/$max)
}
return count;
",
"reduce_script": "
double count = 0;
for (a in states) {
count += a;
}
return count;
"
}
}
}
}
}
}
}
}

我尝试在 Kibana 中运行此脚本,这是错误消息:

Error

我得到的是, reduce_script 有问题部分,试图改变这部分:

来自
for (a in states) {
count += a;
}


for (a in states) {
count += 1;
}

并且工作得很好,我觉得 a变量没有得到它应该持有的东西

这里有什么想法吗?非常感谢您的帮助,非常感谢!

最佳答案

原因解释here :

If a parent bucket of the scripted metric aggregation does not collect any documents an empty aggregation response will be returned from the shard with a null value. In this case the reduce_script's states variable will contain null as a response from that shard. reduce_script's should therefore expect and deal with null responses from shards.



所以很明显你的一个桶是空的,你需要像这样处理那个空:
            "reduce_script": "
double count = 0;
for (a in states) {
count += (a ?: 0);
}
return count;
"

关于Elasticsearch scripted_metric null_pointer_exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59087489/

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