I added to my elastic query a scripted filed, called "age", which is define like this:
"script_fields" : {
"age" : {
"script" : "DateTime.now().year - doc['date_of_birth'].date.year"
}
}
Now, i also have other field for each person, called "myscore". I'm trying to aggreagte on myscore, and create a sub-aggregation of age. the result i should want to see is something like:
key: 25
buckets: [
67,
70,
74
]
key: 62
buckets: [
45
]
I added this aggregation:
{
"myagg": {
"terms": {
"field": "myscore",
"size": 1000,
"order": {
"_count": "desc"
}
},
"aggregations": {
"inner": {
"terms": {
"field": "age",
"size": 1000
}
}
}
}
}
but the inner buckets of the age returns empty (In the hits itself i can see the age field)...
any ideas?