From 91afd80123bb1cc43d80b65d38e6fe19a36e1002 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 5 Feb 2025 13:34:57 +0000 Subject: [PATCH] Bug 38912: Add option to include '_doc' type in ES record view This bug has been filed several times and seems to relate to the ES version, the version of Search::Elasticsearch and maybe other factors. Because the version of ES being used may vary, and such the necessary perl module version needed we should add an easy toggle to allow this feature to work, including the type if needed and not if not. To test: 1 - Apply patches, updatedatabase 2 - Enable Elasticsearch in Koha 3 - View a record details page 4 - Click 'Elastic record: Show' 5 - You should see the record 6 - Toggle ElasticsearchIncludeDocType system preference 7 - You get a 404 8 - Toggle it back 9 - Record shows 10 - sudo apt-get install libsearch-elasticsearch-perl=6.81-1-koha1 11 - Restart all 12 - View ES record - it fails! 13 - Toggle the syspref 14 - It works! 15 - Sign off --- catalogue/showelastic.pl | 12 ++++++----- .../data/mysql/atomicupdate/bug_38912.pl | 21 +++++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../modules/admin/preferences/searching.pref | 8 +++++++ 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_38912.pl diff --git a/catalogue/showelastic.pl b/catalogue/showelastic.pl index 0b19704c5b0..b2049283157 100755 --- a/catalogue/showelastic.pl +++ b/catalogue/showelastic.pl @@ -58,12 +58,14 @@ my $es_record; my @es_fields; try { - $es_record = $es->get_elasticsearch()->get({ + my $params = { index => $es->index_name, - id => $biblionumber, - }); -} -catch{ + id => $biblionumber + }; + $params->{type} = '_doc' if C4::Context->preference('ElasticsearchIncludeDocType'); + + $es_record = $es->get_elasticsearch()->get( $params ); +} catch { warn $_; print $input->redirect("/cgi-bin/koha/errors/404.pl"); }; diff --git a/installer/data/mysql/atomicupdate/bug_38912.pl b/installer/data/mysql/atomicupdate/bug_38912.pl new file mode 100755 index 00000000000..e91f195892e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_38912.pl @@ -0,0 +1,21 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "BUG_NUMBER", + description => "A single line description", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('ElasticsearchIncludeDocType', '0', '', 'When displaying ES records on the details page include the "type => _doc".', 'YesNo') + } + ); + + # sysprefs + say $out "Added new system preference 'ElasticsearchIncludeDocType'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 682b9fb950b..00bb58ae5c1 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -230,6 +230,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('EdifactInvoiceImport', 'automatic', 'automatic|manual', "If on, don't auto-import EDI invoices, just keep them in the database with the status 'new'", 'Choice'), ('EdifactLSQ', 'location', 'location|ccode', 'Map EDI sequence code (GIR+LSQ) to Koha Item field', 'Choice'), ('ElasticsearchCrossFields', '1', '', 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo'), +('ElasticsearchIncludeDocType', '0', '', 'When displaying ES records on the details page include the "type => _doc".', 'YesNo'), ('ElasticsearchIndexStatus_authorities', '0', 'Authorities index status', NULL, NULL), ('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL), ('ElasticsearchMARCFormat', 'ISO2709', 'ISO2709|ARRAY', 'Elasticsearch MARC format. ISO2709 format is recommended as it is faster and takes less space, whereas array is searchable.', 'Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref index 211d469dfd4..69bc6c2010b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref @@ -95,6 +95,14 @@ Searching: 0: Disable - "the cross_fields option for Elasticsearch searches, supported in Elasticsearch 6.X and above." - See the Elasticsearch cross_fields documentation. + - + - pref: ElasticsearchIncludeDocType + default: 0 + choices: + 1: Do + 0: Don't + - "include the 'type => _doc' parameter when displaying ES records on the details page." + - Due to specific configurations and versions the command to fetch a single record may or may not require this parameter, toggling it should fix 404 errors when viewing ES records from the details page. - - pref: SavedSearchFilters default: 0 -- 2.39.5