Get single value out of specific aggregation bucket document?

So I'm trying to work out a query for my project. But I can't figure out which way to go to achieve one of my goals in the query.

I'm aggregating my results, I'm getting the average score of each aggregation, but then I need to add up a single integer which can be found in the most recent document.

So just one result, sorted and ordered by DateTime so that the one result contains the most recent document, but how do I get the "urgency" variable integer out of it so that I can add it up to the average aggregation score?

Nobody?
This is what I got so far, but I can't get the value out of the document which has the max dateTimeStamp........

.Query(q => q
...
)
.Aggregations(a => a
.Terms("Hash", st => st
.Field(o => o.messageHash.Suffix("keyword")).OrderDescending("Avg-Score")
.Aggregations(aa => aa
.Max("Max-DateTime", ff => ff
.Field(oo => oo.dateTimeStamp)
)
.Average("Avg-Score", sc => sc
.Script("_score")
)
.BucketScript("finalScore", scb => scb
.BucketsPath(bp => bp
.Add("avgScore", "Avg-Score")
.Add("maxDateTime", "Max-DateTime"))
.Script(i => i.Inline("avgScore").Lang("groovy"))
//int t = 0; if (doc['dateTimeStamp'].avlue == params.maxDateTime) { t = doc['urgency'].value; } return t;
)
)
)
)
);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.