I have an elastic index with authors field as array of objects:
"authors" : [
{
"email" : "100@gmail.com",
"authid" : "100",
},
{
"email" : "200@gmail.com",
"authid" : "200",
}, {
"email" : "300@gmail.com",
"authid" : "300",
},
]
And am calculating sum of relevance score of each author as follows:
"aggregations": {
"authid": {
"terms": {
"field": "authors.authid",
"order": [
{
"relevance": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"relevance": {
"sum": {
"script": {
"source":"_score"
"lang": "painless"
}
}
}
}
}
}
Here, I need to boost score of authors whose id comes as the first or last in authors array
I tried as below:
"aggregations": {
"relevance": {
"sum": {
"script": {
"source": "params._source.authors[0].authid == params.author_id || params._source.authors[-1].authid == params.author_id ? _score * params.boost_factor : _score",
"params": {
"author_id": "{{key}}",
"boost_factor": 2
},
"lang": "painless"
}
}
}
}
Here I tried to get outer bucket key using params.key.But its not returnig its original value