Commit 40ed936f authored by Dylan Griffith's avatar Dylan Griffith

Monkey patch ES gem to handle v7 API total count

This is due to the breaking change introduced in ES7
https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#hits-total-now-object-search-response
. This can be handled by the v7 client gem but since our main target is
ES6 for now we will just monkey patch the gem with this fix. When we
remove support for ES6 or use the ES7 gem and default to supporting ES7
then we can remove it.
parent 11f82bc8
......@@ -10,6 +10,7 @@ Gitlab.ee do
### 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
......
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment