Skip to content

Commit

Permalink
delay the version number check until a "Type Exists" call is detected.
Browse files Browse the repository at this point in the history
  • Loading branch information
gugod committed Jul 5, 2018
1 parent 765e18f commit 2a8c8ab
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/Elastijk/oo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sub new {

sub __fleshen_request_args {
my ($self, $args) = @_;
$args->{$_} ||= $self->{$_} for grep { exists $self->{$_} } qw(host port index type head socket_cache on_connect connect_timeout read_timeout);
$args->{$_} ||= $self->{$_} for grep { defined $self->{$_} } qw(host port index type head socket_cache on_connect connect_timeout read_timeout);
}

sub request {
Expand Down Expand Up @@ -65,12 +65,18 @@ sub exists {
my $index = exists($args{index}) ? $args{index} : $self->{index};

my ($status,$res);
$res = $self->request(method => "GET", path => '/');

if (($res->{version}{number} ge '5') && $index && exists($args{type}) && !exists($args{id})) {
if ($index && exists($args{type}) && !exists($args{id})) {
# Type exists API
# https://www.elastic.co/guide/en/elasticsearch/reference/6.0/indices-types-exists.html
my $path = '/' . $index . '/_mappings/' . $args{type};
($status,$res) = $self->request(method => "GET", path => $path);

$res = $self->request( method => 'GET', path => '/', index => undef );
if ( ($res->{version}{number} || '') ge '5') {
my $path = '/' . $index . '/_mappings/' . $args{type};
($status,$res) = $self->request(method => "GET", path => $path);
} else {
($status,$res) = $self->request(method => "HEAD", %args);
}
} else {
($status,$res) = $self->request(method => "HEAD", %args);
}
Expand Down

0 comments on commit 2a8c8ab

Please sign in to comment.