Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Melissa Vagi <[email protected]>
Signed-off-by: leanneeliatra <[email protected]>
  • Loading branch information
leanneeliatra and vagimeli authored Aug 30, 2024
1 parent ad12cd8 commit 1d1e5ca
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions _search-plugins/collapse-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."

Check failure on line 69 in _search-plugins/collapse-search.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: uncollapsed. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: uncollapsed. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_search-plugins/collapse-search.md", "range": {"start": {"line": 69, "column": 24}}}, "severity": "ERROR"}

#### 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
Expand All @@ -87,7 +89,7 @@ GET /bakery-items/_search
}
```

**Results collapsed on item field**
**Response**

```json
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1d1e5ca

Please sign in to comment.