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.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit afefb8a485)
Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
This commit is contained in:
Jonathan Druart 2025-12-15 15:25:07 +01:00 committed by Jacob O'Mara
parent 17aa1fd2e1
commit 8e7d76c60d
No known key found for this signature in database
1 changed files with 18 additions and 0 deletions

View File

@ -38,6 +38,24 @@ 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 = '';
}
$orig_sub->(@_);
};
}
use Try::Tiny qw( catch try );
use YAML::XS;