Skip to content

Commit 2110bc3

Browse files
committed
[STORE] Deprecate _all field in ES 6.x (#820)
1 parent 3541fce commit 2110bc3

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

elasticsearch-persistence/lib/elasticsearch/persistence/repository/find.rb

+9-13
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ class DocumentNotFound < StandardError; end
77
#
88
module Find
99

10-
# The default type of document.
11-
#
12-
ALL = '_all'.freeze
13-
1410
# The key for accessing the document found and returned from an
1511
# Elasticsearch _mget query.
1612
#
@@ -57,16 +53,17 @@ def find(*args)
5753
# @return [true, false]
5854
#
5955
def exists?(id, options={})
60-
type = document_type || ALL
61-
client.exists( { index: index_name, type: type, id: id }.merge(options) )
56+
request = { index: index_name, id: id }
57+
request[:type] = document_type if document_type
58+
client.exists(request.merge(options))
6259
end
6360

6461
# @api private
6562
#
6663
def __find_one(id, options={})
67-
type = document_type || ALL
68-
document = client.get( { index: index_name, type: type, id: id }.merge(options) )
69-
64+
request = { index: index_name, id: id }
65+
request[:type] = document_type if document_type
66+
document = client.get(request.merge(options))
7067
deserialize(document)
7168
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
7269
raise DocumentNotFound, e.message, caller
@@ -75,13 +72,12 @@ def __find_one(id, options={})
7572
# @api private
7673
#
7774
def __find_many(ids, options={})
78-
type = document_type || ALL
79-
documents = client.mget( { index: index_name, type: type, body: { ids: ids } }.merge(options) )
80-
75+
request = { index: index_name, body: { ids: ids } }
76+
request[:type] = document_type if document_type
77+
documents = client.mget(request.merge(options))
8178
documents[DOCS].map { |document| document[FOUND] ? deserialize(document) : nil }
8279
end
8380
end
84-
8581
end
8682
end
8783
end

elasticsearch-persistence/test/unit/repository_find_test.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MyDocument; end
4949
end
5050

5151
should "return whether document for document_type exists" do
52-
subject.expects(:document_type).returns('my_document')
52+
subject.expects(:document_type).twice.returns('my_document')
5353

5454
@client
5555
.expects(:exists)
@@ -63,12 +63,12 @@ class MyDocument; end
6363
assert_equal true, subject.exists?('1')
6464
end
6565

66-
should "return whether document exists using _all type" do
66+
should "return whether document exists using no document type" do
6767

6868
@client
6969
.expects(:exists)
7070
.with do |arguments|
71-
assert_equal '_all', arguments[:type]
71+
assert_equal nil, arguments[:type]
7272
assert_equal '1', arguments[:id]
7373
true
7474
end
@@ -92,7 +92,7 @@ class MyDocument; end
9292
context "'__find_one' method" do
9393

9494
should "find a document based on document_type and return a deserialized object" do
95-
subject.expects(:document_type).returns('my_document')
95+
subject.expects(:document_type).twice.returns('my_document')
9696

9797
subject.expects(:deserialize).with({'_source' => {'foo' => 'bar'}}).returns(MyDocument.new)
9898

@@ -108,15 +108,15 @@ class MyDocument; end
108108
assert_instance_of MyDocument, subject.__find_one('1')
109109
end
110110

111-
should "find a document using _all if document_type is not defined" do
111+
should "find a document using no type if document_type is not defined" do
112112
subject.expects(:document_type).returns(nil)
113113

114114
subject.expects(:deserialize).with({'_source' => {'foo' => 'bar'}}).returns(MyDocument.new)
115115

116116
@client
117117
.expects(:get)
118118
.with do |arguments|
119-
assert_equal '_all', arguments[:type]
119+
assert_equal nil, arguments[:type]
120120
assert_equal '1', arguments[:id]
121121
true
122122
end
@@ -187,7 +187,7 @@ class MyDocument; end
187187
end
188188

189189
should "find documents based on document_type and return an Array of deserialized objects" do
190-
subject.expects(:document_type).returns('my_document')
190+
subject.expects(:document_type).twice.returns('my_document')
191191

192192
subject.expects(:deserialize).twice
193193

@@ -219,7 +219,7 @@ class MyDocument; end
219219
@client
220220
.expects(:mget)
221221
.with do |arguments|
222-
assert_equal '_all', arguments[:type]
222+
assert_equal nil, arguments[:type]
223223
assert_equal ['1', '2'], arguments[:body][:ids]
224224
true
225225
end
@@ -256,7 +256,7 @@ class MyDocument; end
256256
"_source"=>{"id"=>"2", "title"=>"Test 2"}}
257257
]}
258258

259-
subject.expects(:document_type).returns('my_document')
259+
subject.expects(:document_type).twice.returns('my_document')
260260

261261
subject
262262
.expects(:deserialize)

0 commit comments

Comments
 (0)