lib/elasticsearch/persistence/repository/response/results.rb in elasticsearch-persistence-6.1.2 vs lib/elasticsearch/persistence/repository/response/results.rb in elasticsearch-persistence-7.0.0.pre

- old
+ new

@@ -1,5 +1,22 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + module Elasticsearch module Persistence module Repository module Response # :nodoc: @@ -19,10 +36,14 @@ # The key for accessing the total number of hits in an Elasticsearch query response. # TOTAL = 'total'.freeze + # The key for accessing the value field in an Elasticsearch query response when 'total' is an object. + # + VALUE = 'value'.freeze + # The key for accessing the maximum score in an Elasticsearch query response. # MAX_SCORE = 'max_score'.freeze # @param repository [Elasticsearch::Persistence::Repository::Class] The repository instance @@ -44,10 +65,14 @@ end # The number of total hits for a query # def total - raw_response[HITS][TOTAL] + if raw_response[HITS][TOTAL].respond_to?(:keys) + raw_response[HITS][TOTAL][VALUE] + else + raw_response[HITS][TOTAL] + end end # The maximum score for a query # def max_score