Created
March 16, 2012 10:50
-
-
Save clintongormley/2049562 to your computer and use it in GitHub Desktop.
Elasticsearch to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use ElasticSearch; | |
use Text::CSV_XS; | |
my $csv_file = 'output.csv'; | |
open my $fh, '>:encoding(utf8)', $csv_file or die $!; | |
my $csv = Text::CSV_XS->new; | |
my $e = ElasticSearch->new(servers => '127.0.0.1:9200'); | |
my $s = $e->scrolled_search( | |
index => 'foo', | |
type => 'bar', | |
query => {....} | |
); | |
my @field_names = qw(title name foo bar); | |
while (my $doc = $s->next) { | |
my @cols = map {$doc->{$_} @field_names; | |
$csv->print($fh, \@cols); | |
} | |
close $fh or die $!; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also https://robbydyer.wordpress.com/2014/08/25/exporting-from-kibana/