Created
June 16, 2020 13:56
-
-
Save netsensei/6eabebc8e2345bc5c35d1db61a6b0fef to your computer and use it in GitHub Desktop.
Quick 'n dirty ElasticSearch via Catmandu/Perl (Part 1)
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
# assuming catmandu.yml in the same folder as this script | |
# Change bag("document") to the relevant bag name / document type in ES | |
# ensure camtandu.yml exists! | |
use Catmandu::Sane; | |
use Config::Onion; | |
use Catmandu; | |
use Path::Tiny; | |
use Data::Dumper; | |
sub build_root_path { | |
path(__FILE__)->parent->absolute->stringify; | |
} | |
sub build_config { | |
my $config = Config::Onion->new(prefix_key => '_prefix'); | |
my @paths = ( build_root_path() ); | |
$config->load_glob(map {path($_)->child('*.yml')->stringify} | |
reverse @paths); | |
$config->get; | |
} | |
Catmandu->load(build_root_path()); | |
Catmandu->config(build_config()); | |
my $store = Catmandu->store('search'); | |
my $hits = $store->bag("document")->search(query => 'text:contents'); | |
print Dumper($hits); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment