From 23e0e89f0b2d598a229bc09da0953ed6343f3c30 Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Tue, 6 Aug 2024 18:34:58 +0100 Subject: [PATCH 01/27] adding documentation for collapsing search results Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 332 +++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 _search-plugins/collapse-search.md diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md new file mode 100644 index 0000000000..61b23949ad --- /dev/null +++ b/_search-plugins/collapse-search.md @@ -0,0 +1,332 @@ +--- +layout: default +title: Collapse search results +nav_order: 3 +--- + +# Collapse search results + +The collapse parameter in OpenSearch enables you to group search results by a particular field value, returning only the top document within each group. This feature is especially beneficial for reducing redundancy and enhancing performance when handling large datasets. By grouping these documents, you can streamline the search results and focus on unique entries, avoiding duplicates. + +### Example of collapsing search results + +To collapse search results by the `item` field and sort them by `price`, you can use the following query: + +```json +GET /bakery-items/_search +{ + "query": { + "match": { + "category": "cakes" + } + }, + "collapse": { + "field": "item" + }, + "sort": ["price"], + "from": 0 +} + +``` + +Collapsing only impacts the top hits and does not influence aggregations. The total number of hits in the response represents the count of matching documents before any collapsing is applied. The exact number of unique groups formed by collapsing is not provided. For collapsing to work, the field must be a single-valued `keyword` or `numeric` type with `doc_values` enabled. + +### Expanding collapsed results + +You can expand each collapsed top hit with the `inner_hits` property. + +The following query will retrieve the top 5 items per bakery `item_name`, sorted by `price`. +`` + +```json +GET /bakery-items/_search +GET /bakery-items/_search +{ + "query": { + "match": { + "category": "Pastry" + } + }, + "collapse": { + "field": "item_name", + "inner_hits": { + "name": "top_items", + "size": 5, + "sort": [{ "price": "asc" }] + } + }, + "sort": ["price"] +} + +``` + +### Multiple Inner Hits for Each Collapsed Hit + +To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three least expensive items and the three most recent items for every bakery item. + +```json +GET /bakery-items/_search +{ + "query": { + "match": { + "category": "cakes" + } + }, + "collapse": { + "field": "item_name", + "inner_hits": [ + { + "name": "cheapest_items", + "size": 3, + "sort": ["price"] + }, + { + "name": "newest_items", + "size": 3, + "sort": [{ "baked_date": "desc" }] + } + ] + }, + "sort": ["price"] +} + +``` +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 3 cheapest items and the top 3 most recent items, sorted by the `baked_date` in descending order. + +The expansion of the group is done by sending an additional query for each inner hit request for each collapsed hit returned in the response. This can significantly slow down the process if there are too many groups and/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. + +### Second level of collapsing + +Second level of collapsing is also supported and is applied to inner hits. + + +```json +GET /bakery-items/_search +{ + "query": { + "match": { + "category": "cakes" + } + }, + "collapse": { + "field": "baker", + "inner_hits": { + "name": "recent_items", + "size": 3, + "sort": [{ "baked_date": "desc" }] + } + } +} +``` + + +response +```json +{ + "took": 8, + "timed_out": false, + "_shards": { + "total": 1, + "successful": 1, + "skipped": 0, + "failed": 0 + }, + "hits": { + "total": { + "value": 6, + "relation": "eq" + }, + "max_score": 0.61310446, + "hits": [ + { + "_index": "bakery-items", + "_id": "fSW9KJEB3prnZWCKY5wg", + "_score": 0.61310446, + "_source": { + "item_name": "Chocolate Cake", + "category": "cakes", + "price": 15, + "baked_date": "2023-07-01T00:00:00Z", + "baker": "Baker A" + }, + "fields": { + "baker": [ + "Baker A" + ] + }, + "inner_hits": { + "recent_items": { + "hits": { + "total": { + "value": 2, + "relation": "eq" + }, + "max_score": null, + "hits": [ + { + "_index": "bakery-items", + "_id": "gCW9KJEB3prnZWCKY5wg", + "_score": null, + "_source": { + "item_name": "Chocolate Cake", + "category": "cakes", + "price": 18, + "baked_date": "2023-07-04T00:00:00Z", + "baker": "Baker A" + }, + "sort": [ + 1688428800000 + ] + }, + { + "_index": "bakery-items", + "_id": "fSW9KJEB3prnZWCKY5wg", + "_score": null, + "_source": { + "item_name": "Chocolate Cake", + "category": "cakes", + "price": 15, + "baked_date": "2023-07-01T00:00:00Z", + "baker": "Baker A" + }, + "sort": [ + 1688169600000 + ] + } + ] + } + } + } + }, + { + "_index": "bakery-items", + "_id": "fiW9KJEB3prnZWCKY5wg", + "_score": 0.61310446, + "_source": { + "item_name": "Vanilla Cake", + "category": "cakes", + "price": 12, + "baked_date": "2023-07-02T00:00:00Z", + "baker": "Baker B" + }, + "fields": { + "baker": [ + "Baker B" + ] + }, + "inner_hits": { + "recent_items": { + "hits": { + "total": { + "value": 2, + "relation": "eq" + }, + "max_score": null, + "hits": [ + { + "_index": "bakery-items", + "_id": "gSW9KJEB3prnZWCKY5wg", + "_score": null, + "_source": { + "item_name": "Vanilla Cake", + "category": "cakes", + "price": 14, + "baked_date": "2023-07-05T00:00:00Z", + "baker": "Baker B" + }, + "sort": [ + 1688515200000 + ] + }, + { + "_index": "bakery-items", + "_id": "fiW9KJEB3prnZWCKY5wg", + "_score": null, + "_source": { + "item_name": "Vanilla Cake", + "category": "cakes", + "price": 12, + "baked_date": "2023-07-02T00:00:00Z", + "baker": "Baker B" + }, + "sort": [ + 1688256000000 + ] + } + ] + } + } + } + }, + { + "_index": "bakery-items", + "_id": "fyW9KJEB3prnZWCKY5wg", + "_score": 0.61310446, + "_source": { + "item_name": "Red Velvet Cake", + "category": "cakes", + "price": 20, + "baked_date": "2023-07-03T00:00:00Z", + "baker": "Baker C" + }, + "fields": { + "baker": [ + "Baker C" + ] + }, + "inner_hits": { + "recent_items": { + "hits": { + "total": { + "value": 2, + "relation": "eq" + }, + "max_score": null, + "hits": [ + { + "_index": "bakery-items", + "_id": "giW9KJEB3prnZWCKY5wg", + "_score": null, + "_source": { + "item_name": "Red Velvet Cake", + "category": "cakes", + "price": 22, + "baked_date": "2023-07-06T00:00:00Z", + "baker": "Baker C" + }, + "sort": [ + 1688601600000 + ] + }, + { + "_index": "bakery-items", + "_id": "fyW9KJEB3prnZWCKY5wg", + "_score": null, + "_source": { + "item_name": "Red Velvet Cake", + "category": "cakes", + "price": 20, + "baked_date": "2023-07-03T00:00:00Z", + "baker": "Baker C" + }, + "sort": [ + 1688342400000 + ] + } + ] + } + } + } + } + ] + } +} +``` + +By using collapsing and inner hits effectively, you can manage large datasets in your bakery inventory, reduce redundancy, and focus on the most relevant information. This technique helps streamline search results, providing a clear and concise view of your data. + + + + + + From 3ab36b1f90ef48155eb6b61124ffc8be3ecc5cf1 Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Thu, 15 Aug 2024 16:51:09 +0200 Subject: [PATCH 02/27] Clarifying collapsing of search results Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 61b23949ad..bce625566c 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -6,7 +6,7 @@ nav_order: 3 # Collapse search results -The collapse parameter in OpenSearch enables you to group search results by a particular field value, returning only the top document within each group. This feature is especially beneficial for reducing redundancy and enhancing performance when handling large datasets. By grouping these documents, you can streamline the search results and focus on unique entries, avoiding duplicates. +The collapse parameter in OpenSearch enables you to group search results by a particular field value, returning only the top document within each group. This feature is useful for reducing redundancy in search results by eliminating duplicates. ### Example of collapsing search results @@ -40,7 +40,6 @@ The following query will retrieve the top 5 items per bakery `item_name`, sorted ```json GET /bakery-items/_search -GET /bakery-items/_search { "query": { "match": { From fa3ffbd9150e523536d749b7cc265fe1d966a48b Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Mon, 19 Aug 2024 18:20:07 +0100 Subject: [PATCH 03/27] updating collapsing example as per request Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 384 +++++++++++------------------ 1 file changed, 150 insertions(+), 234 deletions(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index bce625566c..e7b8a79fdc 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -10,59 +10,46 @@ The collapse parameter in OpenSearch enables you to group search results by a pa ### Example of collapsing search results -To collapse search results by the `item` field and sort them by `price`, you can use the following query: +In OpenSearch, the collapse feature requires the field to be either a `keyword` or a `numeric` type. + +To populate our index with the data needed, we will define our index mappings and define an `item` field indexed as a `keyword`. +#### Define the index mappings ```json -GET /bakery-items/_search +PUT /bakery-items { - "query": { - "match": { - "category": "cakes" + "mappings": { + "properties": { + "item": { + "type": "keyword" + }, + "category": { + "type": "keyword" + }, + "price": { + "type": "float" + }, + "baked_date": { + "type": "date" + } } - }, - "collapse": { - "field": "item" - }, - "sort": ["price"], - "from": 0 + } } - ``` -Collapsing only impacts the top hits and does not influence aggregations. The total number of hits in the response represents the count of matching documents before any collapsing is applied. The exact number of unique groups formed by collapsing is not provided. For collapsing to work, the field must be a single-valued `keyword` or `numeric` type with `doc_values` enabled. - -### Expanding collapsed results - -You can expand each collapsed top hit with the `inner_hits` property. - -The following query will retrieve the top 5 items per bakery `item_name`, sorted by `price`. -`` - +#### Populate the index ```json -GET /bakery-items/_search -{ - "query": { - "match": { - "category": "Pastry" - } - }, - "collapse": { - "field": "item_name", - "inner_hits": { - "name": "top_items", - "size": 5, - "sort": [{ "price": "asc" }] - } - }, - "sort": ["price"] -} - +POST /bakery-items/_bulk +{ "index": {} } +{ "item": "Chocolate Cake", "category": "cakes", "price": 15, "baked_date": "2023-07-01T00:00:00Z" } +{ "index": {} } +{ "item": "Chocolate Cake", "category": "cakes", "price": 18, "baked_date": "2023-07-04T00:00:00Z" } +{ "index": {} } +{ "item": "Vanilla Cake", "category": "cakes", "price": 12, "baked_date": "2023-07-02T00:00:00Z" } ``` -### Multiple Inner Hits for Each Collapsed Hit - -To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three least expensive items and the three most recent items for every bakery item. - +#### Search the index, returning all results +##### Uncollapsed Query ```json GET /bakery-items/_search { @@ -71,34 +58,19 @@ GET /bakery-items/_search "category": "cakes" } }, - "collapse": { - "field": "item_name", - "inner_hits": [ - { - "name": "cheapest_items", - "size": 3, - "sort": ["price"] - }, - { - "name": "newest_items", - "size": 3, - "sort": [{ "baked_date": "desc" }] - } - ] - }, "sort": ["price"] } - ``` -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 3 cheapest items and the top 3 most recent items, sorted by the `baked_date` in descending order. -The expansion of the group is done by sending an additional query for each inner hit request for each collapsed hit returned in the response. This can significantly slow down the process if there are too many groups and/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. +##### Uncollapsed result -### Second level of collapsing +The uncollapsed search results example will show all the documents, including both entries for "Chocolate Cake." -Second level of collapsing is also supported and is applied to inner hits. +#### Search the index & collapse results +To collapse search results by the `item` field and sort them by `price`, you can use the following query: +##### Collapsed search query ```json GET /bakery-items/_search { @@ -108,21 +80,17 @@ GET /bakery-items/_search } }, "collapse": { - "field": "baker", - "inner_hits": { - "name": "recent_items", - "size": 3, - "sort": [{ "baked_date": "desc" }] - } - } + "field": "item" + }, + "sort": ["price"] } ``` +##### Collapsed search result -response ```json { - "took": 8, + "took": 3, "timed_out": false, "_shards": { "total": 1, @@ -132,196 +100,144 @@ response }, "hits": { "total": { - "value": 6, + "value": 4, "relation": "eq" }, - "max_score": 0.61310446, + "max_score": null, "hits": [ { "_index": "bakery-items", - "_id": "fSW9KJEB3prnZWCKY5wg", - "_score": 0.61310446, + "_id": "mISga5EB2HLDXHkv9kAr", + "_score": null, "_source": { - "item_name": "Chocolate Cake", - "category": "cakes", - "price": 15, - "baked_date": "2023-07-01T00:00:00Z", - "baker": "Baker A" - }, - "fields": { - "baker": [ - "Baker A" - ] - }, - "inner_hits": { - "recent_items": { - "hits": { - "total": { - "value": 2, - "relation": "eq" - }, - "max_score": null, - "hits": [ - { - "_index": "bakery-items", - "_id": "gCW9KJEB3prnZWCKY5wg", - "_score": null, - "_source": { - "item_name": "Chocolate Cake", - "category": "cakes", - "price": 18, - "baked_date": "2023-07-04T00:00:00Z", - "baker": "Baker A" - }, - "sort": [ - 1688428800000 - ] - }, - { - "_index": "bakery-items", - "_id": "fSW9KJEB3prnZWCKY5wg", - "_score": null, - "_source": { - "item_name": "Chocolate Cake", - "category": "cakes", - "price": 15, - "baked_date": "2023-07-01T00:00:00Z", - "baker": "Baker A" - }, - "sort": [ - 1688169600000 - ] - } - ] - } - } - } - }, - { - "_index": "bakery-items", - "_id": "fiW9KJEB3prnZWCKY5wg", - "_score": 0.61310446, - "_source": { - "item_name": "Vanilla Cake", + "item": "Vanilla Cake", "category": "cakes", "price": 12, "baked_date": "2023-07-02T00:00:00Z", - "baker": "Baker B" + "baker": "Baker A" }, "fields": { - "baker": [ - "Baker B" + "item": [ + "Vanilla Cake" ] }, - "inner_hits": { - "recent_items": { - "hits": { - "total": { - "value": 2, - "relation": "eq" - }, - "max_score": null, - "hits": [ - { - "_index": "bakery-items", - "_id": "gSW9KJEB3prnZWCKY5wg", - "_score": null, - "_source": { - "item_name": "Vanilla Cake", - "category": "cakes", - "price": 14, - "baked_date": "2023-07-05T00:00:00Z", - "baker": "Baker B" - }, - "sort": [ - 1688515200000 - ] - }, - { - "_index": "bakery-items", - "_id": "fiW9KJEB3prnZWCKY5wg", - "_score": null, - "_source": { - "item_name": "Vanilla Cake", - "category": "cakes", - "price": 12, - "baked_date": "2023-07-02T00:00:00Z", - "baker": "Baker B" - }, - "sort": [ - 1688256000000 - ] - } - ] - } - } - } + "sort": [ + 12 + ] }, { "_index": "bakery-items", - "_id": "fyW9KJEB3prnZWCKY5wg", - "_score": 0.61310446, + "_id": "loSga5EB2HLDXHkv9kAr", + "_score": null, "_source": { - "item_name": "Red Velvet Cake", + "item": "Chocolate Cake", "category": "cakes", - "price": 20, - "baked_date": "2023-07-03T00:00:00Z", - "baker": "Baker C" + "price": 15, + "baked_date": "2023-07-01T00:00:00Z", + "baker": "Baker A" }, "fields": { - "baker": [ - "Baker C" + "item": [ + "Chocolate Cake" ] }, - "inner_hits": { - "recent_items": { - "hits": { - "total": { - "value": 2, - "relation": "eq" - }, - "max_score": null, - "hits": [ - { - "_index": "bakery-items", - "_id": "giW9KJEB3prnZWCKY5wg", - "_score": null, - "_source": { - "item_name": "Red Velvet Cake", - "category": "cakes", - "price": 22, - "baked_date": "2023-07-06T00:00:00Z", - "baker": "Baker C" - }, - "sort": [ - 1688601600000 - ] - }, - { - "_index": "bakery-items", - "_id": "fyW9KJEB3prnZWCKY5wg", - "_score": null, - "_source": { - "item_name": "Red Velvet Cake", - "category": "cakes", - "price": 20, - "baked_date": "2023-07-03T00:00:00Z", - "baker": "Baker C" - }, - "sort": [ - 1688342400000 - ] - } - ] - } - } - } + "sort": [ + 15 + ] } ] } } ``` +The collapsed search results example will show only one "Chocolate Cake" entry, demonstrating how collapsing works in reducing redundancy. + +Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. To use collapsing, the field you want to collapse by must be a single-valued `keyword` or `numeric type` with `doc_values` enabled. + + + + + + + + + + + + + + + +### Expanding collapsed results + +You can expand each collapsed top hit with the `inner_hits` property. + +To demonstrate multiple inner hits, we'll retrieve the cheapest and most recent items for each type of cake. + +```json +GET /bakery-items/_search +{ + "query": { + "match": { + "category": "cakes" + } + }, + "collapse": { + "field": "item", + "inner_hits": [ + { + "name": "cheapest_items", + "size": 1, + "sort": ["price"] + }, + { + "name": "newest_items", + "size": 1, + "sort": [{ "baked_date": "desc" }] + } + ] + }, + "sort": ["price"] +} + +``` + +### Multiple Inner Hits for Each Collapsed Hit + +To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three least expensive items and the three most recent items for every bakery item. + +```json +GET /bakery-items/_search +{ + "query": { + "match": { + "category": "cakes" + } + }, + "collapse": { + "field": "item", + "inner_hits": [ + { + "name": "cheapest_items", + "size": 1, + "sort": ["price"] + }, + { + "name": "newest_items", + "size": 3, + "sort": [{ "baked_date": "desc" }] + } + ] + }, + "sort": ["price"] +} + + +``` +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 3 cheapest items and the top 3 most recent items, sorted by the `baked_date` in descending order. + +The expansion of the group is done by sending an additional query for each inner hit request for each collapsed hit returned in the response. This can significantly slow down the process if there are too many groups and/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. + By using collapsing and inner hits effectively, you can manage large datasets in your bakery inventory, reduce redundancy, and focus on the most relevant information. This technique helps streamline search results, providing a clear and concise view of your data. From 84bec0de321d6f052c23206eeec52613a3ec9daf Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Tue, 20 Aug 2024 13:58:33 +0100 Subject: [PATCH 04/27] updates as per reviewdog Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index e7b8a79fdc..cdd30cc0d0 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -8,13 +8,14 @@ nav_order: 3 The collapse parameter in OpenSearch enables you to group search results by a particular field value, returning only the top document within each group. This feature is useful for reducing redundancy in search results by eliminating duplicates. -### Example of collapsing search results +The collapse feature requires the field to to be collapsed to be either a `keyword` or a `numeric` type. -In OpenSearch, the collapse feature requires the field to be either a `keyword` or a `numeric` type. +## Example of collapsing search results To populate our index with the data needed, we will define our index mappings and define an `item` field indexed as a `keyword`. #### Define the index mappings + ```json PUT /bakery-items { @@ -38,6 +39,7 @@ PUT /bakery-items ``` #### Populate the index + ```json POST /bakery-items/_bulk { "index": {} } @@ -49,7 +51,7 @@ POST /bakery-items/_bulk ``` #### Search the index, returning all results -##### Uncollapsed Query + ```json GET /bakery-items/_search { @@ -62,15 +64,14 @@ GET /bakery-items/_search } ``` -##### Uncollapsed result - -The uncollapsed search results example will show all the documents, including both entries for "Chocolate Cake." +The query above will return the uncollapsed search results, showing all the documents, including both entries for "Chocolate Cake." #### Search the index & collapse results To collapse search results by the `item` field and sort them by `price`, you can use the following query: -##### Collapsed search query +**Search query that collapses the results on the item field** + ```json GET /bakery-items/_search { @@ -86,7 +87,7 @@ GET /bakery-items/_search } ``` -##### Collapsed search result +**Results collapsed on item field** ```json { @@ -152,7 +153,7 @@ GET /bakery-items/_search The collapsed search results example will show only one "Chocolate Cake" entry, demonstrating how collapsing works in reducing redundancy. -Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. To use collapsing, the field you want to collapse by must be a single-valued `keyword` or `numeric type` with `doc_values` enabled. +Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. From 18befbbd9d0ccf6ae99e1d599ab691a5d8187cb4 Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Tue, 20 Aug 2024 14:22:13 +0100 Subject: [PATCH 05/27] updates as per review dog Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index cdd30cc0d0..5a9673d361 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -8,7 +8,7 @@ nav_order: 3 The collapse parameter in OpenSearch enables you to group search results by a particular field value, returning only the top document within each group. This feature is useful for reducing redundancy in search results by eliminating duplicates. -The collapse feature requires the field to to be collapsed to be either a `keyword` or a `numeric` type. +The collapse feature requires the field to be collapsed to be either a `keyword` or a `numeric` type. ## Example of collapsing search results @@ -64,9 +64,9 @@ GET /bakery-items/_search } ``` -The query above will return the uncollapsed search results, showing all the documents, including both entries for "Chocolate Cake." +The previous query will return the uncollapsed search results, showing all the documents, including both entries for "Chocolate Cake." -#### Search the index & collapse results +#### Search the index and collapse the results To collapse search results by the `item` field and sort them by `price`, you can use the following query: @@ -153,21 +153,7 @@ GET /bakery-items/_search The collapsed search results example will show only one "Chocolate Cake" entry, demonstrating how collapsing works in reducing redundancy. -Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. - - - - - - - - - - - - - - +Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. ### Expanding collapsed results @@ -203,7 +189,7 @@ GET /bakery-items/_search ``` -### Multiple Inner Hits for Each Collapsed Hit +### Multiple inner hits for each collapsed hit To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three least expensive items and the three most recent items for every bakery item. From a5a1a5a72318808eb06ff66e2794ecb332be0bb8 Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Tue, 20 Aug 2024 14:24:02 +0100 Subject: [PATCH 06/27] remove unneeded space Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 5a9673d361..d9e667f801 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -226,9 +226,3 @@ This query searches for documents in the `cakes` category and groups the search The expansion of the group is done by sending an additional query for each inner hit request for each collapsed hit returned in the response. This can significantly slow down the process if there are too many groups and/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. By using collapsing and inner hits effectively, you can manage large datasets in your bakery inventory, reduce redundancy, and focus on the most relevant information. This technique helps streamline search results, providing a clear and concise view of your data. - - - - - - From d3b6fe6a1fdf88217cf5a146124c7924b258e76a Mon Sep 17 00:00:00 2001 From: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:39:20 +0100 Subject: [PATCH 07/27] Update _search-plugins/collapse-search.md Co-authored-by: Melissa Vagi Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --- _search-plugins/collapse-search.md | 1 - 1 file changed, 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index d9e667f801..ed82c4e210 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -225,4 +225,3 @@ This query searches for documents in the `cakes` category and groups the search The expansion of the group is done by sending an additional query for each inner hit request for each collapsed hit returned in the response. This can significantly slow down the process if there are too many groups and/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. -By using collapsing and inner hits effectively, you can manage large datasets in your bakery inventory, reduce redundancy, and focus on the most relevant information. This technique helps streamline search results, providing a clear and concise view of your data. From bdedb119b43736b496e56d402a4a420cbf5d66a8 Mon Sep 17 00:00:00 2001 From: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:39:33 +0100 Subject: [PATCH 08/27] Update _search-plugins/collapse-search.md Co-authored-by: Melissa Vagi Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index ed82c4e210..2c828ac20c 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -223,5 +223,5 @@ 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 3 cheapest items and the top 3 most recent items, sorted by the `baked_date` in descending order. -The expansion of the group is done by sending an additional query for each inner hit request for each collapsed hit returned in the response. This can significantly slow down the process if there are too many groups and/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. +Expanding the groups is done by sending an additional query for each inner hit request for each collapsed hit returned 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 856b6c6e8aa560000973b54e90bd27a2bdbf9e0f Mon Sep 17 00:00:00 2001 From: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:39:44 +0100 Subject: [PATCH 09/27] Update _search-plugins/collapse-search.md Co-authored-by: Melissa Vagi Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 2c828ac20c..76a0adffab 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -221,7 +221,7 @@ 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 3 cheapest items and the top 3 most recent items, sorted by the `baked_date` in descending order. +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. Expanding the groups is done by sending an additional query for each inner hit request for each collapsed hit returned 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 ad12cd82655084c2861accead6886c963109f5d7 Mon Sep 17 00:00:00 2001 From: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:39:50 +0100 Subject: [PATCH 10/27] Update _search-plugins/collapse-search.md Co-authored-by: Melissa Vagi Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 76a0adffab..fc1cb7e996 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -191,7 +191,7 @@ GET /bakery-items/_search ### Multiple inner hits for each collapsed hit -To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three least expensive items and the three most recent items for every bakery item. +To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three lowest priced items and the three most recent items for every bakery item. ```json GET /bakery-items/_search From 1d1e5ca144bb2e10d1bb6024105477f9454a6fe5 Mon Sep 17 00:00:00 2001 From: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:41:14 +0100 Subject: [PATCH 11/27] Apply suggestions from code review Co-authored-by: Melissa Vagi Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --- _search-plugins/collapse-search.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index fc1cb7e996..7073179a9b 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -6,13 +6,15 @@ nav_order: 3 # Collapse search results -The collapse parameter in OpenSearch enables you to group search results by a particular field value, returning only the top document within each group. This feature is useful for reducing redundancy in search results by eliminating duplicates. +The collapse parameter groups search results by a particular field value. This returns only the top document within each group, which helps reduce redundancy by eliminating duplicates. -The collapse feature requires the field to be collapsed to be either a `keyword` or a `numeric` type. +The collapse feature requires the field being collapsed to be either a `keyword` or a `numeric` type. -## Example of collapsing search results +--- + +## Collapsing search results -To populate our index with the data needed, we will define our index mappings and define an `item` field indexed as a `keyword`. +To populate the index with the data needed, define the index mappings and an `item` field indexed as a `keyword`. The following example requests shows how to define index mappings, populate the index, and then search it: #### Define the index mappings @@ -64,13 +66,13 @@ GET /bakery-items/_search } ``` -The previous query will return the uncollapsed search results, showing all the documents, including both entries for "Chocolate Cake." +This query returns the uncollapsed search results, showing all the documents, including both entries for "Chocolate Cake." #### Search the index and collapse the results To collapse search results by the `item` field and sort them by `price`, you can use the following query: -**Search query that collapses the results on the item field** +**Collapsed search results on item field** ```json GET /bakery-items/_search @@ -87,7 +89,7 @@ GET /bakery-items/_search } ``` -**Results collapsed on item field** +**Response** ```json { @@ -155,11 +157,13 @@ The collapsed search results example will show only one "Chocolate Cake" entry, Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. -### Expanding collapsed results +--- + +## Expanding collapsed results You can expand each collapsed top hit with the `inner_hits` property. -To demonstrate multiple inner hits, we'll retrieve the cheapest and most recent items for each type of cake. +The following example request applies `inner_hits` to retrieve the lowest priced and most recent items for each type of cake. ```json GET /bakery-items/_search From 9942b78b9422db92e695129014c3e1424de087dd Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:24:59 -0600 Subject: [PATCH 12/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 7073179a9b..d0213fe58e 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -227,5 +227,5 @@ 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. -Expanding the groups is done by sending an additional query for each inner hit request for each collapsed hit returned 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. +You can expand the groups by sending an additional query for each inner hit request for each collapsed hit returned 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 587e3b6f42c55f290579b6c574dde637ede912d7 Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:25:28 -0600 Subject: [PATCH 13/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index d0213fe58e..8b9adeedc0 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -225,7 +225,7 @@ 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. +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 for each collapsed hit returned 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 6d1cc8f780567cdcdc328d3d5e6d40c3039635f0 Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:25:41 -0600 Subject: [PATCH 14/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 8b9adeedc0..911bf19e27 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -6,7 +6,7 @@ nav_order: 3 # Collapse search results -The collapse parameter groups search results by a particular field value. This returns only the top document within each group, which helps reduce redundancy by eliminating duplicates. +The `collapse` parameter groups search results by a particular field value. This returns only the top document within each group, which helps reduce redundancy by eliminating duplicates. The collapse feature requires the field being collapsed to be either a `keyword` or a `numeric` type. From df623307b655780a8b5b90014e07d363cc9bb19a Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:25:48 -0600 Subject: [PATCH 15/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 911bf19e27..293c9c9b7e 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -8,7 +8,7 @@ nav_order: 3 The `collapse` parameter groups search results by a particular field value. This returns only the top document within each group, which helps reduce redundancy by eliminating duplicates. -The collapse feature requires the field being collapsed to be either a `keyword` or a `numeric` type. +The `collapse` parameter requires the field being collapsed to be of either a `keyword` or a `numeric` type. --- From 9544dcddbe444ed7c1829a7c281451ef45b69a86 Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:26:06 -0600 Subject: [PATCH 16/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 293c9c9b7e..8412b1fb81 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -14,7 +14,7 @@ The `collapse` parameter requires the field being collapsed to be of either a `k ## Collapsing search results -To populate the index with the data needed, define the index mappings and an `item` field indexed as a `keyword`. The following example requests shows how to define index mappings, populate the index, and then search it: +To populate an index with data, define the index mappings and an `item` field indexed as a `keyword`. The following example request shows you how to define index mappings, populate an index, and then search it. #### Define the index mappings From c74e3508947b82259ae32ee7b9c127cf65bf67d7 Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:26:13 -0600 Subject: [PATCH 17/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 8412b1fb81..6b61352b5f 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -16,7 +16,7 @@ The `collapse` parameter requires the field being collapsed to be of either a `k To populate an index with data, define the index mappings and an `item` field indexed as a `keyword`. The following example request shows you how to define index mappings, populate an index, and then search it. -#### Define the index mappings +#### Define index mappings ```json PUT /bakery-items From 80c8b03825c79ff978aa417419eef4f54f186d4e Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:26:22 -0600 Subject: [PATCH 18/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 6b61352b5f..a8652b652e 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -40,7 +40,7 @@ PUT /bakery-items } ``` -#### Populate the index +#### Populate an index ```json POST /bakery-items/_bulk From 38a6cd8e9109ae8205b54a4de845700e63c5dabe Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:26:38 -0600 Subject: [PATCH 19/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index a8652b652e..a03318a70d 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -66,7 +66,7 @@ GET /bakery-items/_search } ``` -This query returns the uncollapsed search results, showing all the documents, including both entries for "Chocolate Cake." +This query returns the uncollapsed search results, showing all documents, including both entries for "Chocolate Cake". #### Search the index and collapse the results From c8cac89d96170850084c62861b1806de93fa3a4d Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:27:09 -0600 Subject: [PATCH 20/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index a03318a70d..d642f6c6c5 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -153,7 +153,7 @@ GET /bakery-items/_search } ``` -The collapsed search results example will show only one "Chocolate Cake" entry, demonstrating how collapsing works in reducing redundancy. +The collapsed search results will show only one "Chocolate Cake" entry, demonstrating how the `collapse` parameter reduces redundancy. Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. From 0c68494941d6d62f78c873374266cb8b4036ca17 Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:27:25 -0600 Subject: [PATCH 21/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index d642f6c6c5..9fb44200a7 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -155,7 +155,7 @@ GET /bakery-items/_search The collapsed search results will show only one "Chocolate Cake" entry, demonstrating how the `collapse` parameter reduces redundancy. -Collapsing affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before collapsing is applied, including duplicates. However, the response doesn't tell you the exact number of unique groups formed by collapsing. +The `collapse` parameter affects only the top search results and does not change any aggregation results. The total number of hits shown in the response reflects all matching documents before the parameter is applied, including duplicates. However, the response doesn't indicate the exact number of unique groups formed by the operation. --- From 3df37b89e261585a65a028c3ed962413bb13bc13 Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:27:37 -0600 Subject: [PATCH 22/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 9fb44200a7..542774c0d1 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -163,7 +163,7 @@ The `collapse` parameter affects only the top search results and does not change You can expand each collapsed top hit with the `inner_hits` property. -The following example request applies `inner_hits` to retrieve the lowest priced and most recent items for each type of cake. +The following example request applies `inner_hits` to retrieve the lowest-priced and most recent items for each type of cake: ```json GET /bakery-items/_search From 535f77a00741fb4936f970f9dc0bc5a6e2ef35ab Mon Sep 17 00:00:00 2001 From: Melissa Vagi Date: Thu, 12 Sep 2024 14:27:45 -0600 Subject: [PATCH 23/27] Update _search-plugins/collapse-search.md Co-authored-by: Nathan Bower Signed-off-by: Melissa Vagi --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 542774c0d1..534ee9bac1 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -195,7 +195,7 @@ GET /bakery-items/_search ### Multiple inner hits for each collapsed hit -To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three lowest priced items and the three most recent items for every bakery item. +To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three lowest-priced items and the three most recent items for every bakery item: ```json GET /bakery-items/_search From b606e21c94d1a72d4f98d4f44a9236a0df7bff35 Mon Sep 17 00:00:00 2001 From: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:54:43 +0100 Subject: [PATCH 24/27] Update _search-plugins/collapse-search.md Co-authored-by: Melissa Vagi Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 534ee9bac1..ea26ef580f 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -195,7 +195,7 @@ GET /bakery-items/_search ### Multiple inner hits for each collapsed hit -To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three lowest-priced items and the three most recent items for every bakery item: +To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three lowest-priced items and the three most recent items: ```json GET /bakery-items/_search From 5dbb1c6e439ff4b469ca7ace5e4aad9cb45437cd Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Tue, 17 Sep 2024 15:54:33 +0100 Subject: [PATCH 25/27] Review suggestions addressed Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index ea26ef580f..d02f08555b 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -163,7 +163,7 @@ The `collapse` parameter affects only the top search results and does not change You can expand each collapsed top hit with the `inner_hits` property. -The following example request applies `inner_hits` to retrieve the lowest-priced and most recent items for each type of cake: +The following example request applies `inner_hits` to retrieve the lowest-priced and most recent item, for each type of cake: ```json GET /bakery-items/_search @@ -195,7 +195,7 @@ GET /bakery-items/_search ### Multiple inner hits for each collapsed hit -To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, you could request the three lowest-priced items and the three most recent items: +To obtain several groups of inner hits for each collapsed result, you can set different criteria for each group. For example, lets request the three most recent items for every bakery item: ```json GET /bakery-items/_search @@ -227,5 +227,5 @@ 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 for each collapsed hit returned 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. +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 5535fcf07317f7ec167ed0a1d8379281e1f55a8e Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Tue, 17 Sep 2024 15:59:40 +0100 Subject: [PATCH 26/27] update to language Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index d02f08555b..5d1826fc9c 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -70,7 +70,7 @@ This query returns the uncollapsed search results, showing all documents, includ #### Search the index and collapse the results -To collapse search results by the `item` field and sort them by `price`, you can use the following query: +To group search results by the `item` field and sort them by `price`, you can use the following query: **Collapsed search results on item field** From 4e6c7121052a97a1bf8707921fb8a6b1b479d2f7 Mon Sep 17 00:00:00 2001 From: "leanne.laceybyrne@eliatra.com" Date: Tue, 17 Sep 2024 16:01:22 +0100 Subject: [PATCH 27/27] update to language from review Signed-off-by: leanne.laceybyrne@eliatra.com --- _search-plugins/collapse-search.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_search-plugins/collapse-search.md b/_search-plugins/collapse-search.md index 5d1826fc9c..ec7e57515a 100644 --- a/_search-plugins/collapse-search.md +++ b/_search-plugins/collapse-search.md @@ -72,7 +72,7 @@ This query returns the uncollapsed search results, showing all documents, includ To group search results by the `item` field and sort them by `price`, you can use the following query: -**Collapsed search results on item field** +**Collapsed `item` field search results** ```json GET /bakery-items/_search