"source": "double norm=l2norm(params.queryVector, 'vec')^2; return 1/(1+norm);"
or
"source": "1/(1+l2norm(params.queryVector, 'vec')^2)"
or
"source": "1.0/(1.0+l2norm(params.queryVector, 'vec')^2)"
all result in
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"double norm=l2norm(params.queryVector ...",
" ^---- HERE"
],
"script" : "double norm=l2norm(params.queryVector, 'vec')^2; return 1/(1+norm);",
"lang" : "painless",
"position" : {
"offset" : 12,
"start" : 0,
"end" : 37
},
"caused_by" : {
"type" : "class_cast_exception",
"reason" : "Cannot cast from [double] to [int]."
}
}
or
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"1.0/(1.0+l2norm(params.queryVe ...",
" ^---- HERE"
],
"script" : "1.0/(1.0+l2norm(params.queryVector, 'vec')^2)",
"lang" : "painless",
"position" : {
"offset" : 5,
"start" : 0,
"end" : 30
},
"caused_by" : {
"type" : "class_cast_exception",
"reason" : "Cannot cast from [double] to [int]."
}
}
How to fix Cannot cast from [double] to [int].
? The following does not have such error by removing ^2
, which is required by script formula:
"source": "1.0/(1.0+l2norm(params.queryVector, 'vec'))"