Bugzilla – Attachment 130343 Details for
Bug 28610
Elasticsearch 7 - hits.total is now an object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28610: Elasticsearch 7 - hits.total is now an object
Bug-28610-Elasticsearch-7---hitstotal-is-now-an-ob.patch (text/plain), 2.87 KB, created by
Kevin Carnes
on 2022-02-09 08:44:16 UTC
(
hide
)
Description:
Bug 28610: Elasticsearch 7 - hits.total is now an object
Filename:
MIME Type:
Creator:
Kevin Carnes
Created:
2022-02-09 08:44:16 UTC
Size:
2.87 KB
patch
obsolete
>From 88070b5b295d9a90f76420b129b8c48d1bf6eea3 Mon Sep 17 00:00:00 2001 >From: Kevin Carnes <kevin.carnes@ub.lu.se> >Date: Tue, 8 Feb 2022 14:48:19 +0100 >Subject: [PATCH] Bug 28610: Elasticsearch 7 - hits.total is now an object > >In Elasticsearch 7 hits.total is now an object which is not always an exact >value. You can always get an exact total by adding a track_total_hits >parameter set to true when using the Elasticsearch search method > >To test: >1) Run prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t >2) If you observe an error about types, apply patch for bug 25669 >3) Run prove t/db_dependent/Koha/SearchEngine/Elasticsearch/Search.t >4) Observe that tests with count fail >5) Apply patch >6) Observe that tests with count pass >7) Sign off > >Sponsored-by: Lund University Library >--- > Koha/SearchEngine/Elasticsearch.pm | 1 + > Koha/SearchEngine/Elasticsearch/Search.pm | 20 ++++++++++++++++---- > 2 files changed, 17 insertions(+), 4 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index 203183138f..c04c2173d6 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -104,6 +104,7 @@ sub get_elasticsearch { > $self->{elasticsearch} = Search::Elasticsearch->new( > $self->get_elasticsearch_params() > ); >+ $self->{es_version} = $self->{elasticsearch}->info->{version}{number}; > } > return $self->{elasticsearch}; > } >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index e753220948..038e56ce6e 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -51,6 +51,8 @@ use Koha::Exceptions::Elasticsearch; > use MARC::Record; > use MARC::File::XML; > use MIME::Base64 qw( decode_base64 ); >+use JSON; >+use version; > > Koha::SearchEngine::Elasticsearch::Search->mk_accessors(qw( store )); > >@@ -90,15 +92,22 @@ sub search { > $query->{from} = $page * $query->{size}; > } > my $elasticsearch = $self->get_elasticsearch(); >+ my %es_search = ( >+ index => $self->index_name, >+ body => $query >+ ); >+ if (version->parse($self->{es_version}) >= version->parse('7.0.0')) { >+ $es_search{'track_total_hits'} = JSON::true; >+ } > my $results = eval { >- $elasticsearch->search( >- index => $self->index_name, >- body => $query >- ); >+ $elasticsearch->search(%es_search); > }; > if ($@) { > die $self->process_error($@); > } >+ if (ref $results->{hits}->{total} eq 'HASH') { >+ $results->{hits}->{total} = $results->{hits}->{total}->{value}; >+ } > return $results; > } > >@@ -122,6 +131,9 @@ sub count { > body => $query > ); > >+ if (ref $result->{hits}->{total} eq 'HASH') { >+ return $result->{hits}->{total}->{value}; >+ } > return $result->{hits}->{total}; > } > >-- >2.17.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 28610
:
130291
|
130343
|
130844
|
131008
|
131436
|
131542
|
132389