I have no Java experience and I have an issue with elasticsearch painless script language. (the name painless it's not well chosen).
For the following code I get the error:
{"lang": "painless",
"inline": "float price = doc['newPrice'] > 0.0 ? doc['price'] / doc['newPrice'] : 0; _score * params.constant * price",
"params": {"constant": 1.2}}}}
Cannot apply [>] operation to types [org.elasticsearch.index.fielddata.ScriptDocValues.Doubles] and [java.lang.Double].
I tied to cast it as float with (float) doc['newPrice'] > 0 with the same error.
Then I changed to "Double price = ((Double)doc['discountPrice'] > 0.0) ? doc['price'] / doc['discountPrice'] : 0; _score * params.constant * price",
And received:
'Cannot cast from [Double] to [double].'
Can somebody help me, tried lots of variations with similar kind of errors. Damn painless language...
You're simply missing the
.value
to access the field value.Your script needs to be like this instead: