Skip to content
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

Add ES 8.x support #1025

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ task :wait_for_green do
ready = true
break
end
rescue Elasticsearch::Transport::Transport::Errors::RequestTimeout => ex
rescue ELASTIC_TRANSPORT_CLASS::Transport::Errors::RequestTimeout => ex
puts "Couldn't confirm green status.\n#{ex.inspect}."
rescue Faraday::ConnectionFailed => ex
puts "Couldn't connect to Elasticsearch.\n#{ex.inspect}."
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-model/elasticsearch-model.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.4'

s.add_dependency 'activesupport', '> 3'
s.add_dependency 'elasticsearch', '~> 7'
s.add_dependency 'elasticsearch', '~> 8'
s.add_dependency 'hashie'

s.add_development_dependency 'activemodel', '> 3'
Expand Down
8 changes: 8 additions & 0 deletions elasticsearch-model/lib/elasticsearch/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::WillPaginate
end

ELASTIC_TRANSPORT_CLASS =
begin
require 'elastic/transport'
Elastic::Transport
rescue LoadError
Elasticsearch::Transport
end

module Elasticsearch

# Elasticsearch integration for Ruby models
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-model/lib/elasticsearch/model/importing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def import(options={}, &block)
index: target_index,
type: target_type,
body: __batch_to_bulk(batch, transform)
}
}.compact

params[:pipeline] = pipeline if pipeline

Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-model/lib/elasticsearch/model/multimodel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def document_type

# Get the client common for all models
#
# @return Elasticsearch::Transport::Client
# @return Elastic::Transport::Client
#
def client
Elasticsearch::Model.client
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-model/lib/elasticsearch/model/searching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def initialize(klass, query_or_payload, options={})
end

if body
@definition = { index: __index_name, type: __document_type, body: body }.update options
@definition = { index: __index_name, type: __document_type, body: body }.compact.update options
else
@definition = { index: __index_name, type: __document_type, q: q }.update options
@definition = { index: __index_name, type: __document_type, q: q }.compact.update options
end
end

Expand Down
6 changes: 3 additions & 3 deletions elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ class ::DummyIndexingModelForRecreate
context 'when the index is not found' do
let(:logger) { nil }
let(:transport) do
Elasticsearch::Transport::Client.new(logger: logger)
ELASTIC_TRANSPORT_CLASS::Client.new(logger: logger)
end

let(:client) do
Expand Down Expand Up @@ -918,7 +918,7 @@ class ::DummyIndexingModelForRefresh
end

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

let(:indices) do
Expand Down Expand Up @@ -949,7 +949,7 @@ class ::DummyIndexingModelForRefresh
end

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

it 'does not raise an exception' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Gem::Specification.new do |s|

s.required_ruby_version = ">= 1.9.3"

s.add_dependency "elasticsearch", '~> 7'
s.add_dependency "elasticsearch", '~> 8'
s.add_dependency "elasticsearch-model", '7.2.1'
s.add_dependency "activesupport", '> 4'
s.add_dependency "activemodel", '> 4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __find_one(id, options={})
request[:type] = document_type if document_type
document = client.get(request.merge(options))
deserialize(document)
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
rescue ELASTIC_TRANSPORT_CLASS::Transport::Errors::NotFound => e
raise DocumentNotFound, e.message, caller
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module Search
#
def search(query_or_definition, options={})
request = { index: index_name,
type: document_type }
type: document_type }.compact
if query_or_definition.respond_to?(:to_hash)
request[:body] = query_or_definition.to_hash
elsif query_or_definition.is_a?(String)
Expand Down Expand Up @@ -99,7 +99,7 @@ def search(query_or_definition, options={})
def count(query_or_definition=nil, options={})
query_or_definition ||= { query: { match_all: {} } }
request = { index: index_name,
type: document_type }
type: document_type }.compact

if query_or_definition.respond_to?(:to_hash)
request[:body] = query_or_definition.to_hash
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch-persistence/spec/repository/store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def to_hash
it 'raises an exception' do
expect {
repository.update(1, doc: { text: 'testing_2' })
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
}.to raise_exception(ELASTIC_TRANSPORT_CLASS::Transport::Errors::NotFound)
end

context 'when upsert is provided' do
Expand All @@ -262,7 +262,7 @@ def to_hash
it 'raises an exception' do
expect {
repository.update(id: 1, text: 'testing_2')
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
}.to raise_exception(ELASTIC_TRANSPORT_CLASS::Transport::Errors::NotFound)
end

context 'when upsert is provided' do
Expand Down Expand Up @@ -337,7 +337,7 @@ def to_hash
it 'raises an exception' do
expect {
repository.delete(1)
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
}.to raise_exception(ELASTIC_TRANSPORT_CLASS::Transport::Errors::NotFound)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-persistence/spec/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class RepositoryWithoutDSL
it 'raises an error' do
expect {
repository.create_index!
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::BadRequest)
}.to raise_exception(ELASTIC_TRANSPORT_CLASS::Transport::Errors::BadRequest)
end
end
end
Expand Down