Elasticsearch Aggregation - elasticsearch - elasticsearch tutorial - elastic search
Elasticsearch Aggregation
- The aggregations framework helps provide aggregated data based on a search query.
- It is based on simple building blocks called aggregations, that can be composed in order to build complex summaries of the data.
- An aggregation can be seen as a unit-of-work that builds analytic information over a set of documents.
- The context of the execution defines what this document set is (e.g. a top-level aggregation executes within the context of the executed query/filters of the search request).
learn elasticsearch tutorials - aggregation Example
- There are many different types of aggregations, each with its own purpose and output. To better understand these types, it is often easier to break them into four main families:
Metrics Aggregations:
- These aggregations help in computing matrices from the field’s values of the aggregated documents and sometime some values can be generated from scripts.
- Numeric matrices are either single-valued like average aggregation or multi-valued like stats.
learn elasticsearch tutorials - search results aggregation Example
Avg Aggregation:
- This aggregation is used to get the average of any numeric field present in the aggregated documents. For example,
Request Body:
Response:
- If the value is not present in one or more aggregated documents, it gets ignored by default. You can add a missing field in the aggregation for treating missing value as default.
Cardinality Aggregation:
- This aggregation gives the count of distinct values of a particular field. For example,
Request Body:
Response:
- Note − The value of cardinality is 3 because there are three distinct values in name — Government, School and Model.
Extended Stats Aggregation:
- This aggregation generates all the statistics about a specific numerical field in aggregated documents. For example,
Request Body:
Response:
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node
Max Aggregation:
- This aggregation finds the max value of a specific numeric field in aggregated documents. For example,
Request Body:
Response:
Min Aggregation:
- This aggregation finds the max value of a specific numeric field in aggregated documents. For example,
Request Body:
Response:
Sum Aggregation:
- This aggregation calculates the sum of a specific numeric field in aggregated documents. For example,
Request Body:
Response:
- There are some other metrics aggregations which are used in special cases like geo bounds aggregation and geo centroid aggregation for the purpose of geo location.
Bucket Aggregations:
- These aggregations contain many buckets for different types of aggregations having a criterion, which determines whether a document belongs to that bucket or not. The bucket aggregations have been described below −
Children Aggregation:
- This bucket aggregation makes a collection of documents, which are mapped to parent bucket. A type parameter is used to define the parent index. For example, we have a brand and its different models, and then the model type will have the following _parent field −
- There are many other special bucket aggregations, which are useful in many other cases, those are −
- Date Histogram Aggregation
- Date Range Aggregation
- Filter Aggregation
- Filters Aggregation
- Geo Distance Aggregation
- GeoHash grid Aggregation
- Global Aggregation
- Histogram Aggregation
- IPv4 Range Aggregation
- Missing Aggregation
- Nested Aggregation
- Range Aggregation
- Reverse nested Aggregation
- Sampler Aggregation
- Significant Terms Aggregation
- Terms Aggregation
Aggregation Metadata:
- You can add some data about the aggregation at the time of request by using meta tag and can get that in response. For example,