Bugzilla – Attachment 136417 Details for
Bug 25669
ElasticSearch 6: [types removal] Specifying types in put mapping requests is deprecated (incompatible with 7)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25669: [alternate] Use include_type_name parameter in ES calls
Bug-25669-alternate-Use-includetypename-parameter-.patch (text/plain), 7.16 KB, created by
Martin Renvoize (ashimema)
on 2022-06-22 13:51:33 UTC
(
hide
)
Description:
Bug 25669: [alternate] Use include_type_name parameter in ES calls
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-06-22 13:51:33 UTC
Size:
7.16 KB
patch
obsolete
>From 8aafbf6a4b0828c898fe815df993ff29d19cfeb2 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 28 Mar 2022 12:00:25 +0000 >Subject: [PATCH] Bug 25669: [alternate] Use include_type_name parameter in ES > calls > >This patch includes the parameter: >include_type_name >on our ES calls > >It removes the deprecation warning we are seeing, and should allow using ES7 with no other chnages. > >For ES8 we will need to remove the hardcoded type, > >I would suggest a second patch, with a new syspref "ElasticsearchLegacyType" set to 'True' by default. >Description can explain that this must be set to false, and data reindexed after upgrading to ES7 and before >upgrading to ES8 - then we can drop this pref when we drop ES7 support > >When we drop ES6 support the pref can be set default true for upgrades, default 'false' for new installs > >Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/SearchEngine/Elasticsearch.pm | 14 ++++---- > Koha/SearchEngine/Elasticsearch/Indexer.pm | 36 +++++++++---------- > .../Elasticsearch/QueryBuilder.pm | 4 +-- > 3 files changed, 26 insertions(+), 28 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index 85d8cba798..c4f5041930 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -189,9 +189,7 @@ sub get_elasticsearch_mappings { > if (!defined $all_mappings{$self->index}) { > $sort_fields{$self->index} = {}; > # Clone the general mapping to break ties with the original hash >- my $mappings = { >- data => clone(_get_elasticsearch_field_config('general', '')) >- }; >+ my $mappings = clone(_get_elasticsearch_field_config('general', '')); > my $marcflavour = lc C4::Context->preference('marcflavour'); > $self->_foreach_mapping( > sub { >@@ -214,25 +212,25 @@ sub get_elasticsearch_mappings { > } > > if ($search) { >- $mappings->{data}{properties}{$name} = _get_elasticsearch_field_config('search', $es_type); >+ $mappings->{properties}{$name} = _get_elasticsearch_field_config('search', $es_type); > } > > if ($facet) { >- $mappings->{data}{properties}{ $name . '__facet' } = _get_elasticsearch_field_config('facet', $es_type); >+ $mappings->{properties}{ $name . '__facet' } = _get_elasticsearch_field_config('facet', $es_type); > } > if ($suggestible) { >- $mappings->{data}{properties}{ $name . '__suggestion' } = _get_elasticsearch_field_config('suggestible', $es_type); >+ $mappings->{properties}{ $name . '__suggestion' } = _get_elasticsearch_field_config('suggestible', $es_type); > } > # Sort is a bit special as it can be true, false, undef. > # We care about "true" or "undef", > # "undef" means to do the default thing, which is make it sortable. > if (!defined $sort || $sort) { >- $mappings->{data}{properties}{ $name . '__sort' } = _get_elasticsearch_field_config('sort', $es_type); >+ $mappings->{properties}{ $name . '__sort' } = _get_elasticsearch_field_config('sort', $es_type); > $sort_fields{$self->index}{$name} = 1; > } > } > ); >- $mappings->{data}{properties}{ 'match-heading' } = _get_elasticsearch_field_config('search', 'text') if $self->index eq 'authorities'; >+ $mappings->{properties}{ 'match-heading' } = _get_elasticsearch_field_config('search', 'text') if $self->index eq 'authorities'; > $all_mappings{$self->index} = $mappings; > } > $self->sort_fields(\%{$sort_fields{$self->index}}); >diff --git a/Koha/SearchEngine/Elasticsearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm >index ca0d19a442..adefd1f7ec 100644 >--- a/Koha/SearchEngine/Elasticsearch/Indexer.pm >+++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm >@@ -267,24 +267,23 @@ sub update_mappings { > my $elasticsearch = $self->get_elasticsearch(); > my $mappings = $self->get_elasticsearch_mappings(); > >- foreach my $type (keys %{$mappings}) { >- try { >- my $response = $elasticsearch->indices->put_mapping( >- index => $self->index_name, >- type => $type, >- body => { >- $type => $mappings->{$type} >- } >- ); >- } catch { >- $self->set_index_status_recreate_required(); >- my $reason = $_[0]->{vars}->{body}->{error}->{reason}; >- my $index_name = $self->index_name; >- Koha::Exception->throw( >- error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed", >- ); >- }; >- } >+ try { >+ my $response = $elasticsearch->indices->put_mapping( >+ index => $self->index_name, >+ type => 'data', >+ include_type_name => JSON::true(), >+ body => { >+ data => $mappings >+ } >+ ); >+ } catch { >+ $self->set_index_status_recreate_required(); >+ my $reason = $_[0]->{vars}->{body}->{error}->{reason}; >+ my $index_name = $self->index_name; >+ Koha::Exception->throw( >+ error => "Unable to update mappings for index \"$index_name\". Reason was: \"$reason\". Index needs to be recreated and reindexed", >+ ); >+ }; > $self->set_index_status_ok(); > } > >@@ -356,6 +355,7 @@ sub delete_index { > my $result = $elasticsearch->bulk( > index => $self->index_name, > type => 'data', >+ include_type_name => JSON::true(), > body => \@body, > ); > if ($result->{errors}) { >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index dba475eb3c..a3f15f01c0 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -577,7 +577,7 @@ sub build_authorities_query_compat { > > $m = exists $koha_to_index_name->{$m} ? $koha_to_index_name->{$m} : $m; > push @indexes, $m; >- warn "Unknown search field $m in marclist" unless (defined $mappings->{data}->{properties}->{$m} || $m eq '' || $m eq 'match-heading'); >+ warn "Unknown search field $m in marclist" unless (defined $mappings->{properties}->{$m} || $m eq '' || $m eq 'match-heading'); > } > for ( my $i = 0 ; $i < @$value ; $i++ ) { > next unless $value->[$i]; #clean empty form values, ES doesn't like undefined searches >@@ -1125,7 +1125,7 @@ sub _sort_field { > my ($self, $f) = @_; > > my $mappings = $self->get_elasticsearch_mappings(); >- my $textField = defined $mappings->{data}{properties}{$f}{type} && $mappings->{data}{properties}{$f}{type} eq 'text'; >+ my $textField = defined $mappings->{properties}{$f}{type} && $mappings->{properties}{$f}{type} eq 'text'; > if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) { > $f .= '__sort'; > } else { >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25669
:
130288
|
130293
|
130341
|
130811
|
131009
|
131037
|
131484
|
132321
|
135335
|
135542
|
135543
|
136417
|
136418
|
136452
|
136453
|
139531
|
139532