elasticsearch/server
Nik Everett 126ec9edf6
Fix sorting terms by cardinality agg (#67839)
The cardinality agg delays calculating stuff until just before it is
needed. Before #64016 it used the `postCollect` phase to do this work
which was perfect for the `terms` agg but we decided that `postCollect`
was dangerous because some aggs, notably the `parent` and `child` aggs
need to know which children to build and they *can't* during
`postCollect`. After #64016 we built the cardinality agg results when we
built the buckets. But we if you sort on the cardinality agg then you
need to do the `postCollect` stuff in order to know which buckets
to build! So you have a chicken and egg problem. Sort of.

This change splits the difference by running the delayed cardinality agg
stuff as soon as you *either* try to build the buckets *or* read the
cardinality for use with sorting. This works, but is a little janky and
feels wrong. It feels like we could make a structural fix to the way we
read metric values from aggs before building the buckets that would make
this sort of bug much more difficult to cause. But any sort of solution
to this is a larger structural change. So this fixes the bug in the
quick and janky way and we hope to do a more structural fix to the way
we read metrics soon.

Closes #67782
2021-01-26 08:42:17 -05:00
..
licenses Upgrade to a new lucene 8.8.0 snapshot (#67691) 2021-01-19 13:33:19 +01:00
src Fix sorting terms by cardinality agg (#67839) 2021-01-26 08:42:17 -05:00
build.gradle Split test runner security permissions (#64748) 2020-11-09 11:41:49 -08:00