Skip to content

New Pull Request #2

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 68 additions & 16 deletions _aggregations/bucket/index.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
---
layout: default
title: Bucket aggregations
has_children: true
has_toc: false
nav_order: 3
redirect_from:
- /opensearch/bucket-agg/
- /query-dsl/aggregations/bucket-agg/
- /query-dsl/aggregations/bucket/
- /aggregations/bucket-agg/
---

# Bucket aggregations

Bucket aggregations categorize sets of documents as buckets. The type of bucket aggregation determines the bucket for a given document.
Bucket aggregations categorize sets of documents into buckets. The type of bucket aggregation determines the bucket for a given document.

You can use bucket aggregations to implement faceted navigation (usually placed as a sidebar on a search result landing page) to help your users filter the results.

Expand All @@ -22,7 +9,8 @@ You can use bucket aggregations to implement faceted navigation (usually placed
OpenSearch supports the following bucket aggregations:

- [Adjacency matrix]({{site.url}}{{site.baseurl}}/aggregations/bucket/adjacency-matrix/)
- [Children]({{site.url}}{{site.baseurl}}/aggregations/bucket/children)
- [Auto-interval date histogram]({{site.url}}{{site.baseurl}}/aggregations/bucket/auto-interval-date-histogram/)
- [Children]({{site.url}}{{site.baseurl}}/aggregations/bucket/children/)
- [Date histogram]({{site.url}}{{site.baseurl}}/aggregations/bucket/date-histogram/)
- [Date range]({{site.url}}{{site.baseurl}}/aggregations/bucket/date-range/)
- [Diversified sampler]({{site.url}}{{site.baseurl}}/aggregations/bucket/diversified-sampler/)
Expand All @@ -43,4 +31,68 @@ OpenSearch supports the following bucket aggregations:
- [Sampler]({{site.url}}{{site.baseurl}}/aggregations/bucket/sampler/)
- [Significant terms]({{site.url}}{{site.baseurl}}/aggregations/bucket/significant-terms/)
- [Significant text]({{site.url}}{{site.baseurl}}/aggregations/bucket/significant-text/)
- [Terms]({{site.url}}{{site.baseurl}}/aggregations/bucket/terms/)
- [Terms]({{site.url}}{{site.baseurl}}/aggregations/bucket/terms/)

## Usage

To use a bucket aggregation, specify it in the `aggs` section of your search request:

```json
GET _search
{
"aggs": {
"my_bucket_agg": {
"BUCKET_TYPE": {
...
}
}
}
}
```

Replace `BUCKET_TYPE` with the type of bucket aggregation you want to use.

## Common parameters

Most bucket aggregations support the following common parameters:

- `field`: The field to aggregate on
- `script`: A script to generate values to aggregate on
- `missing`: A value to use for documents that are missing the field

## Nesting aggregations

You can nest bucket aggregations within other bucket aggregations to create more complex aggregations. For example:

```json
GET _search
{
"aggs": {
"my_date_histo": {
"date_histogram": {
"field": "date",
"interval": "month"
},
"aggs": {
"my_terms": {
"terms": {
"field": "category"
}
}
}
}
}
}
```

This creates date histogram buckets and then subdivides those buckets using a terms aggregation.

## Performance considerations

Bucket aggregations can be computationally expensive, especially on large datasets. To improve performance:

- Use filters to reduce the number of documents before aggregating
- Set a reasonable `size` parameter to limit the number of buckets returned
- Consider using sampling aggregations like `sampler` for approximate results on very large datasets

For more details on each bucket aggregation type, refer to the individual documentation pages linked above.
92 changes: 92 additions & 0 deletions _aggregations/bucket/reroute-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# RerouteService

The `RerouteService` interface allows you to asynchronously perform cluster reroute operations in OpenSearch.

## Overview

The `RerouteService` provides methods to:

- Schedule cluster reroute operations
- Update shard states
- Rebalance the cluster if appropriate

Reroute operations can be triggered with different priority levels to control when they are executed relative to other cluster state update tasks.

## Usage

To use the `RerouteService`, inject it as a dependency:

```java
public class MyClass {

private final RerouteService rerouteService;

@Inject
public MyClass(RerouteService rerouteService) {
this.rerouteService = rerouteService;
}

// Use rerouteService...
}
```

## Methods

### reroute

```java
void reroute(String reason, Priority priority, ActionListener<ClusterState> listener)
```

Schedules a cluster reroute operation.

Parameters:
- `reason` - A string describing the reason for the reroute
- `priority` - The priority level for this reroute operation
- `listener` - An `ActionListener` to be notified when the reroute completes

The priority determines when this reroute will be executed relative to other cluster state update tasks. If there is already a pending reroute at a higher priority, this reroute will be batched with it. If there is a pending reroute at a lower priority, its priority will be raised to match this one.

### newFunctionality

```java
void newFunctionality()
```

This method provides new functionality added to the `RerouteService` interface. The specific behavior is not yet documented.

## Priority Levels

The `Priority` enum defines the available priority levels for reroute operations:

- `IMMEDIATE` - Highest priority, executed as soon as possible
- `HIGH` - High priority
- `NORMAL` - Normal priority
- `LOW` - Low priority
- `LANGUID` - Lowest priority

Higher priority operations will be executed before lower priority ones.

## Examples

Scheduling a normal priority reroute:

```java
rerouteService.reroute("Rebalance cluster", Priority.NORMAL, new ActionListener<ClusterState>() {
@Override
public void onResponse(ClusterState clusterState) {
// Handle successful reroute
}

@Override
public void onFailure(Exception e) {
// Handle reroute failure
}
});
```

## Best Practices

- Use an appropriate priority level based on the urgency of the reroute
- Provide descriptive reason strings to aid debugging
- Handle both success and failure cases in the listener