OpenSearch/docs/reference/aggregations/bucket
Jim Ferenczi 623367d793
Add composite aggregator (#26800)
* This change adds a module called `aggs-composite` that defines a new aggregation named `composite`.
The `composite` aggregation is a multi-buckets aggregation that creates composite buckets made of multiple sources.
The sources for each bucket can be defined as:
  * A `terms` source, values are extracted from a field or a script.
  * A `date_histogram` source, values are extracted from a date field and rounded to the provided interval.
This aggregation can be used to retrieve all buckets of a deeply nested aggregation by flattening the nested aggregation in composite buckets.
A composite buckets is composed of one value per source and is built for each document as the combinations of values in the provided sources.
For instance the following aggregation:

````
"test_agg": {
  "terms": {
    "field": "field1"
  },
  "aggs": {
    "nested_test_agg":
      "terms": {
        "field": "field2"
      }
  }
}
````
... which retrieves the top N terms for `field1` and for each top term in `field1` the top N terms for `field2`, can be replaced by a `composite` aggregation in order to retrieve **all** the combinations of `field1`, `field2` in the matching documents:

````
"composite_agg": {
  "composite": {
    "sources": [
      {
	"field1": {
          "terms": {
              "field": "field1"
            }
        }
      },
      {
	"field2": {
          "terms": {
            "field": "field2"
          }
        }
      },
    }
  }
````

The response of the aggregation looks like this:

````
"aggregations": {
  "composite_agg": {
    "buckets": [
      {
        "key": {
          "field1": "alabama",
          "field2": "almanach"
        },
        "doc_count": 100
      },
      {
        "key": {
          "field1": "alabama",
          "field2": "calendar"
        },
        "doc_count": 1
      },
      {
        "key": {
          "field1": "arizona",
          "field2": "calendar"
        },
        "doc_count": 1
      }
    ]
  }
}
````

By default this aggregation returns 10 buckets sorted in ascending order of the composite key.
Pagination can be achieved by providing `after` values, the values of the composite key to aggregate after.
For instance the following aggregation will aggregate all composite keys that sorts after `arizona, calendar`:

````
"composite_agg": {
  "composite": {
    "after": {"field1": "alabama", "field2": "calendar"},
    "size": 100,
    "sources": [
      {
	"field1": {
          "terms": {
            "field": "field1"
          }
        }
      },
      {
	"field2": {
          "terms": {
            "field": "field2"
          }
	}
      }
    }
  }
````

This aggregation is optimized for indices that set an index sorting that match the composite source definition.
For instance the aggregation above could run faster on indices that defines an index sorting like this:

````
"settings": {
  "index.sort.field": ["field1", "field2"]
}
````

In this case the `composite` aggregation can early terminate on each segment.
This aggregation also accepts multi-valued field but disables early termination for these fields even if index sorting matches the sources definition.
This is mandatory because index sorting picks only one value per document to perform the sort.
2017-11-16 15:13:36 +01:00
..
adjacency-matrix-aggregation.asciidoc Update experimental labels in the docs (#25727) 2017-07-18 14:06:22 +02:00
children-aggregation.asciidoc Add a shard filter search phase to pre-filter shards based on query rewriting (#25658) 2017-07-12 22:19:20 +02:00
composite-aggregation.asciidoc Add composite aggregator (#26800) 2017-11-16 15:13:36 +01:00
datehistogram-aggregation.asciidoc fixing typo in datehistogram-aggregation.asciidoc (#26924) 2017-10-08 15:12:43 +02:00
daterange-aggregation.asciidoc Update aggs reference documentation for 'keyed' options (#23758) 2017-04-18 15:57:50 +02:00
diversified-sampler-aggregation.asciidoc Enforce that responses in docs are valid json (#26249) 2017-08-17 09:02:10 -04:00
filter-aggregation.asciidoc Update filter-aggregation.asciidoc (#24138) 2017-04-17 18:46:13 -04:00
filters-aggregation.asciidoc Fix `other_bucket` on the `filters` agg to be enabled if a key is set. (#21994) 2016-12-09 09:48:48 +01:00
geodistance-aggregation.asciidoc Update aggs reference documentation for 'keyed' options (#23758) 2017-04-18 15:57:50 +02:00
geohashgrid-aggregation.asciidoc Support distance units in GeoHashGrid aggregation precision (#26291) 2017-08-21 17:29:28 +02:00
global-aggregation.asciidoc CONSOLE-ify global-aggregation.asciidoc 2017-01-20 14:36:51 -05:00
histogram-aggregation.asciidoc Compound order for histogram aggregations. (#22343) 2017-05-11 18:06:26 +01:00
iprange-aggregation.asciidoc CONSOLEify ip-range bucket agg docs 2017-08-03 17:19:54 -04:00
missing-aggregation.asciidoc CONSOLEify some more aggregation docs 2017-05-16 17:25:24 -04:00
nested-aggregation.asciidoc fixing typo in nested-aggregation.asciidoc (#26481) 2017-09-04 06:42:44 +02:00
range-aggregation.asciidoc [Docs] Convert remaining code snippets in docs (#26422) 2017-08-30 12:11:10 +02:00
reverse-nested-aggregation.asciidoc [Docs] Convert remaining code snippets in docs (#26422) 2017-08-30 12:11:10 +02:00
sampler-aggregation.asciidoc Update experimental labels in the docs (#25727) 2017-07-18 14:06:22 +02:00
significantterms-aggregation.asciidoc [Docs] Convert remaining code snippets in docs (#26422) 2017-08-30 12:11:10 +02:00
significanttext-aggregation.asciidoc SignificantText aggregation - like significant_terms, but for text (#24432) 2017-05-24 13:46:43 +01:00
terms-aggregation.asciidoc [Docs] Convert remaining code snippets in docs (#26422) 2017-08-30 12:11:10 +02:00