Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add composite aggregation documentation #7666

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
79 changes: 79 additions & 0 deletions _aggregations/bucket/composite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
layout: default
title: Composite
parent: Bucket aggregations
grand_parent: Aggregations
nav_order: 20
has_children: true
---

# Composite

The `composite` aggregation is a multi-bucket aggregation that creates composite buckets from different sources. It is useful for efficiently paginating multi-level aggregations and retrieving all buckets. Composite buckets are built from combinations of values extracted from documents for each specified source field.

## Syntax
Copy link
Contributor Author

@vagimeli vagimeli Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical reviewer: Please review this content and confirm the syntax and examples are accurate and relevant to an OpenSearch user. I tested the examples using Dev Tools. If another example is more appropriate, please replace the draft example with your example. Thank you.


```json
{
"composite": {
"sources": [
{
"source_field_1": {
"terms": {
"field": "field_name"
}
}
},
{
"source_field_2": {
"terms": {
"field": "another_field_name"
}
}
}
]
}
}
```
{% include copy-curl.html %}

Property | Description |
---------|------------|
`composite` | The aggregation type.
`sources ` | An array of source objects, where each object defines a source field for the composite buckets.
`terms` | The subaggregation type used to extract the values from the specified field for each source.
`field` | The field name in your documents from which the values will be extracted for the corresponding source.

For example, consider the following document:

```json
{
"product": "T-Shirt",
"category": "Clothing",
"brand": "Acme",
"price": 19.99,
"sizes": ["S", "M", "L"],
"colors": ["red", "blue"]
}
```
{% include copy-curl.html %}

Using `sizes` and `colors` as source fields for the aggregation results in the following composite buckets:

```json
{ "sizes": "S", "colors": "red" }
{ "sizes": "S", "colors": "blue" }
{ "sizes": "M", "colors": "red" }
{ "sizes": "M", "colors": "blue" }
{ "sizes": "L", "colors": "red" }
{ "sizes": "L", "colors": "blue" }
```
{% include copy-curl.html %}

## Compatibility and limitations

<SME: What version of OpenSearch is this compatible with? What are the limitations?>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical reviewer: Please provide information about compatibility and limitations.


## Performance considerations
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical reviewer: Please provide information about performance considerations, if any.


<What are the performance implications or best practices for using this aggregation?>
Loading
Loading