Bug 33353: Add compatibility with Search::Elasticsearch 8.0

For some reasons, with Search::Elasticsearch 8.0 JSON::true is
interpreted as 1 and Elasticsearch will always respond that it found "at
least 1 record". Something like this:

{
    total => {
        value => 1,
        relation => 'gte'
    }
}

Replacing JSON::true by \1 works with every version of
Search::Elasticsearch I tested (6.80, 7.717, 8.0)

Also worth noting:
Search::Elasticsearch will stop being supported by Elastic
https://github.com/elastic/elasticsearch-perl/issues/220

We might need to find an alternative for future versions of
Elasticsearch

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Philip Orr <philip.orr@lmscloud.de>
Signed-off-by: Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz>
This commit is contained in:
Julian Maurice 2023-03-28 17:02:19 +02:00 committed by Wainui Witika-Park
parent 0ae4d379fb
commit a053c21385
No known key found for this signature in database
GPG Key ID: 2D0A6AB5DAF1B78D
1 changed files with 2 additions and 2 deletions

View File

@ -94,7 +94,7 @@ sub search {
my $results = eval {
$elasticsearch->search(
index => $self->index_name,
track_total_hits => JSON::true,
track_total_hits => \1,
body => $query
);
};
@ -124,7 +124,7 @@ sub count {
# and just return number of hits
my $result = $elasticsearch->search(
index => $self->index_name,
track_total_hits => JSON::true,
track_total_hits => \1,
body => $query
);