Skip to content

Commit 5bbe5aa

Browse files
Remove type from persistent requests
1 parent 6900eb5 commit 5bbe5aa

File tree

7 files changed

+62
-258
lines changed

7 files changed

+62
-258
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def find(*args)
6464
#
6565
def exists?(id, options={})
6666
request = { index: index_name, id: id }
67-
request[:type] = document_type if document_type
6867
client.exists(request.merge(options))
6968
end
7069

@@ -84,7 +83,6 @@ def exists?(id, options={})
8483
#
8584
def __find_one(id, options={})
8685
request = { index: index_name, id: id }
87-
request[:type] = document_type if document_type
8886
document = client.get(request.merge(options))
8987
deserialize(document)
9088
rescue OpenSearch::Transport::Transport::Errors::NotFound => e
@@ -95,7 +93,6 @@ def __find_one(id, options={})
9593
#
9694
def __find_many(ids, options={})
9795
request = { index: index_name, body: { ids: ids } }
98-
request[:type] = document_type if document_type
9996
documents = client.mget(request.merge(options))
10097
documents[DOCS].map do |document|
10198
deserialize(document) if document[FOUND]

opensearch-persistence/lib/opensearch/persistence/repository/search.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ module Search
6060
# @return [OpenSearch::Persistence::Repository::Response::Results]
6161
#
6262
def search(query_or_definition, options={})
63-
request = { index: index_name,
64-
type: document_type }
63+
request = { index: index_name }
6564
if query_or_definition.respond_to?(:to_hash)
6665
request[:body] = query_or_definition.to_hash
6766
elsif query_or_definition.is_a?(String)
@@ -98,8 +97,7 @@ def search(query_or_definition, options={})
9897
#
9998
def count(query_or_definition=nil, options={})
10099
query_or_definition ||= { query: { match_all: {} } }
101-
request = { index: index_name,
102-
type: document_type }
100+
request = { index: index_name }
103101

104102
if query_or_definition.respond_to?(:to_hash)
105103
request[:body] = query_or_definition.to_hash

opensearch-persistence/lib/opensearch/persistence/repository/store.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def save(document, options={})
4040
request = { index: index_name,
4141
id: id,
4242
body: serialized }
43-
request[:type] = document_type if document_type
4443
client.index(request.merge(options))
4544
end
4645

@@ -65,7 +64,6 @@ def update(document_or_id, options = {})
6564
if document_or_id.is_a?(String) || document_or_id.is_a?(Integer)
6665
id = document_or_id
6766
body = options
68-
type = document_type
6967
else
7068
document = serialize(document_or_id)
7169
id = __extract_id_from_document(document)
@@ -74,9 +72,8 @@ def update(document_or_id, options = {})
7472
else
7573
body = { doc: document }.merge(options)
7674
end
77-
type = document.delete(:type) || document_type
7875
end
79-
client.update(index: index_name, id: id, type: type, body: body)
76+
client.update(index: index_name, id: id, body: body)
8077
end
8178

8279
# Remove the serialized object or document with specified ID from OpenSearch
@@ -98,7 +95,7 @@ def delete(document_or_id, options = {})
9895
serialized = serialize(document_or_id)
9996
id = __get_id_from_document(serialized)
10097
end
101-
client.delete({ index: index_name, type: document_type, id: id }.merge(options))
98+
client.delete({ index: index_name, id: id }.merge(options))
10299
end
103100
end
104101
end

opensearch-persistence/spec/repository/find_spec.rb

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@
4646
expect(repository.exists?('1')).to be(false)
4747
end
4848
end
49-
50-
context 'when options are provided' do
51-
52-
let(:id) do
53-
repository.save(a: 1)['_id']
54-
end
55-
56-
it 'applies the options' do
57-
expect(repository.exists?(id, type: 'other_type')).to be(false)
58-
end
59-
end
6049
end
6150

6251
describe '#find' do
@@ -132,48 +121,6 @@
132121
end
133122
end
134123

