我们应该如何检查map中作为参数传递给无痛脚本的键是否具有值?我目前正在Elasticsearch 6.8.4
中执行此操作if (params.feedId!=null) {
whatever()
}
但在
时会引发此异常params.feedId
为空
ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception,reason=Cannot cast null to a primitive type [void].]]
它在Elasticsearch 5.6.13上可以正常工作,因此似乎有重大变化,但到目前为止我什么都找不到。
更新:实际上,这部分脚本不是问题,但在某些部分中,我们正在执行 return null; 来中断脚本的过程,由于某种原因,它似乎不再起作用。为了提供更多背景信息,我正在使用Java API(更具体地说是Rest High Level客户端)进行这些更新。
我已经能够使用类似curl的命令重现该问题
curl -X POST "localhost:9200/myindex/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'
{
"script": {
"source": "ctx._source.result = true; return null;"
}
}'
这将产生下一个输出:
{
"error" : {
"root_cause" : [
{
"type" : "remote_transport_exception","reason" : "[sBix--f][172.18.0.4:9300][indices:data/write/update[s]]"
}
],"type" : "illegal_argument_exception","reason" : "failed to execute script","caused_by" : {
"type" : "script_exception","reason" : "compile error","script_stack" : [
"... ce.result = true; return null;"," ^---- HERE"
],"script" : "ctx._source.result = true; return null;","lang" : "painless","caused_by" : {
"type" : "illegal_argument_exception","reason" : "Cannot cast null to a primitive type [void]."
}
}
},"status" : 400
}
只需将 return null; 替换为 return; ,即可使此脚本在ES 6.8.4中正常工作。
在Elasticsearch:https://github.com/elastic/elasticsearch/issues/35888发现了此问题。在不同版本的Elasticsearch中,短路的工作方式存在一些不一致之处。