Skip to content

Commit

Permalink
Add --with-missing to es-search.pl
Browse files Browse the repository at this point in the history
If specified, all terms aggregations will calculate the missing element
as 'MISSING'.
  • Loading branch information
reyjrar committed Sep 1, 2021
1 parent dc6735a commit 963498b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions scripts/es-search.pl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
top=s
interval=s
with=s@
with-missing
or
));

Expand Down Expand Up @@ -246,10 +247,13 @@
# Skip invalid elements
next unless defined $field and defined $size and $size > 0;

my %params = ();
my $id = "$type-$field";
# If a term agg and we haven't used this field name, simplify it
if( $type =~ /terms$/ && !$sub_agg{$field} ) {
$id = $field;
$params{size} = $size;
$params{missing} = 'MISSING' if $OPT{'with-missing'};
}

if( $type =~ /histogram|stats|percentiles/ && !$OPT{'no-implications'} ) {
Expand All @@ -260,17 +264,20 @@
$sub_agg{$id} = {
$type => {
field => $field,
$type =~ /terms/ ? (size => $size) : (),
$type eq 'percentiles' ? ( percents => [split /,/, $pcts] ) : (),
$type eq 'histogram' ? ( interval => $hi ) : (),
%params,
}
};
}
}

my %params = ();
$params{missing} = 'MISSING' if $OPT{'with-missing'} and $top_agg eq 'terms';

my $field = shift @agg_fields;
$agg_header = "count\tpct\t" . $field;
$agg{$top_agg} = { field => $field };
$agg{$top_agg} = { field => $field, %params };

if( $OPT{'bg-filter'} && $top_agg eq 'significant_terms' ) {
my $bgf = App::ElasticSearch::Utilities::QueryString->new();
Expand Down Expand Up @@ -921,6 +928,10 @@ =head1 OPTIONS
--with percentiles:out_bytes:50,95,99
--with histogram:out_bytes:1024
=item B<with-missing>
For terms aggregations, adds a C<MISSING> bucket.
=item B<bg-filter>
Only used if the C<--top> aggregation is C<significant_terms>. Sets the
Expand Down

0 comments on commit 963498b

Please sign in to comment.