-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add update_by_query method to index
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-6/index/documents_update_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/index_documents_update_by_query' | ||
|
||
stack_describe 'elasticsearch', '6.x', Esse::Index, '.update_by_query' do | ||
include_examples 'index.update_by_query' | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-7/index/documents_update_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/index_documents_update_by_query' | ||
|
||
stack_describe 'elasticsearch', '7.x', Esse::Index, '.update_by_query' do | ||
include_examples 'index.update_by_query' | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/esse/integrations/elasticsearch-8/indices/documents_update_by_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/shared_examples/index_documents_update_by_query' | ||
|
||
stack_describe 'elasticsearch', '8.x', Esse::Index, '.update_by_query' do | ||
include_examples 'index.update_by_query' | ||
end |
61 changes: 61 additions & 0 deletions
61
spec/support/shared_examples/index_documents_update_by_query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples 'index.update_by_query' do |doc_type: false| | ||
include_context 'with venues index definition' | ||
|
||
let(:params) do | ||
doc_type ? { type: 'venue' } : {} | ||
end | ||
let(:doc_params) do | ||
doc_type ? { _type: 'venue' } : {} | ||
end | ||
let(:index_suffix) { SecureRandom.hex(8) } | ||
let(:body) { { script: { source: 'ctx._source.title = "foo"' }, query: { match_all: {} } } } | ||
|
||
it 'raises an Esse::Transport::ReadonlyClusterError exception when the cluster is readonly' do | ||
es_client do |client, _conf, cluster| | ||
cluster.warm_up! | ||
expect(client).not_to receive(:perform_request) | ||
cluster.readonly = true | ||
expect { | ||
VenuesIndex.update_by_query(body: body, **params) | ||
}.to raise_error(Esse::Transport::ReadonlyClusterError) | ||
end | ||
end | ||
|
||
it 'raises an Esse::Transport::ServerError exception when api throws an error' do | ||
es_client do |client, _conf, cluster| | ||
expect { | ||
VenuesIndex.update_by_query(body: body, **params) | ||
}.to raise_error(Esse::Transport::NotFoundError) | ||
end | ||
end | ||
|
||
it 'updates the documents in the aliased index' do | ||
es_client do |client, _conf, cluster| | ||
VenuesIndex.create_index(alias: true, suffix: index_suffix) | ||
VenuesIndex.import(refresh: true, suffix: index_suffix, **params) | ||
|
||
resp = nil | ||
expect { | ||
resp = VenuesIndex.update_by_query(body: body, **params) | ||
}.not_to raise_error | ||
expect(resp['total']).to eq(total_venues) | ||
expect(resp['updated']).to eq(total_venues) | ||
end | ||
end | ||
|
||
it 'updates the documents in the unaliased index' do | ||
es_client do |client, _conf, cluster| | ||
VenuesIndex.create_index(alias: false, suffix: index_suffix) | ||
VenuesIndex.import(refresh: true, suffix: index_suffix, **params) | ||
|
||
resp = nil | ||
expect { | ||
resp = VenuesIndex.update_by_query(body: body, suffix: index_suffix, **params) | ||
}.not_to raise_error | ||
expect(resp['total']).to eq(total_venues) | ||
expect(resp['updated']).to eq(total_venues) | ||
end | ||
end | ||
end |