Skip to content

Commit

Permalink
Bumped elasticsearch to 7.x and remove references to ES types which a…
Browse files Browse the repository at this point in the history
…re no longer supported in 7.x+ (#25)

[changelog]

version: unreleased
changed: "Upgrade to elasticsearch ~ 7.x (via #25) (@demsullivan)"
  • Loading branch information
demsullivan authored Jun 5, 2021
1 parent c7535d5 commit db8139e
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/rom/elasticsearch/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def settings
#
# @api public
def mappings
client.indices.get_mapping[index.to_s]['mappings'][type.to_s]
client.indices.get_mapping[index.to_s]['mappings']
end

# Delete everything matching configured params and/or body
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/elasticsearch/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def dataset?(index)
# @api public
def dataset(index)
idx_name = IndexName[index]
Dataset.new(client, params: { index: idx_name.to_sym, type: idx_name.type })
Dataset.new(client, params: { index: idx_name.to_sym })
end
alias_method :[], :dataset
end
Expand Down
16 changes: 3 additions & 13 deletions lib/rom/elasticsearch/index_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,24 @@ class IndexName
# @api private
attr_reader :name

# @api private
attr_reader :types

def self.[](name, types = nil)
def self.[](name)
if name.is_a?(self)
name
else
new(name, types)
new(name)
end
end

# @api private
def initialize(name, types = nil)
def initialize(name)
@name = name
@types = types
freeze
end

# @api private
def type
types ? Array(types).join(',') : Inflector.singularize(name).to_sym
end

# @api private
def to_sym
name
end
end

end
end
5 changes: 2 additions & 3 deletions lib/rom/elasticsearch/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Relation < ROM::Relation
# @return [self]
def self.schema(dataset = nil, multi: false, **opts, &block)
if multi
super(IndexName[:_all, multi_index_types], **opts, &block)
super(IndexName[:_all], **opts, &block)
else
super(dataset, **opts, &block)
end
Expand Down Expand Up @@ -339,7 +339,6 @@ def refresh
def count
dataset.client.count(
index: dataset.index,
type: dataset.type,
body: dataset.body
)['count']
end
Expand Down Expand Up @@ -381,7 +380,7 @@ def index_params
{ index: name.dataset.to_sym,
body: {
settings: self.class.index_settings,
mappings: { dataset.type => { properties: schema.to_properties } } } }
mappings: { properties: schema.to_properties } } }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/elasticsearch/relation/loaded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Loaded < ROM::Relation::Loaded
#
# @api public
def total_hits
response['hits']['total']
response['hits']['total']['value']
end

# Return raw response from the ES client
Expand Down
2 changes: 1 addition & 1 deletion rom-elasticsearch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency 'rom-core', '~> 5.2', '>= 5.2.5'
spec.add_runtime_dependency 'elasticsearch', '~> 6.0'
spec.add_runtime_dependency 'elasticsearch', '~> 7.0'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/rom/elasticsearch/dataset/body_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe ROM::Elasticsearch::Dataset, '#body' do
subject(:dataset) do
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
ROM::Elasticsearch::Dataset.new(client, params: { index: :users })
end

include_context 'user fixtures'
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/rom/elasticsearch/dataset/delete_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe ROM::Elasticsearch::Dataset, '#delete' do
subject(:dataset) do
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
ROM::Elasticsearch::Dataset.new(client, params: { index: :users })
end

include_context 'user fixtures'
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/rom/elasticsearch/dataset/params_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RSpec.describe ROM::Elasticsearch::Dataset, '#params' do
subject(:dataset) do
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
ROM::Elasticsearch::Dataset.new(client, params: { index: :users })
end

include_context 'user fixtures'

it 'returns a new dataset with updated params' do
new_ds = dataset.params(size: 100)

expect(new_ds.params).to eql(size: 100, index: :users, type: :user)
expect(new_ds.params).to eql(size: 100, index: :users)
end
end
2 changes: 1 addition & 1 deletion spec/unit/rom/elasticsearch/dataset/put_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe ROM::Elasticsearch::Dataset, '#put' do
subject(:dataset) do
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
ROM::Elasticsearch::Dataset.new(client, params: { index: :users })
end

include_context 'setup'
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/rom/elasticsearch/dataset/query_string_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe ROM::Elasticsearch::Dataset, '#query_string' do
subject(:dataset) do
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
ROM::Elasticsearch::Dataset.new(client, params: { index: :users })
end

include_context 'user fixtures'
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/rom/elasticsearch/dataset/scroll_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RSpec.describe ROM::Elasticsearch::Dataset, '#scroll' do
subject(:dataset) do
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
ROM::Elasticsearch::Dataset.new(client, params: { index: :users })
end

include_context 'user fixtures'

it 'returns a new dataset with updated params' do
new_ds = dataset.scroll('5m')

expect(new_ds.params).to eql(scroll: '5m', index: :users, type: :user)
expect(new_ds.params).to eql(scroll: '5m', index: :users)
end
end
2 changes: 1 addition & 1 deletion spec/unit/rom/elasticsearch/dataset/search_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe ROM::Elasticsearch::Dataset, '#search' do
subject(:dataset) do
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
ROM::Elasticsearch::Dataset.new(client, params: { index: :users })
end

include_context 'setup'
Expand Down
4 changes: 0 additions & 4 deletions spec/unit/rom/elasticsearch/relation/dataset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
it 'sets up correct index name' do
expect(relation.dataset.index).to eql(:users)
end

it 'sets up default index type' do
expect(relation.dataset.type).to eql(:user)
end
end

context 'overridding default dataset object' do
Expand Down

0 comments on commit db8139e

Please sign in to comment.