From 3d033e839fc6d756c9c1482e661752f87589b281 Mon Sep 17 00:00:00 2001 From: Mihail Pozarski Date: Wed, 1 Jun 2022 14:20:30 -0400 Subject: [PATCH 1/6] chore(Elasticsearch) use version elasticsearch 7.2 --- docker-compose.services.yml | 2 +- elastic-rails.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.services.yml b/docker-compose.services.yml index dd08b64..93b9735 100644 --- a/docker-compose.services.yml +++ b/docker-compose.services.yml @@ -2,7 +2,7 @@ version: '3' services: elasticsearch: - image: elasticsearch:6.7.0 + image: elasticsearch:7.2.0 ports: - 9200 volumes: diff --git a/elastic-rails.gemspec b/elastic-rails.gemspec index 944b295..03838f2 100644 --- a/elastic-rails.gemspec +++ b/elastic-rails.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "elasticsearch", "~> 6.8" + spec.add_dependency "elasticsearch", "~> 7.2" spec.add_dependency "activesupport", [">= 4.0", "< 8.0"] spec.add_development_dependency "dotenv" From 8c1ecfa783a3363ec0a3bc77a702b540e6a7c1c1 Mon Sep 17 00:00:00 2001 From: Mihail Pozarski Date: Wed, 1 Jun 2022 14:22:49 -0400 Subject: [PATCH 2/6] fix(Connector): remove type definition --- lib/elastic/core/connector.rb | 15 ++++++--------- spec/lib/core/connector_spec.rb | 4 +--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/elastic/core/connector.rb b/lib/elastic/core/connector.rb index f1bdf81..30b1177 100644 --- a/lib/elastic/core/connector.rb +++ b/lib/elastic/core/connector.rb @@ -1,7 +1,5 @@ module Elastic::Core class Connector - DEFAULT_TYPE = '_doc' - def initialize(_name, _mapping, settling_time: 10.seconds) @name = _name @mapping = _mapping @@ -56,7 +54,7 @@ def index(_document) # TODO: validate document type operations = write_indices.map do |write_index| - { 'index' => _document.merge('_index' => write_index, '_type' => DEFAULT_TYPE) } + { 'index' => _document.merge('_index' => write_index) } end api.bulk(body: operations) @@ -66,7 +64,7 @@ def bulk_index(_documents) return if Elastic.config.disable_indexing # TODO: validate documents type - body = _documents.map { |doc| { 'index' => doc.merge('_type' => DEFAULT_TYPE) } } + body = _documents.map { |doc| { 'index' => doc } } write_indices.each do |write_index| retry_on_temporary_error('bulk indexing') do @@ -83,12 +81,12 @@ def delete(_document) write_index, rolling_index = write_indices operations = [{ - 'delete' => _document.merge('_index' => write_index, '_type' => DEFAULT_TYPE) + 'delete' => _document.merge('_index' => write_index) }] if rolling_index operations << { - 'delete' => _document.merge('_index' => rolling_index, '_type' => DEFAULT_TYPE) + 'delete' => _document.merge('_index' => rolling_index) } end @@ -243,7 +241,7 @@ def create_from_scratch end def mapping_synchronized?(_index) - type_mappings = api.indices.get_mapping(index: _index, include_type_name: false) + type_mappings = api.indices.get_mapping(index: _index) return false if type_mappings[_index].nil? return false if type_mappings[_index]['mappings'].empty? @@ -256,7 +254,7 @@ def mapping_synchronized?(_index) end def setup_index_mapping(_index) - api.indices.put_mapping(index: _index, type: DEFAULT_TYPE, body: @mapping) + api.indices.put_mapping(index: _index, body: @mapping) end def transfer_alias(_alias, from: nil, to: nil) @@ -274,7 +272,6 @@ def transform_hit_to_create(_hit) { 'create' => { '_id' => _hit['_id'], - '_type' => DEFAULT_TYPE, 'data' => _hit['_source'] } } diff --git a/spec/lib/core/connector_spec.rb b/spec/lib/core/connector_spec.rb index 402b794..cc66a47 100644 --- a/spec/lib/core/connector_spec.rb +++ b/spec/lib/core/connector_spec.rb @@ -255,9 +255,7 @@ def prepare_index(mapping: nil, records: nil) api.indices.put_alias index: actual_index, name: index_name api.indices.put_alias index: actual_index, name: "#{index_name}.w" - if mapping - api.indices.put_mapping index: actual_index, type: '_doc', body: mapping - end + api.indices.put_mapping index: actual_index, body: mapping if mapping if records records.each do |r| From 46fd5c9ecabd9857e182089bfbb92b0be992c5a1 Mon Sep 17 00:00:00 2001 From: Mihail Pozarski Date: Wed, 1 Jun 2022 14:23:33 -0400 Subject: [PATCH 3/6] fix(Connector): remove deprecated ":" from index name --- lib/elastic/core/connector.rb | 4 ++-- spec/lib/core/connector_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/elastic/core/connector.rb b/lib/elastic/core/connector.rb index 30b1177..531c131 100644 --- a/lib/elastic/core/connector.rb +++ b/lib/elastic/core/connector.rb @@ -21,7 +21,7 @@ def status end def drop - api.indices.delete index: "#{index_name}:*" + api.indices.delete index: "#{index_name}_*" nil end @@ -221,7 +221,7 @@ def resolve_actual_index_name end def create_index_w_mapping - new_name = "#{index_name}:#{Time.now.to_i}" + new_name = "#{index_name}_#{Time.now.to_i}" api.indices.create index: new_name api.cluster.health wait_for_status: 'yellow' setup_index_mapping new_name diff --git a/spec/lib/core/connector_spec.rb b/spec/lib/core/connector_spec.rb index cc66a47..a80c902 100644 --- a/spec/lib/core/connector_spec.rb +++ b/spec/lib/core/connector_spec.rb @@ -82,7 +82,7 @@ describe "drop" do it "removes index" do expect { connector.drop } - .to change { api.indices.exists? index: "#{index_name}:12345" }.to false + .to change { api.indices.exists? index: "#{index_name}_12345" }.to false end end @@ -248,7 +248,7 @@ # Some helpers def prepare_index(mapping: nil, records: nil) - actual_index = "#{index_name}:12345" + actual_index = "#{index_name}_12345" api.indices.create index: actual_index api.cluster.health wait_for_status: 'yellow' From 3efc6c8fb8f4420d996301a414aa53466a166780 Mon Sep 17 00:00:00 2001 From: Mihail Pozarski Date: Wed, 1 Jun 2022 14:24:38 -0400 Subject: [PATCH 4/6] fix(TotalPicking): extract value from result total --- lib/elastic/shims/total_picking.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/elastic/shims/total_picking.rb b/lib/elastic/shims/total_picking.rb index 7493575..b544618 100644 --- a/lib/elastic/shims/total_picking.rb +++ b/lib/elastic/shims/total_picking.rb @@ -5,7 +5,7 @@ def handle_result(_raw, _formatter) case result when Elastic::Results::Root - result.total + result.total['value'] when Elastic::Results::GroupedResult result.map_to_group { |bucket| Elastic::Results::Metric.new(bucket.total) } else From 43665e6dfb3ddf76819e3ad445c79fe01f768b7e Mon Sep 17 00:00:00 2001 From: Mihail Pozarski Date: Wed, 1 Jun 2022 14:24:57 -0400 Subject: [PATCH 5/6] fix(BooleanQuery): remove deprecated disable_coord --- lib/elastic/dsl/bool_query_builder.rb | 2 +- lib/elastic/nodes/boolean.rb | 5 +---- spec/lib/nodes/boolean_spec.rb | 7 ------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/elastic/dsl/bool_query_builder.rb b/lib/elastic/dsl/bool_query_builder.rb index 9e4915e..539efea 100644 --- a/lib/elastic/dsl/bool_query_builder.rb +++ b/lib/elastic/dsl/bool_query_builder.rb @@ -1,7 +1,7 @@ module Elastic::Dsl module BoolQueryBuilder def coord_similarity(_enable) - with_bool_query { |query| query.disable_coord = !_enable } + with_bool_query { |query| query } end def must(*_queries) diff --git a/lib/elastic/nodes/boolean.rb b/lib/elastic/nodes/boolean.rb index d1a81e6..a81fbdf 100644 --- a/lib/elastic/nodes/boolean.rb +++ b/lib/elastic/nodes/boolean.rb @@ -10,7 +10,7 @@ def self.build_or(_nodes) new.tap { |n| n.shoulds = _nodes } end - attr_accessor :minimum_should_match, :disable_coord + attr_accessor :minimum_should_match def initialize super @@ -18,7 +18,6 @@ def initialize @must_nots = [] @shoulds = [] @filters = [] - @disable_coord = !Elastic.config.coord_similarity end def must(_node) @@ -82,7 +81,6 @@ def render(_options = {}) hash['should'] = @shoulds.map { |n| n.render(_options) } if !@shoulds.empty? hash['filters'] = @filters.map { |n| n.render(_options) } if !@filters.empty? hash['minimum_should_match'] = minimum_should_match unless minimum_should_match.nil? - hash['disable_coord'] = true if disable_coord render_boost(hash) { "bool" => hash } @@ -123,7 +121,6 @@ def prepare_clone(_clone, _musts, _must_nots, _shoulds, _filters) _clone.shoulds = _shoulds _clone.filters = _filters _clone.minimum_should_match = @minimum_should_match - _clone.disable_coord = @disable_coord _clone end end diff --git a/spec/lib/nodes/boolean_spec.rb b/spec/lib/nodes/boolean_spec.rb index f18621f..242108b 100644 --- a/spec/lib/nodes/boolean_spec.rb +++ b/spec/lib/nodes/boolean_spec.rb @@ -31,13 +31,6 @@ def build_boolean(must: [], must_not: [], should: [], filter: [], boost: nil) let(:single_filter) { build_boolean(filter: [child_a]) } let(:single_must_not) { build_boolean(must_not: [child_a]) } - describe "disable_coord" do - it "is set to true by default if coord_similarity is disabled in configuration" do - expect { Elastic.configure coord_similarity: false } - .to change { build_boolean.disable_coord }.to true - end - end - describe "render" do it "renders correctly" do expect(node.render) From 20fedc6134b84c96a132ce5608d2f0cdcd5fb5be Mon Sep 17 00:00:00 2001 From: Mihail Pozarski Date: Wed, 1 Jun 2022 14:29:47 -0400 Subject: [PATCH 6/6] fix(Query): remove coord_similarity option --- README.md | 2 -- lib/elastic/configuration.rb | 3 +-- lib/elastic/dsl/bool_query_builder.rb | 4 ---- lib/elastic/nested_type.rb | 2 +- lib/elastic/type.rb | 4 ++-- spec/lib/query_spec.rb | 1 - 6 files changed, 4 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fbc8ce9..2d11274 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,6 @@ BikeIndex # More score manipulation: BikeIndex - .coord_similarity(false) # disable coord similarity (no score normalization) .boost(0.0) { must(brand: ['Trek', 'Cannondale']) } # no score .boost(fixed: 1.0) { should(year: 2015) } # fixed score .boost(fixed: 2.0) { should(year: 2016) } @@ -150,4 +149,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/platan ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). - diff --git a/lib/elastic/configuration.rb b/lib/elastic/configuration.rb index 24eced0..7da7fc0 100644 --- a/lib/elastic/configuration.rb +++ b/lib/elastic/configuration.rb @@ -4,7 +4,6 @@ class Configuration host: '127.0.0.1', port: 9200, page_size: 20, - coord_similarity: true, import_batch_size: 10_000, whiny_indices: false, api_client: nil, # set by method @@ -14,7 +13,7 @@ class Configuration disable_index_name_caching: false } - attr_accessor :host, :port, :api_client, :index, :page_size, :coord_similarity, :logger, + attr_accessor :host, :port, :api_client, :index, :page_size, :logger, :import_batch_size, :whiny_indices, :time_zone, :disable_indexing, :disable_index_name_caching def initialize diff --git a/lib/elastic/dsl/bool_query_builder.rb b/lib/elastic/dsl/bool_query_builder.rb index 539efea..2f6e432 100644 --- a/lib/elastic/dsl/bool_query_builder.rb +++ b/lib/elastic/dsl/bool_query_builder.rb @@ -1,9 +1,5 @@ module Elastic::Dsl module BoolQueryBuilder - def coord_similarity(_enable) - with_bool_query { |query| query } - end - def must(*_queries) with_bool_query do |query| node = build_query_from_params(_queries) diff --git a/lib/elastic/nested_type.rb b/lib/elastic/nested_type.rb index bd8377b..16afe1d 100644 --- a/lib/elastic/nested_type.rb +++ b/lib/elastic/nested_type.rb @@ -5,7 +5,7 @@ class NestedType < Types::BaseType class << self extend Forwardable - def_delegators :query, :must, :should, :segment, :coord_similarity + def_delegators :query, :must, :should, :segment end def self.query diff --git a/lib/elastic/type.rb b/lib/elastic/type.rb index 141dab3..cb6e2b1 100644 --- a/lib/elastic/type.rb +++ b/lib/elastic/type.rb @@ -6,8 +6,8 @@ class Type < Types::BaseType class << self extend Forwardable - def_delegators :query, :must, :should, :segment, :stats, :maximum, :minimum, :sum, :average, - :coord_similarity, :limit, :offset, :pluck, :ids, :total + def_delegators :query, :must, :should, :segment, :stats, :maximum, :minimum, :sum, + :average, :limit, :offset, :pluck, :ids, :total end def self.default_suffix diff --git a/spec/lib/query_spec.rb b/spec/lib/query_spec.rb index c0f53ba..3e8c0ba 100644 --- a/spec/lib/query_spec.rb +++ b/spec/lib/query_spec.rb @@ -140,7 +140,6 @@ describe "each_with_score" do it "iterates over matching documents and its scores" do results = query - .coord_similarity(false) .boost(2.0, fixed: true) { should('tags.name' => 'baz_tag') } .boost(3.0, fixed: true) { should('tags.name' => 'qux_tag') }