Elasticsearch painless error script

I have no Java experience, and I have a problem with the ridiculous language elasticsearch script. (the name is painless, which he did not choose well).

For the following code, I get an 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 linked it as a 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 be included from [Double] to [double].

Can someone help me, tried many options with similar errors. Damn painless tongue ...

+8
source share
2 answers

.value, .

script :

double price = doc['newPrice'].value > 0.0 ? doc['price'].value / doc['newPrice'].value : 0; _score * params.constant * price
+19
doc['newPrice']

doc['newPrice'].value

+2

Source: https://habr.com/ru/post/1665015/


All Articles