Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/MetaCPAN/ES.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ use Search::Elasticsearch;
use MetaCPAN::Ingest qw< config handle_error >;

sub new ( $class, %args ) {
my $mode = $args{mode} // "local";
my $node = $args{node};
my $index = $args{index} // "cpan";

my $config = config;
$node ||= $config->{es_node};
$node or die "Cannot create an ES instance without a node\n";
my $config_node =
$node ? $node :
$mode eq 'local' ? $config->{es_node} :
$mode eq 'test' ? $config->{es_test_node} :
$mode eq 'prod' ? $config->{es_production_node} :
undef;
$config_node or die "Cannot create an ES instance without a node\n";

return bless {
es => Search::Elasticsearch->new(
client => '2_0::Direct',
nodes => [$node],
nodes => [$config_node],
),
index => $index,
( $args{type} ? ( type => $args{type} ) : () ),
Expand Down
6 changes: 4 additions & 2 deletions metacpan_ingest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ log4perl_file log4perl.conf

es_node "elasticsearch:9200"

# Dev: for testing -
# for local data tests
es_test_node "elasticsearch_test:9200"

# to enable *reading* from profuction (check it's used in the code):
es_test_node "https://fastapi.metacpan.org/v1"
es_production_node "https://fastapi.metacpan.org/v1"