135-
context 'when options are provided' do
136-
137-
context 'when a single id is passed' do
138-
139-
let!(:id) do
140-
repository.save(a: 1)['_id']
141-
end
142-
143-
it 'applies the options' do
144-
expect {
145-
repository.find(id, type: 'none')
146-
}.to raise_exception(OpenSearch::Persistence::Repository::DocumentNotFound)
147-
end
148-
end
149-
150-
context 'when an array of ids is passed' do
151-
152-
let!(:ids) do
153-
3.times.collect do |i|
154-
repository.save(a: i)['_id']
155-
end
156-
end
157-
158-
it 'applies the options' do
159-
expect(repository.find(ids, type: 'none')).to eq([nil, nil, nil])
160-
end
161-
end
162-
163-
context 'when multiple ids are passed' do
164-
165-
let!(:ids) do
166-
3.times.collect do |i|
167-
repository.save(a: i)['_id']
168-
end
169-
end
170-
171-
it 'applies the options' do
172-
expect(repository.find(*ids, type: 'none')).to eq([nil, nil, nil])
173-
end
174-
end
175-
end
176-
177124
context 'when a document_type is defined on the class' do
178125

179126
let(:repository) do

opensearch-persistence/spec/repository/search_spec.rb

Lines changed: 24 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -29,169 +29,55 @@
2929
DEFAULT_REPOSITORY
3030
end
3131

32-
context 'when the repository does not have a type set' do
33-
3432
before do
3533
repository.save({ name: 'user' }, refresh: true)
3634
end
3735

38-
context 'when a query definition is provided as a hash' do
39-
40-
it 'uses the default document type' do
41-
expect(repository.search({ query: { match: { name: 'user' } } }).first).to eq('name' => 'user')
42-
end
43-
end
44-
45-
context 'when a query definition is provided as a string' do
46-
47-
it 'uses the default document type' do
48-
expect(repository.search('user').first).to eq('name' => 'user')
49-
end
50-
end
51-
52-
context 'when the query definition is neither a String nor a Hash' do
36+
context 'when a query definition is provided as a hash' do
5337

54-
it 'raises an ArgumentError' do
55-
expect {
56-
repository.search(1)
57-
}.to raise_exception(ArgumentError)
58-
end
59-
end
60-
61-
context 'when options are provided' do
62-
63-
context 'when a query definition is provided as a hash' do
64-
65-
it 'uses the default document type' do
66-
expect(repository.search({ query: { match: { name: 'user' } } }, type: 'other').first).to be_nil
67-
end
68-
end
69-
70-
context 'when a query definition is provided as a string' do
71-
72-
it 'uses the default document type' do
73-
expect(repository.search('user', type: 'other').first).to be_nil
74-
end
75-
end
76-
77-
context 'when the query definition is neither a String nor a Hash' do
78-
79-
it 'raises an ArgumentError' do
80-
expect {
81-
repository.search(1)
82-
}.to raise_exception(ArgumentError)
83-
end
84-
end
38+
it 'uses the default document type' do
39+
expect(repository.search({ query: { match: { name: 'user' } } }).first).to eq('name' => 'user')
8540
end
8641
end
8742

88-
context 'when the repository does have a type set' do
43+
context 'when a query definition is provided as a string' do
8944

90-
let(:repository) do
91-
MyTestRepository.new(document_type: 'other_note')
45+
it 'uses the default document type' do
46+
expect(repository.search('user').first).to eq('name' => 'user')
9247
end
48+
end
9349

94-
before do
95-
repository.save({ name: 'user' }, refresh: true)
96-
end
97-
98-
context 'when options are provided' do
99-
100-
context 'when a query definition is provided as a hash' do
101-
102-
it 'uses the options' do
103-
expect(repository.search({ query: { match: { name: 'user' } } }, type: 'other').first).to be_nil
104-
end
105-
end
106-
107-
context 'when a query definition is provided as a string' do
108-
109-
it 'uses the options' do
110-
expect(repository.search('user', type: 'other').first).to be_nil
111-
end
112-
end
113-
114-
context 'when the query definition is neither a String nor a Hash' do
50+
context 'when the query definition is neither a String nor a Hash' do
11551

