App::ElasticSearch::Utilities::Aggregations - Code to simplify creating and working with Elasticsearch aggregations
version 8.2
Returns true if an aggregation returns a single value.
Takes a simplified aggregation grammar and expands it the full aggregation hash.
Simple Terms:
field_name
To
{ field_name => { terms => { field => 'field_name', size => 20, } } }
Alias expansion:
alias=field_name
{ alias => { terms => { field => 'field_name', size => 20, } } }
Parameters:
alias=field_name:10
{ alias => { terms => { field => 'field_name', size => 10, } } }
Parameters, k/v:
alias=field_name:size=13
{ alias => { terms => { field => 'field_name', size => 13, } } }
Takes the aggregations section of the query result and parses it into a flat structure so each row contains all the sub aggregation information.
It returns an array reference, containing arrray references. The individual rows of the array are ordered in a depth first fashion. The array does include a key for every value, so the array can be cast to a hash safely.
List of supported aggregations. Other aggregation may work, but these have defined behavior.
These aggregations will support sub aggregations.
The default aggregation if none is specified.
field_name terms:field_name
Results in
{ "field_name": { "terms": { "field": "field_name" } } }
Supports a positional parameter: size
field_name:20 terms:field_name:20
{ "field_name": { "terms": { "field": "field_name", "size": 20 } } }
Same as terms.
terms
significant_terms:field_name:10
Results in:
{ "rare_terms.field_name": { "terms": { "field": "field_name", "size": 10 } } }
Same as terms but the positional parameter is the max_doc_count.
max_doc_count
rare_terms:field_name:10
{ "rare_terms.field_name": { "terms": { "field": "field_name", "max_doc_count": 10 } } }
Creates a histogram for numeric fields. Positional parameter is the interval.
histogram:field_name:10
{ "histogram.field_name": { "histogram": { "field": "field_name", "interval": 10 } } }
Creates a histogram for date fields. Positional parameter is the calendar_interval.
date_histogram:field_name:1h
{ "histogram.field_name": { "histogram": { "field": "field_name", "calendar_interval": "1h" } } }
Creates a geohash grid bucket aggregation. Positional parameter is the precision.
geohash_grid:field_name:6
{ "geohash_grid.field_name": { "geohash_grid": { "field": "field_name", "precision": 6 } } }
Creates a bucket for documents missing the field. No positional parameters.
missing:field_name
{ "missing.field_name": { "missing": { "field": "field_name" } } }
Aggregations that generate metrics from enclosing buckets.
Single stat metric aggregations to generate the various single statistics over the enclosing bucket.
sum:field_name
{ "sum.field_names": { "sum": { "field": "field_name" } } }
Computes the unique count of terms in a field.
cardinality:field_name
{ "cardinality.field_names": { "cardinality": { "field": "field_name" } } }
Runs the stats aggregation that returns min, max, avg, sum, and count.
stats:field_name
{ "stats.field_names": { "stats": { "field": "field_name" } } }
Runs the stats aggregation that returns the same data as the sum aggregation plus variance, sum of squares, and standard deviation.
sum
extended_stats:field_name
{ "extended_stats.field_names": { "extended_stats": { "field": "field_name" } } }
Computes percentiles for the enclosing bucket. The positional parameter is interpretted at the percents computed. If ommitted, the percentiles computed will be: 25, 50, 75, 90.
percentiles:field_name:75,95,99
{ "percentiles.field_names": { "percentiles": { "field": "field_name", "percents": [ 75, 95, 99 ] } } }
Computes center of a group of geo points. No positional parameters supported.
geo_centroid:field_name
{ "geo_centroid.field_names": { "geo_centroid": { "field": "field_name" } } }
Brad Lhotsky <brad@divisionbyzero.net>
This software is Copyright (c) 2021 by Brad Lhotsky.
This is free software, licensed under:
The (three-clause) BSD License
To install App::ElasticSearch::Utilities, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::ElasticSearch::Utilities
CPAN shell
perl -MCPAN -e shell install App::ElasticSearch::Utilities
For more information on module installation, please visit the detailed CPAN module installation guide.