-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Multiple levels of field collapse #24855
Description
Describe the feature:
Currently, we support 1 level of field collapse + inner hits (https://www.elastic.co/guide/en/elasticsearch/reference/5.4/search-request-collapse.html#_expand_collapse_results). However, some users need to collapse multiple levels (while still providing features provided by field collapse, e.g. pagination), e.g. to simply provide the top item for 2 tiers of collapsing. For those users, they have a few options:
- Ignore the pagination requirement and do terms+terms+top_hits (which will be fine for some users)
- In a single query, ask for a very large
inner_hitssizeand then reduce the set client-side - Perform multiple queries: 1 for the first collapse level and then iterate through these for secondary queries
When 1 is not an option for business purposes, this leaves you with options 2 and 3. 2 is a fairly abusive/expensive way to solve it when you're looking for just the top result under each of the top-level collapse. 3 adds a lot of client code as well as round trips (which increase overall query latency).
Unfortunately, opening up multiple levels also opens the query up for abuse in different ways (asking for high depth)
I wanted to open up for discussion the possibility of having multiple levels of field collapse, even if there were additional restrictions (e.g. only 2 levels, only can return a much smaller result set from the second level, etc)