Skip to content

Commit ed9f449

Browse files
committed
[STORE] Handle total hits as an object in search response
1 parent 6baae48 commit ed9f449

File tree

1 file changed

+9
-1
lines changed
  • elasticsearch-persistence/lib/elasticsearch/persistence/repository/response

1 file changed

+9
-1
lines changed

elasticsearch-persistence/lib/elasticsearch/persistence/repository/response/results.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Results
3838
#
3939
TOTAL = 'total'.freeze
4040

41+
# The key for accessing the value field in an Elasticsearch query response when 'total' is an object.
42+
#
43+
VALUE = 'value'.freeze
44+
4145
# The key for accessing the maximum score in an Elasticsearch query response.
4246
#
4347
MAX_SCORE = 'max_score'.freeze
@@ -63,7 +67,11 @@ def respond_to?(method_name, include_private = false)
6367
# The number of total hits for a query
6468
#
6569
def total
66-
raw_response[HITS][TOTAL]
70+
if raw_response[HITS][TOTAL].respond_to?(:keys)
71+
raw_response[HITS][TOTAL][VALUE]
72+
else
73+
raw_response[HITS][TOTAL]
74+
end
6775
end
6876

6977
# The maximum score for a query

0 commit comments

Comments
 (0)