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/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" 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/core/connector.rb b/lib/elastic/core/connector.rb index f1bdf81..531c131 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 @@ -23,7 +21,7 @@ def status end def drop - api.indices.delete index: "#{index_name}:*" + api.indices.delete index: "#{index_name}_*" nil end @@ -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 @@ -223,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 @@ -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/lib/elastic/dsl/bool_query_builder.rb b/lib/elastic/dsl/bool_query_builder.rb index 9e4915e..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.disable_coord = !_enable } - 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/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/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 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/core/connector_spec.rb b/spec/lib/core/connector_spec.rb index 402b794..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,16 +248,14 @@ # 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' 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| 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) 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') }