From 8e7e6a7efa6ceadf49adbdb0c3c869eac67e1578 Mon Sep 17 00:00:00 2001 From: gaobinlong Date: Tue, 23 Sep 2025 17:08:43 +0800 Subject: [PATCH 1/3] Field collapsing supports search_after parameter Signed-off-by: gaobinlong --- .../searching-data/collapse-search.md | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/_search-plugins/searching-data/collapse-search.md b/_search-plugins/searching-data/collapse-search.md index 771d79b622b..9454255677f 100644 --- a/_search-plugins/searching-data/collapse-search.md +++ b/_search-plugins/searching-data/collapse-search.md @@ -162,6 +162,33 @@ The `collapse` parameter affects only the top search results and does not change --- +## Collapse with search_after + +You can paginate collapsed search results using the `search_after` parameter. The collapse field and sort field must be the same, and only one sort field can be specified. + +The following example shows how to use collapse with `search_after`: + +```json +GET /bakery-items/_search +{ + "query": { + "match": { + "category": "cakes" + } + }, + "collapse": { + "field": "item" + }, + "sort": [ + { + "item": "asc" + } + ], + "search_after": ["Chocolate Cake"] +} + +``` + ## Expanding collapsed results You can expand each collapsed top hit with the `inner_hits` property. @@ -229,4 +256,4 @@ GET /bakery-items/_search This query searches for documents in the `cakes` category and groups the search results by the `item_name` field. For each `item_name`, it retrieves the top three lowest-priced items and the top three most recent items, sorted by `baked_date` in descending order. -You can expand the groups by sending an additional query for each inner hit request corresponding to each collapsed hit in the response. This can significantly slow down the process if there are too many groups or inner hit requests. The `max_concurrent_group_searches` request parameter can be used to control the maximum number of concurrent searches allowed in this phase. The default is based on the number of data nodes and the default search thread pool size. \ No newline at end of file +You can expand the groups by sending an additional query for each inner hit request corresponding to each collapsed hit in the response. This can significantly slow down the process if there are too many groups or inner hit requests. The `max_concurrent_group_searches` request parameter can be used to control the maximum number of concurrent searches allowed in this phase. The default is based on the number of data nodes and the default search thread pool size. From 006d84bcd77a173b85285eef6c3390cc37d826ca Mon Sep 17 00:00:00 2001 From: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:10:23 -0400 Subject: [PATCH 2/3] Apply suggestions from code review Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> --- _search-plugins/searching-data/collapse-search.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_search-plugins/searching-data/collapse-search.md b/_search-plugins/searching-data/collapse-search.md index 9454255677f..d22658150cd 100644 --- a/_search-plugins/searching-data/collapse-search.md +++ b/_search-plugins/searching-data/collapse-search.md @@ -164,7 +164,7 @@ The `collapse` parameter affects only the top search results and does not change ## Collapse with search_after -You can paginate collapsed search results using the `search_after` parameter. The collapse field and sort field must be the same, and only one sort field can be specified. +You can paginate collapsed search results using the `search_after` parameter. The collapsed field and sort field must be the same, and only one sort field can be specified. The following example shows how to use collapse with `search_after`: @@ -186,8 +186,8 @@ GET /bakery-items/_search ], "search_after": ["Chocolate Cake"] } - ``` +{% include copy-curl.html %} ## Expanding collapsed results From 772a26b0b6eef891e686e99911def56a60ed6495 Mon Sep 17 00:00:00 2001 From: Nathan Bower Date: Wed, 1 Oct 2025 11:19:53 -0400 Subject: [PATCH 3/3] Update _search-plugins/searching-data/collapse-search.md Signed-off-by: Nathan Bower --- _search-plugins/searching-data/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/searching-data/collapse-search.md b/_search-plugins/searching-data/collapse-search.md index d22658150cd..175608ef89f 100644 --- a/_search-plugins/searching-data/collapse-search.md +++ b/_search-plugins/searching-data/collapse-search.md @@ -166,7 +166,7 @@ The `collapse` parameter affects only the top search results and does not change You can paginate collapsed search results using the `search_after` parameter. The collapsed field and sort field must be the same, and only one sort field can be specified. -The following example shows how to use collapse with `search_after`: +The following example shows how to use `collapse` with `search_after`: ```json GET /bakery-items/_search