Skip to content

Updates for using with client v7.14.0 #999

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 4 commits into from
Aug 9, 2021
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
3 changes: 3 additions & 0 deletions .github/workflows/2.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
branches:
- '*'
jobs:
tests:
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/2.5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
branches:
- '*'
jobs:
tests:
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/2.6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
branches:
- '*'
jobs:
tests:
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/2.7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
branches:
- '*'
jobs:
tests:
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/jruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
branches:
- '*'
jobs:
tests:
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/license.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: License headers
on: [pull_request]
on: [pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-model/lib/elasticsearch/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module ClassMethods
# @example Get the client
#
# Elasticsearch::Model.client
# => #<Elasticsearch::Transport::Client:0x007f96a7d0d000 @transport=... >
# => #<Elasticsearch::Client:0x007f96a7d0d000... >
#
def client
@client ||= Elasticsearch::Client.new
Expand All @@ -138,7 +138,7 @@ def client
# @example Configure (set) the client for all models
#
# Elasticsearch::Model.client = Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true
# => #<Elasticsearch::Transport::Client:0x007f96a6dd0d80 @transport=... >
# => #<Elasticsearch::Client:0x007f96a6dd0d80... >
#
# @note You have to set the client before you call Elasticsearch methods on the model,
# or set it directly on the model; see {Elasticsearch::Model::Client::ClassMethods#client}
Expand Down
5 changes: 0 additions & 5 deletions elasticsearch-model/lib/elasticsearch/model/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@

module Elasticsearch
module Model

# Contains an `Elasticsearch::Client` instance
#
module Client

module ClassMethods

# Get the client for a specific model class
#
# @example Get the client for `Article` and perform API request
Expand All @@ -48,7 +45,6 @@ def client=(client)
end

module InstanceMethods

# Get or set the client for a specific model instance
#
# @example Get the client for a specific record and perform API request
Expand All @@ -72,7 +68,6 @@ def client=(client)
@client = client
end
end

end
end
end
4 changes: 2 additions & 2 deletions elasticsearch-model/lib/elasticsearch/model/indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def delete_index!(options={})
self.client.indices.delete index: target_index
rescue Exception => e
if e.class.to_s =~ /NotFound/ && options[:force]
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger
nil
else
raise e
Expand All @@ -317,7 +317,7 @@ def refresh_index!(options={})
self.client.indices.refresh index: target_index
rescue Exception => e
if e.class.to_s =~ /NotFound/ && options[:force]
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger
nil
else
raise e
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch-model/spec/elasticsearch/model/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class ::DummyClientModel
context 'when a class includes the client module class methods' do

it 'defines the client module class methods on the model' do
expect(DummyClientModel.client).to be_a(Elasticsearch::Transport::Client)
expect(DummyClientModel.client).to be_a(Elasticsearch::Client)
end
end

context 'when a class includes the client module instance methods' do

it 'defines the client module class methods on the model' do
expect(DummyClientModel.new.client).to be_a(Elasticsearch::Transport::Client)
expect(DummyClientModel.new.client).to be_a(Elasticsearch::Client)
end
end

Expand Down Expand Up @@ -77,7 +77,7 @@ class ::DummyClientModel
end

it 'does not set the client on the class' do
expect(DummyClientModel.client).to be_a(Elasticsearch::Transport::Client)
expect(DummyClientModel.client).to be_a(Elasticsearch::Client)
end
end
end
27 changes: 16 additions & 11 deletions elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,13 @@ class ::DummyIndexingModelForRecreate
end

context 'when the index is not found' do
let(:logger) { nil }
let(:transport) do
Elasticsearch::Transport::Client.new(logger: logger)
end

let(:client) do
double('client', indices: indices, transport: double('transport', { logger: nil }))
double('client', indices: indices, transport: transport)
end

let(:indices) do
Expand All @@ -692,19 +696,17 @@ class ::DummyIndexingModelForRecreate
end

context 'when the force option is true' do

it 'deletes the index without raising an exception' do
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
end

context 'when the client has a logger' do

let(:logger) do
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
end

let(:client) do
double('client', indices: indices, transport: double('transport', { logger: logger }))
double('client', indices: indices, transport: transport)
end

it 'deletes the index without raising an exception' do
Expand Down Expand Up @@ -912,7 +914,11 @@ class ::DummyIndexingModelForRefresh
end

let(:client) do
double('client', indices: indices, transport: double('transport', { logger: nil }))
double('client', indices: indices, transport: transport)
end

let(:transport) do
Elasticsearch::Transport::Client.new(logger: nil)
end

let(:indices) do
Expand All @@ -924,9 +930,7 @@ class ::DummyIndexingModelForRefresh
end

context 'when the force option is true' do

context 'when the operation raises a NotFound exception' do

before do
expect(indices).to receive(:refresh).and_raise(NotFound)
end
Expand All @@ -936,13 +940,16 @@ class ::DummyIndexingModelForRefresh
end

context 'when the client has a logger' do

let(:logger) do
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
end

let(:client) do
double('client', indices: indices, transport: double('transport', { logger: logger }))
double('client', indices: indices, transport: transport)
end

let(:transport) do
Elasticsearch::Transport::Client.new(logger: logger)
end

it 'does not raise an exception' do
Expand All @@ -957,7 +964,6 @@ class ::DummyIndexingModelForRefresh
end

context 'when the operation raises another type of exception' do

before do
expect(indices).to receive(:refresh).and_raise(Exception)
end
Expand All @@ -971,7 +977,6 @@ class ::DummyIndexingModelForRefresh
end

context 'when an index name is provided in the options' do

before do
expect(indices).to receive(:refresh).with(index: 'custom-foo')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
describe '#client' do

it 'should have a default' do
expect(Elasticsearch::Model.client).to be_a(Elasticsearch::Transport::Client)
expect(Elasticsearch::Model.client).to be_a(Elasticsearch::Client)
end
end

Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-persistence/spec/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class RepositoryWithoutDSL
end

it 'sets a default client' do
expect(repository.client).to be_a(Elasticsearch::Transport::Client)
expect(repository.client).to be_a(Elasticsearch::Client)
end


Expand Down Expand Up @@ -465,7 +465,7 @@ class RepositoryWithoutDSL
end

it 'sets a default on the instance' do
expect(RepositoryWithoutDSL.new.client).to be_a(Elasticsearch::Transport::Client)
expect(RepositoryWithoutDSL.new.client).to be_a(Elasticsearch::Client)
end

it 'allows the value to be overridden with options on the instance' do
Expand Down