# Top Hits within Top Hits and custom key sorting with explicit order

**URL:** <https://discuss.elastic.co/t/top-hits-within-top-hits-and-custom-key-sorting-with-explicit-order/23209>\
**Category:** Elasticsearch\
**Created:** [April 13, 2015, 1:13pm UTC](https://discuss.elastic.co/t/top-hits-within-top-hits-and-custom-key-sorting-with-explicit-order/23209 "2015-04-13T13:13:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JZ1](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@JZ1](https://discuss.elastic.co/u/JZ1)\
**Post date:** [April 13, 2015, 1:13pm UTC](https://discuss.elastic.co/t/top-hits-within-top-hits-and-custom-key-sorting-with-explicit-order/23209/1 "2015-04-13T13:13:08Z")

</div>

Hi all,

Assume that we have a field with N unique values. Documents are grouped by  
these N unique values.

We want to create a Top Hits aggregation, and create for each bucket  
another Top Hits aggregation. We use the nested / deeper Top Hits  
Aggregation to create groups based on these N unique values.

Question: is this possible in ES?

However, we do not want to sort the keys within an bucket by a field in  
ascending or descending order, but by providing by the list of N unique  
values in an explicit order using a list.  
We do not want to sort it by relevance score based on the main query as  
well.

I guess we can do this sorting on the application side, since the list of N  
unique values will be limited.

Cheers,  
/JZ

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/37c0d048-3294-4337-85f8-7d95378be75e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/37c0d048-3294-4337-85f8-7d95378be75e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:20am UTC](https://discuss.elastic.co/t/top-hits-within-top-hits-and-custom-key-sorting-with-explicit-order/23209/2 "2017-07-06T00:20:05Z")

</div>


