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: https://github.com/elasticsearch/elasticsearch/issues/8216 -- 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 [email protected]. 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.
