Perl Search::Elasticsearch - result object handling


(Simon Taylor) #1

Writing my first perl script to handle results from ES using the awesome perl api into ES.

The result objects for searches need handling to process them - is their a convenience function for obtaining a field from a each row in a resultset? Strikes me someone would have done this already!


(ankur) #2

You should look at elasticsearch scroll.

use Elasticsearch;
use Elasticsearch::Scroll;

my $es = Elasticsearch->new( nodes => '127.0.0.1:9200' );
my $s = Elasticsearch::Scroll->new(
es => $es,
index => 'myindex',
type => 'mytype',
body => { query => { match_all => {} } }
);

my @field_names = qw(title count); # change as per your fields

while ( my $doc = $s->next ) {
my @cols = map { $doc->{source}{$} } @field_names;
#$csv->print( $fh, @cols );

}

hope it helps.


(system) #3