Specify bucket-wise sort order

I have a use case where I need to get buckets (with documents) and depending on the bucket, specify different field to sort by.
All documents have the field, say, "type", which I will aggregate by. And for just 1 type I want the documents returned to be sorted by createdTime. Rest all documents should be sorted by modifiedTime. Can I achieve this within a single aggregation?

I know I can achieve my goal with 2 parallel partial aggregations (separate the one type from the rest).

I assume this could have been not added because this is a rarer case where the querier knows the key of the buckets that are going to be returned. Let me know if this can be done in a single aggregation?

Thanks for the help!

I believe the only way you could do this with a single aggregation, is if you created a third field (let's say for sake of conversation sortTime) and populated it with the correct data based on type. I haven't played with it, but you might be able to use runtime fields to do what you want.

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