From e566bacdfaa0f27582313bf65723b9d876e8dc6e Mon Sep 17 00:00:00 2001 From: Kevin Carnes Date: Tue, 8 Feb 2022 14:14:11 +0100 Subject: [PATCH] Bug 25669: ElasticSearch 6: [types removal] Specifying types in put mapping requests is deprecated (incompatible with 7) Starting with version 7.0 of Elasticsearch type names should not be used and in version 6.8 there is a warning if you don't use include_type_name when using put_mapping (requires Search::Elasticsearch@6.8). To test: 1) Reindex records with koha-elasticsearch or rebuild_elasticsearch.pl 2) Observe any deprecation warnings or errors 3) Apply patch 4) Install Search::Elasticsearch with the same version as Elasticsearch 5) Reindex records with koha-elasticsearch or rebuild_elasticsearch.pl 6) Observe no warning or errors 7) Sign off Sponsored-by: Lund University Library --- Koha/SearchEngine/Elasticsearch/Indexer.pm | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm index 0a10832d2e..73f869d3db 100644 --- a/Koha/SearchEngine/Elasticsearch/Indexer.pm +++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -21,6 +21,7 @@ use Carp qw( carp croak ); use Modern::Perl; use Try::Tiny qw( catch try ); use List::Util qw( any ); +use version; use base qw(Koha::SearchEngine::Elasticsearch); use Koha::Exceptions; @@ -115,11 +116,14 @@ sub update_index { if (@body) { try{ my $elasticsearch = $self->get_elasticsearch(); - $response = $elasticsearch->bulk( + my %es_bulk = ( index => $self->index_name, - type => 'data', # is just hard coded in Indexer.pm? body => \@body ); + if (version->parse($elasticsearch->info->{version}->{number}) < version->parse('7.0.0')) { + $es_bulk{'type'} = 'data'; + } + $response = $elasticsearch->bulk(%es_bulk); if ($response->{errors}) { carp "One or more ElasticSearch errors occurred when indexing documents"; } @@ -252,13 +256,18 @@ sub update_mappings { foreach my $type (keys %{$mappings}) { try { - my $response = $elasticsearch->indices->put_mapping( + my %es_mapping = ( index => $self->index_name, - type => $type, - body => { - $type => $mappings->{$type} - } + body => $mappings->{$type} ); + if (version->parse($elasticsearch->info->{version}->{number}) < version->parse('7.0.0')) { + if (version->parse($elasticsearch->info->{version}->{number}) >= version->parse('6.8.0') && version->parse($elasticsearch->VERSION) >= version->parse('6.8.0')) { + $es_mapping{'include_type_name'} = \1; + } + $es_mapping{'type'} = $type; + $es_mapping{'body'} = {$type => $mappings->{$type}}; + } + my $response = $elasticsearch->indices->put_mapping(%es_mapping); } catch { $self->set_index_status_recreate_required(); my $reason = $_[0]->{vars}->{body}->{error}->{reason}; @@ -346,11 +355,14 @@ sub delete_index { my $elasticsearch = $self->get_elasticsearch(); my @body = map { { delete => { _id => "$_" } } } @{$biblionums}; - my $result = $elasticsearch->bulk( + my %es_bulk = ( index => $self->index_name, - type => 'data', body => \@body, ); + if (version->parse($elasticsearch->info->{version}->{number}) < version->parse('7.0.0')) { + $es_bulk{'type'} = 'data'; + } + my $result = $elasticsearch->bulk(%es_bulk); if ($result->{errors}) { croak "An Elasticsearch error occurred during bulk delete"; } -- 2.17.1