How to collect docs in order in collect() method of a custom aggregator

I am developing a custom aggregator using ES 1.3.4. It extends from
NumericMetricsAggregator.MultiValue class. Its code structure closely
resembles that of the Stats aggregator. For my requirements, I need the doc
Ids to be received in ascending order in the overridden collect() method.
For most queries, I do get the doc Ids in ascending order. Interestingly
for bool should queries with multiple clauses, I get doc Ids in descending
order. How can I fix this? Is this a bug?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f3fddb08-ef63-4378-8aa2-ea709612bbd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I asked the same question on github and got the answer which worked for me.
Here's the solution:

You can call aggregationContext.ensureScoreDocsInOrder(); to make sure that
docs are going to come in order, have a look for instance at
ReverseNestedAggregator which uses this method.

Queries are indeed allowed to emit documents out-of-order if allowed to do
so and if it makes things faster. I believe the only case when it happens
today is when you get Lucene's BooleanScorer which is used for top-level
disjunctions, so your observation makes sense.

Link to the issue:

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9beda810-af5c-4e5d-b2b2-0eda28aae470%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.