diff --git a/config/initializers/elastic_client_setup.rb b/config/initializers/elastic_client_setup.rb index f38b606b3a8c5ec1d14e385d5b9b62e7ced7f89f..fce2c6782087bc30137e6e3bcec38cdce754ad85 100644 --- a/config/initializers/elastic_client_setup.rb +++ b/config/initializers/elastic_client_setup.rb @@ -10,6 +10,7 @@ ### Monkey patches Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records + Elasticsearch::Model::Response::Results.prepend GemExtensions::Elasticsearch::Model::Response::Results Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods Elasticsearch::Model::Adapter::ActiveRecord::Importing.prepend GemExtensions::Elasticsearch::Model::Adapter::ActiveRecord::Importing diff --git a/ee/lib/gem_extensions/elasticsearch/model/response/results.rb b/ee/lib/gem_extensions/elasticsearch/model/response/results.rb new file mode 100644 index 0000000000000000000000000000000000000000..992a54b2abaaaa75ee9df3cb4b8a4fec171e5741 --- /dev/null +++ b/ee/lib/gem_extensions/elasticsearch/model/response/results.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module GemExtensions + module Elasticsearch + module Model + module Response + module Results + # Handle ES7 API where total is returned as an object. This + # change is taken from the V7 gem + # https://github.com/elastic/elasticsearch-rails/commit/9c40f630e1b549f0b7889fe33dcd826b485af6fc + # and can be removed when we upgrade the gem to V7 + def total + if response.response['hits']['total'].respond_to?(:keys) + response.response['hits']['total']['value'] + else + response.response['hits']['total'] + end + end + end + end + end + end +end