Skip to content

Commit 7aaec34

Browse files
committed
[MODEL] Lazily wrap response in HashWrapper and provide #raw_response access
1 parent 198d1ec commit 7aaec34

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

elasticsearch-model/lib/elasticsearch/model/response.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def initialize(klass, search, options={})
2727
# @return [Hash]
2828
#
2929
def response
30-
@response ||= begin
31-
HashWrapper.new(search.execute!)
32-
end
30+
@response ||= HashWrapper.new(search.execute!)
3331
end
3432

3533
# Returns the collection of "hits" from Elasticsearch
@@ -63,7 +61,7 @@ def timed_out
6361
# Returns the statistics on shards
6462
#
6563
def shards
66-
HashWrapper.new(response['_shards'])
64+
response['_shards']
6765
end
6866

6967
# Returns a Hashie::Mash of the aggregations
@@ -77,6 +75,10 @@ def aggregations
7775
def suggestions
7876
Suggestions.new(response['suggest'])
7977
end
78+
79+
def raw_response
80+
@raw_response ||= search.execute!
81+
end
8082
end
8183
end
8284
end

elasticsearch-model/lib/elasticsearch/model/response/base.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Base
1313
def initialize(klass, response, options={})
1414
@klass = klass
1515
@response = response
16+
@raw_response = response
1617
end
1718

1819
# @abstract Implement this method in specific class

elasticsearch-model/test/unit/response_results_test.rb

+3
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ def self.document_type; 'bar'; end
2727
assert_equal 'bar', @results.first.foo
2828
end
2929

30+
should "provide access to the raw response" do
31+
assert_equal RESPONSE, @response.raw_response
32+
end
3033
end
3134
end

0 commit comments

Comments
 (0)