Skip to content

Commit 0f66db0

Browse files
committed
feat: add ES 8.x support
1 parent 5605d1f commit 0f66db0

File tree

15 files changed

+41
-19
lines changed

15 files changed

+41
-19
lines changed

.github/workflows/2.6.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
sudo sysctl -w vm.max_map_count=262144
2828
- uses: elastic/elastic-github-actions/elasticsearch@master
2929
with:
30-
stack-version: 7.x-SNAPSHOT
30+
stack-version: 8.4.0-SNAPSHOT
3131
- uses: ruby/setup-ruby@v1
3232
with:
3333
ruby-version: 2.6

.github/workflows/2.7.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
sudo sysctl -w vm.max_map_count=262144
2828
- uses: elastic/elastic-github-actions/elasticsearch@master
2929
with:
30-
stack-version: 7.x-SNAPSHOT
30+
stack-version: 8.4.0-SNAPSHOT
3131
- uses: ruby/setup-ruby@v1
3232
with:
3333
ruby-version: 2.7

.github/workflows/jruby.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
sudo sysctl -w vm.max_map_count=262144
2828
- uses: elastic/elastic-github-actions/elasticsearch@master
2929
with:
30-
stack-version: 7.x-SNAPSHOT
30+
stack-version: 8.4.0-SNAPSHOT
3131
- uses: ruby/setup-ruby@v1
3232
with:
3333
ruby-version: jruby-9.3

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ task :wait_for_green do
163163
ready = true
164164
break
165165
end
166-
rescue Elasticsearch::Transport::Transport::Errors::RequestTimeout => ex
166+
rescue ELASTIC_TRANSPORT_CLASS::Transport::Errors::RequestTimeout => ex
167167
puts "Couldn't confirm green status.\n#{ex.inspect}."
168168
rescue Faraday::ConnectionFailed => ex
169169
puts "Couldn't connect to Elasticsearch.\n#{ex.inspect}."

elasticsearch-model/elasticsearch-model.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
4242
s.required_ruby_version = '>= 2.4'
4343

4444
s.add_dependency 'activesupport', '> 3'
45-
s.add_dependency 'elasticsearch', '~> 7'
45+
s.add_dependency 'elasticsearch', '~> 8'
4646
s.add_dependency 'hashie'
4747

4848
s.add_development_dependency 'activemodel', '> 3'

elasticsearch-model/lib/elasticsearch/model.rb

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::WillPaginate
6262
end
6363

64+
ELASTIC_TRANSPORT_CLASS =
65+
begin
66+
require 'elastic/transport'
67+
Elastic::Transport
68+
rescue LoadError
69+
Elasticsearch::Transport
70+
end
71+
6472
module Elasticsearch
6573

6674
# Elasticsearch integration for Ruby models

elasticsearch-model/lib/elasticsearch/model/importing.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def import(options={}, &block)
163163
index: target_index,
164164
type: target_type,
165165
body: __batch_to_bulk(batch, transform)
166-
}
166+
}.compact
167167

168168
params[:pipeline] = pipeline if pipeline
169169

elasticsearch-model/lib/elasticsearch/model/multimodel.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def document_type
9090

9191
# Get the client common for all models
9292
#
93-
# @return Elasticsearch::Transport::Client
93+
# @return Elastic::Transport::Client
9494
#
9595
def client
9696
Elasticsearch::Model.client

elasticsearch-model/lib/elasticsearch/model/searching.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def initialize(klass, query_or_payload, options={})
5454
end
5555

5656
if body
57-
@definition = { index: __index_name, type: __document_type, body: body }.update options
57+
@definition = { index: __index_name, type: __document_type, body: body }.compact.update options
5858
else
59-
@definition = { index: __index_name, type: __document_type, q: q }.update options
59+
@definition = { index: __index_name, type: __document_type, q: q }.compact.update options
6060
end
6161
end
6262

elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ class ::DummyIndexingModelForRecreate
678678
context 'when the index is not found' do
679679
let(:logger) { nil }
680680
let(:transport) do
681-
Elasticsearch::Transport::Client.new(logger: logger)
681+
ELASTIC_TRANSPORT_CLASS::Client.new(logger: logger)
682682
end
683683

