App-ElasticSearch-Utilities

 view release on metacpan or  search on metacpan

scripts/es-search.pl  view on Meta::CPAN

#!perl
# PODNAME: es-search.pl
# ABSTRACT: Provides a CLI for quick searches of data in ElasticSearch daily indexes
use strict;
use warnings;

use App::ElasticSearch::Utilities qw(:all);
use App::ElasticSearch::Utilities::Query;
use App::ElasticSearch::Utilities::QueryString;
use Carp;
use CLI::Helpers qw(:all);
use Getopt::Long qw(:config no_ignore_case no_ignore_case_always);
use JSON::MaybeXS qw(:legacy);
use Pod::Usage;
use POSIX qw(strftime);
use Ref::Util qw(is_ref is_arrayref is_hashref);
use Time::HiRes qw(sleep time);
use YAML::XS;
local $YAML::XS::Boolean = "JSON::PP";

#------------------------------------------------------------------------#
# Argument Parsing
my %OPT;
GetOptions(\%OPT, qw(
    all
    asc
    bases
    bg-filter=s
    by=s
    desc
    exists=s@
    fields
    filter
    format=s
    help|h
    json|jq
    manual|m
    match-all
    max-batch-size=i
    missing=s@
    no-decorators|no-header
    no-implications|no-imply
    precision=i
    prefix=s@
    pretty
    show=s@
    size|n|limit=i
    sort=s
    tail
    timestamp=s
    top=s
    interval=s
    with=s@
    with-missing
    or
));

# Search string is the rest of the argument string
my $context = $OPT{filter} ? 'filter' : 'must';
my $qs = App::ElasticSearch::Utilities::QueryString->new(
            $OPT{filter} ?  (context => 'filter') : (),
            default_join => $OPT{or} ? 'OR' : 'AND',
);
my $q = exists $OPT{'match-all'} && $OPT{'match-all'}
            ? App::ElasticSearch::Utilities::Query->new($context => { match_all => {} })
            : $qs->expand_query_string(@ARGV);

$q->set_timeout('10s');
$q->set_scroll('30s');

if( exists $OPT{prefix} ){
    foreach my $prefix (@{ $OPT{prefix} }) {
        my ($f,$v) = split /:/, $prefix, 2;
        next unless $f && $v;
        $q->add_bool( $context => { prefix => { $f => $v } } );
    }

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.368 second using v1.00-cache-2.02-grep-82fe00e-cpan-48ebf85a1963 )