116-
it 'raises an ArgumentError' do
117-
expect {
118-
repository.search(1)
119-
}.to raise_exception(ArgumentError)
120-
end
121-
end
52+
it 'raises an ArgumentError' do
53+
expect {
54+
repository.search(1)
55+
}.to raise_exception(ArgumentError)
12256
end
12357
end
12458
end
12559

12660
describe '#count' do
12761

128-
context 'when the repository does not have a type set' do
129-
130-
let(:repository) do
131-
DEFAULT_REPOSITORY
132-
end
133-
134-
before do
135-
repository.save({ name: 'user' }, refresh: true)
136-
end
137-
138-
context 'when a query definition is provided as a hash' do
139-
140-
it 'uses the default document type' do
141-
expect(repository.count({ query: { match: { name: 'user' } } })).to eq(1)
142-
end
143-
end
144-
145-
context 'when a query definition is provided as a string' do
146-
147-
it 'uses the default document type' do
148-
expect(repository.count('user')).to eq(1)
149-
end
150-
end
151-
152-
context 'when options are provided' do
153-
154-
context 'when a query definition is provided as a hash' do
155-
156-
it 'uses the options' do
157-
expect(repository.count({ query: { match: { name: 'user' } } }, type: 'other')).to eq(0)
158-
end
159-
end
160-
161-
context 'when a query definition is provided as a string' do
62+
let(:repository) do
63+
DEFAULT_REPOSITORY
64+
end
16265

163-
it 'uses the options' do
164-
expect(repository.count('user', type: 'other')).to eq(0)
165-
end
166-
end
167-
end
66+
before do
67+
repository.save({ name: 'user' }, refresh: true)
16868
end
16969

170-
context 'when the repository does have a type set' do
70+
context 'when a query definition is provided as a hash' do
17171

172-
let(:repository) do
173-
MyTestRepository.new(document_type: 'other_note')
72+
it 'uses the default document type' do
73+
expect(repository.count({ query: { match: { name: 'user' } } })).to eq(1)
17474
end
75+
end
17576

176-
before do
177-
repository.save({ name: 'user' }, refresh: true)
178-
end
179-
180-
context 'when options are provided' do
181-
182-
context 'when a query definition is provided as a hash' do
183-
184-
it 'uses the options' do
185-
expect(repository.count({ query: { match: { name: 'user' } } }, type: 'other')).to eq(0)
186-
end
187-
end
188-
189-
context 'when a query definition is provided as a string' do
77+
context 'when a query definition is provided as a string' do
19078

191-
it 'uses the options' do
192-
expect(repository.count('user', type: 'other')).to eq(0)
193-
end
194-
end
79+
it 'uses the default document type' do
80+
expect(repository.count('user')).to eq(1)
19581
end
19682
end
19783
end

opensearch-persistence/spec/repository/store_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,12 @@ def serialize(document)
7474
context 'when options are provided' do
7575

7676
let!(:response) do
77-
repository.save(document, type: 'other_note')
77+
repository.save(document)
7878
end
7979

8080
it 'saves the document using the options' do
81-
expect {
82-
repository.find(response['_id'])
83-
}.to raise_exception(OpenSearch::Persistence::Repository::DocumentNotFound)
84-
expect(repository.find(response['_id'], type: 'other_note')).to eq('a' => 1)
81+
repository.find(response['_id'])
82+
expect(repository.find(response['_id'])).to eq('a' => 1)
8583
end
8684
end
8785
end
@@ -331,7 +329,7 @@ def to_hash
331329
context 'when the document does not exist' do
332330

333331
before do
334-
repository.create_index!(include_type_name: true)
332+
repository.create_index!
335333
end
336334

337335
it 'raises an exception' do

0 commit comments

Comments
 (0)