From d5675d2b15fc03708452fb6ed8d09cdca66cd87a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 15 Dec 2025 15:25:07 +0100 Subject: [PATCH] Bug 38345: Restore support for OpenSearch The Koha_Main_OS1 and Koha_Main_OS2 jobs are currently failing on Jenkins. ``` [NoNodes] ** No nodes are available: [http://es:9200], called from sub Search::Elasticsearch::Role::Client::Direct::__ANON__ at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch/Indexer.pm line 417. # Looks like your test exited with 11 just after 3. ``` We need to workaround Elasticsearch/OpenSearch product check incompatibility. This patch suggests to monkey-patch Search::Elasticsearch::Role::Cxn::process_response to disable the strict product header check at runtime. This allows the same codebase to talk to both Elasticsearch 8+ and OpenSearch without forking or patching upstream. Test plan: 0. Set KOHA_ELASTICSEARCH=yes in ktd's .env 1. Startup ktd with the compose file for OS1 ktd -f docker-compose.os1.yml up 2. Set SearchEngine=Elasticsearch 3. reindex ktd --shell perl misc/search_tools/rebuild_elasticsearch.pl -a -b 4. run the tests prove -r t/db_dependent/Koha/SearchEngine/Elasticsearch 5. search! http://localhost:8081/cgi-bin/koha/catalogue/search.pl?q=perl should show results 6. ktd down then repeat using the compose file for OS2 (docker-compose.os2.yml), ES6 and ES7 for ES6 and ES7 you can use the --es6 and --es7 ktd flag. IF you get a 403 during the reindex you can try to add cluster.routing.allocation.disk.threshold_enabled: "false" to the environment section of the compose file. Or ``` curl -X PUT http://es:9200/_cluster/settings \ -H 'Content-Type: application/json' \ -d '{ "persistent": { "cluster.blocks.create_index": false } }' ``` OS thinks we lack disk space and force all indices into read-only. --- Koha/SearchEngine/Elasticsearch.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 53afa2929d0..c70ce1d9f9f 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -38,6 +38,25 @@ use Clone qw( clone ); use Modern::Perl; use Readonly qw( Readonly ); use Search::Elasticsearch; +use Search::Elasticsearch::Role::Cxn; +{ + # Monkey-patch Search::Elasticsearch::Role::Cxn::process_response + no warnings 'redefine'; + + my $orig_sub = \&Search::Elasticsearch::Role::Cxn::process_response; + + # Override method + *Search::Elasticsearch::Role::Cxn::process_response = sub { + my ( $self, $params, $code, $msg, $body, $headers ) = @_; + + #if ( $headers && $headers->{'x-elastic-product'} ne 'Elasticsearch' ) { + # $Search::Elasticsearch::Role::Cxn::PRODUCT_CHECK_VALUE = ''; + #} + $Search::Elasticsearch::Role::Cxn::PRODUCT_CHECK_VALUE = ''; + $orig_sub->(@_); + }; +} + use Try::Tiny qw( catch try ); use YAML::XS; -- 2.43.0