Skip to content

[STORE] Deprecate _all field in ES 6.x #820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ class DocumentNotFound < StandardError; end
#
module Find

# The default type of document.
#
ALL = '_all'.freeze

# The key for accessing the document found and returned from an
# Elasticsearch _mget query.
#
Expand Down Expand Up @@ -57,16 +53,17 @@ def find(*args)
# @return [true, false]
#
def exists?(id, options={})
type = document_type || ALL
client.exists( { index: index_name, type: type, id: id }.merge(options) )
request = { index: index_name, id: id }
request[:type] = document_type if document_type
client.exists(request.merge(options))
end

# @api private
#
def __find_one(id, options={})
type = document_type || ALL
document = client.get( { index: index_name, type: type, id: id }.merge(options) )

request = { index: index_name, id: id }
request[:type] = document_type if document_type
document = client.get(request.merge(options))
deserialize(document)
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
raise DocumentNotFound, e.message, caller
Expand All @@ -75,13 +72,12 @@ def __find_one(id, options={})
# @api private
#
def __find_many(ids, options={})
type = document_type || ALL
documents = client.mget( { index: index_name, type: type, body: { ids: ids } }.merge(options) )

request = { index: index_name, body: { ids: ids } }
request[:type] = document_type if document_type
documents = client.mget(request.merge(options))
documents[DOCS].map { |document| document[FOUND] ? deserialize(document) : nil }
end
end

end
end
end
18 changes: 9 additions & 9 deletions elasticsearch-persistence/test/unit/repository_find_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MyDocument; end
end

should "return whether document for document_type exists" do
subject.expects(:document_type).returns('my_document')
subject.expects(:document_type).twice.returns('my_document')

@client
.expects(:exists)
Expand All @@ -63,12 +63,12 @@ class MyDocument; end
assert_equal true, subject.exists?('1')
end

should "return whether document exists using _all type" do
should "return whether document exists using no document type" do

@client
.expects(:exists)
.with do |arguments|
assert_equal '_all', arguments[:type]
assert_equal nil, arguments[:type]
assert_equal '1', arguments[:id]
true
end
Expand All @@ -92,7 +92,7 @@ class MyDocument; end
context "'__find_one' method" do

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

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

Expand All @@ -108,15 +108,15 @@ class MyDocument; end
assert_instance_of MyDocument, subject.__find_one('1')
end

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

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

@client
.expects(:get)
.with do |arguments|
assert_equal '_all', arguments[:type]
assert_equal nil, arguments[:type]
assert_equal '1', arguments[:id]
true
end
Expand Down Expand Up @@ -187,7 +187,7 @@ class MyDocument; end
end

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

subject.expects(:deserialize).twice

Expand Down Expand Up @@ -219,7 +219,7 @@ class MyDocument; end
@client
.expects(:mget)
.with do |arguments|
assert_equal '_all', arguments[:type]
assert_equal nil, arguments[:type]
assert_equal ['1', '2'], arguments[:body][:ids]
true
end
Expand Down Expand Up @@ -256,7 +256,7 @@ class MyDocument; end
"_source"=>{"id"=>"2", "title"=>"Test 2"}}
]}

subject.expects(:document_type).returns('my_document')
subject.expects(:document_type).twice.returns('my_document')

subject
.expects(:deserialize)
Expand Down