Ok, this seems easy from a relational perspective, but I'm becoming unable to achieve it on ES:
I have an index where, among others, there is a numeric field called year. I want to filter my index data, retrieving only those documents which year is equal to the maximum value of year whitin the whole index.
In a relational database using SQL you'd use something more or less like this:
select * from index where year = (select max(year) from index);
On ES I know that I can get my maximum year value through an aggregation:
{
"aggs": {
"maxYear": {
"max": {
"field": "year"
}
}
}
However, I'm being unable to use that maxYear calculated value on the same query. I've been trying to use different pipelines and aggregation combinations to no success.
Also I thought to store my maximum value on a runtime field, but now know really how to obtain that aggregated value on a runtime field.
Any insight on the matter will be much appreciated.