diff --git a/lib/MetaCPAN/ES.pm b/lib/MetaCPAN/ES.pm index 67b51f1..266cda3 100644 --- a/lib/MetaCPAN/ES.pm +++ b/lib/MetaCPAN/ES.pm @@ -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} ) : () ), diff --git a/metacpan_ingest.conf b/metacpan_ingest.conf index 1a3d4b7..81c8201 100644 --- a/metacpan_ingest.conf +++ b/metacpan_ingest.conf @@ -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"