With Elasticsearch and painless is there a way to implement an exponential function? I can't seem to find anything. I have something like this.
bdy = {
"from" : 0,
"size" : 10,
"query": {
"function_score": {
"query": {
"bool": {
"must": must_terms
}
},
"script_score": {
"script": {
"lang": "expression",
"source": "doc['release_year'].value"
}
}
}
}
}
I want to add some more complex math in the source field, like this.
"source": "Math.exponential(1/doc['release_year'].value)"
Is that possible? Or is there another scripting language that you can do that in within elasticsearch?
UPDATE
Actually looks like I can use.
"lang": "expression"
"source": "_score/10 + 1/(1+ exp(-(doc['release_year'].value*a)))"
If anyone has other options that would be cool.
You can do it in Painless the same way with Math.exp()
"source": "_score/10 + 1/(1+ Math.exp(-(doc['release_year'].value*a)))"
See the full Painless API here: https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference.html