684684
let(:client) do
@@ -918,7 +918,7 @@ class ::DummyIndexingModelForRefresh
918918
end
919919

920920
let(:transport) do
921-
Elasticsearch::Transport::Client.new(logger: nil)
921+
ELASTIC_TRANSPORT_CLASS::Client.new(logger: nil)
922922
end
923923

924924
let(:indices) do
@@ -949,7 +949,7 @@ class ::DummyIndexingModelForRefresh
949949
end
950950

951951
let(:transport) do
952-
Elasticsearch::Transport::Client.new(logger: logger)
952+
ELASTIC_TRANSPORT_CLASS::Client.new(logger: logger)
953953
end
954954

955955
it 'does not raise an exception' do

elasticsearch-persistence/elasticsearch-persistence.gemspec

+14
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ Gem::Specification.new do |s|
3636
s.test_files = s.files.grep(%r{^(test|spec|features)/})
3737
s.require_paths = ['lib']
3838

39+
s.extra_rdoc_files = [ 'README.md', 'LICENSE.txt' ]
40+
s.rdoc_options = [ '--charset=UTF-8' ]
41+
42+
s.required_ruby_version = '>= 1.9.3'
43+
44+
s.add_dependency 'elasticsearch', '~> 8'
45+
s.add_dependency 'elasticsearch-model', '7.2.1'
46+
s.add_dependency 'activesupport', '> 4'
47+
s.add_dependency 'activemodel', '> 4'
48+
s.add_dependency 'hashie'
49+
50+
s.add_development_dependency 'bundler'
51+
s.add_development_dependency 'rake', '~> 12'
52+
3953
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
4054
s.rdoc_options = ['--charset=UTF-8']
4155

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __find_one(id, options={})
8787
request[:type] = document_type if document_type
8888
document = client.get(request.merge(options))
8989
deserialize(document)
90-
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
90+
rescue ELASTIC_TRANSPORT_CLASS::Transport::Errors::NotFound => e
9191
raise DocumentNotFound, e.message, caller
9292
end
9393

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module Search
6161
#
6262
def search(query_or_definition, options={})
6363
request = { index: index_name,
64-
type: document_type }
64+
type: document_type }.compact
6565
if query_or_definition.respond_to?(:to_hash)
6666
request[:body] = query_or_definition.to_hash
6767
elsif query_or_definition.is_a?(String)
@@ -99,7 +99,7 @@ def search(query_or_definition, options={})
9999
def count(query_or_definition=nil, options={})
100100
query_or_definition ||= { query: { match_all: {} } }
101101
request = { index: index_name,
102-
type: document_type }
102+
type: document_type }.compact
103103

104104
if query_or_definition.respond_to?(:to_hash)
105105
request[:body] = query_or_definition.to_hash

elasticsearch-persistence/spec/repository/store_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def to_hash
242242
it 'raises an exception' do
243243
expect {
244244
repository.update(1, doc: { text: 'testing_2' })
245-
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
245+
}.to raise_exception(ELASTIC_TRANSPORT_CLASS::Transport::Errors::NotFound)
246246
end
247247

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

268268
context 'when upsert is provided' do
@@ -337,7 +337,7 @@ def to_hash
337337
it 'raises an exception' do
338338
expect {
339339
repository.delete(1)
340-
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
340+
}.to raise_exception(ELASTIC_TRANSPORT_CLASS::Transport::Errors::NotFound)
341341
end
342342
end
343343
end

elasticsearch-persistence/spec/repository_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class RepositoryWithoutDSL
562562
it 'raises an error' do
563563
expect {
564564
repository.create_index!
565-
}.to raise_exception(Elasticsearch::Transport::Transport::Errors::BadRequest)
565+
}.to raise_exception(ELASTIC_TRANSPORT_CLASS::Transport::Errors::BadRequest)
566566
end
567567
end
568568
end

0 commit comments

Comments
 (0)