# Perl Search::Elasticsearch - result object handling

**URL:** <https://discuss.elastic.co/t/perl-search-elasticsearch-result-object-handling/35750>\
**Category:** Elasticsearch\
**Created:** [November 27, 2015, 11:49am UTC](https://discuss.elastic.co/t/perl-search-elasticsearch-result-object-handling/35750 "2015-11-27T11:49:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![setuk](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@setuk](https://discuss.elastic.co/u/setuk)\
**Post date:** [November 27, 2015, 11:49am UTC](https://discuss.elastic.co/t/perl-search-elasticsearch-result-object-handling/35750/1 "2015-11-27T11:49:14Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ankmathur14](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@ankmathur14](https://discuss.elastic.co/u/ankmathur14)\
**Post date:** [November 28, 2015, 5:25pm UTC](https://discuss.elastic.co/t/perl-search-elasticsearch-result-object-handling/35750/2 "2015-11-28T17:25:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:35pm UTC](https://discuss.elastic.co/t/perl-search-elasticsearch-result-object-handling/35750/3 "2017-07-05T23:35:11Z")

</div>

Closed on July 5, 2017, 11:35pm UTC


