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

WIP: Elasticsearch 8.7.x #1056

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions .github/workflows/2.7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
tests:
env:
TEST_ES_SERVER: http://localhost:9200
RAILS_VERSIONS: '5.0,6.0'
RAILS_VERSIONS: '6.0,7.0'
strategy:
fail-fast: false
runs-on: ubuntu-latest
Expand All @@ -27,7 +27,9 @@ jobs:
sudo sysctl -w vm.max_map_count=262144
- uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.x-SNAPSHOT
stack-version: 8.8.0-SNAPSHOT
security-enabled: false
action.destructive_requires_name: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/2.6.yml → .github/workflows/3.2.2.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ruby 2.6
name: Ruby 3.2.2
on:
push:
branches:
Expand All @@ -13,7 +13,7 @@ jobs:
tests:
env:
TEST_ES_SERVER: http://localhost:9200
RAILS_VERSIONS: '5.0,6.0'
RAILS_VERSIONS: '6.0,7.0'
strategy:
fail-fast: false
runs-on: ubuntu-latest
Expand All @@ -27,10 +27,12 @@ jobs:
sudo sysctl -w vm.max_map_count=262144
- uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.x-SNAPSHOT
stack-version: 8.8.0-SNAPSHOT
security-enabled: false
action.destructive_requires_name: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 3.2.2
- name: Bundle
run: |
sudo apt-get install libsqlite3-dev
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/jruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
tests:
env:
TEST_ES_SERVER: http://localhost:9200
RAILS_VERSIONS: '5.0,6.0'
RAILS_VERSIONS: '6.0,7.0'
strategy:
fail-fast: false
runs-on: ubuntu-latest
Expand All @@ -27,10 +27,11 @@ jobs:
sudo sysctl -w vm.max_map_count=262144
- uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 7.x-SNAPSHOT
stack-version: 8.8.0-SNAPSHOT
security-enabled: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: jruby-9.3
ruby-version: jruby-9.4.2.0
- name: Bundle
run: |
sudo apt-get install libsqlite3-dev
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ source 'https://rubygems.org'

gem 'ansi'
gem 'cane'
gem 'elasticsearch', '~> 7'
gem 'elasticsearch', '~> 8.7.0'
gem 'pry'
gem 'rake', '~> 12'

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ You can also unit, integration, or both tests for all sub-projects from the top-

The test suite expects an Elasticsearch cluster running on port 9250, and **will delete all the data**.

```
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "action.destructive_requires_name=false" elasticsearch:8.7.0
```

```
docker run --name mongodb -d mongo:5
```

## License

This software is licensed under the Apache 2 license, quoted below.
Expand Down
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::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
9 changes: 4 additions & 5 deletions elasticsearch-model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,12 @@ Article.__elasticsearch__.create_index! force: true
Article.__elasticsearch__.refresh_index!
```

By default, index name and document type will be inferred from your class name,
By default, index name will be inferred from your class name,
you can set it explicitly, however:

```ruby
class Article
index_name "articles-#{Rails.env}"
document_type "post"
end
```

Expand Down Expand Up @@ -531,7 +530,7 @@ class Indexer
when /delete/
begin
Client.delete index: 'articles', type: 'article', id: record_id
rescue Elasticsearch::Transport::Transport::Errors::NotFound
rescue Elastic::Transport::Transport::Errors::NotFound
logger.debug "Article not found, ID: #{record_id}"
end
else raise ArgumentError, "Unknown operation '#{operation}'"
Expand Down Expand Up @@ -762,9 +761,9 @@ This software is licensed under the Apache 2 license, quoted below.
the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch-model/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ desc 'Run unit tests'
task default: 'test:all'
task test: 'test:all'

gemfiles = ['5.0.gemfile', '6.0.gemfile']
gemfiles = ['5.0.gemfile', '6.0.gemfile', '7.0.gemfile']
gemfiles << '4.0.gemfile' if RUBY_VERSION < '2.7'
GEMFILES = gemfiles.freeze

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.7.0'
s.add_dependency 'hashie'

s.add_development_dependency 'activemodel', '> 3'
Expand Down
35 changes: 35 additions & 0 deletions elasticsearch-model/gemfiles/7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Usage:
#
# $ BUNDLE_GEMFILE=./gemfiles/6.0.gemfile bundle install
# $ BUNDLE_GEMFILE=./gemfiles/6.0.gemfile bundle exec rake test:integration

source 'https://rubygems.org'

gemspec path: '../'

gem 'activemodel', '~> 7.0'
gem 'activerecord', '~> 7.0'
gem 'sqlite3' unless defined?(JRUBY_VERSION)
# gem 'mongoid', '~> 6'

group :development, :testing do
gem 'pry-nav'
gem 'rspec'
end
2 changes: 1 addition & 1 deletion elasticsearch-model/lib/elasticsearch/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module Elasticsearch
# # ...
#
module Model
METHODS = [:search, :mapping, :mappings, :settings, :index_name, :document_type, :import]
METHODS = [:search, :mapping, :mappings, :settings, :index_name, :import]

# Adds the `Elasticsearch::Model` functionality to the including class.
#
Expand Down
2 changes: 0 additions & 2 deletions elasticsearch-model/lib/elasticsearch/model/importing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def import(options={}, &block)
errors = []
refresh = options.delete(:refresh) || false
target_index = options.delete(:index) || index_name
target_type = options.delete(:type) || document_type
transform = options.delete(:transform) || __transform
pipeline = options.delete(:pipeline)
return_value = options.delete(:return) || 'count'
Expand All @@ -161,7 +160,6 @@ def import(options={}, &block)
__find_in_batches(options) do |batch|
params = {
index: target_index,
type: target_type,
body: __batch_to_bulk(batch, transform)
}

Expand Down
13 changes: 4 additions & 9 deletions elasticsearch-model/lib/elasticsearch/model/indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ def as_json(options={})
# Wraps the [index mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)
#
class Mappings
attr_accessor :options, :type
attr_accessor :options

# @private
TYPES_WITH_EMBEDDED_PROPERTIES = %w(object nested)

def initialize(type = nil, options={})
@type = type
def initialize(options={})
@options = options
@mapping = {}
end
Expand Down Expand Up @@ -152,7 +151,7 @@ module ClassMethods
# when it doesn't already define them. Use the `__elasticsearch__` proxy otherwise.
#
def mapping(options={}, &block)
@mapping ||= Mappings.new(document_type, options)
@mapping ||= Mappings.new(options)

@mapping.options.update(options) unless options.empty?

Expand Down Expand Up @@ -290,7 +289,7 @@ def delete_index!(options={})
self.client.indices.delete index: target_index
rescue Exception => e
if e.class.to_s =~ /NotFound/ && options[:force]
client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
nil
else
raise e
Expand Down Expand Up @@ -372,7 +371,6 @@ def index_document(options={})
request = { index: index_name,
id: id,
body: document }
request.merge!(type: document_type) if document_type

client.index(request.merge!(options))
end
Expand All @@ -393,7 +391,6 @@ def index_document(options={})
def delete_document(options={})
request = { index: index_name,
id: self.id }
request.merge!(type: document_type) if document_type

client.delete(request.merge!(options))
end
Expand Down Expand Up @@ -434,7 +431,6 @@ def update_document(options={})
request = { index: index_name,
id: self.id,
body: { doc: attributes } }
request.merge!(type: document_type) if document_type

client.update(request.merge!(options))
end
Expand All @@ -461,7 +457,6 @@ def update_document_attributes(attributes, options={})
request = { index: index_name,
id: self.id,
body: { doc: attributes } }
request.merge!(type: document_type) if document_type

client.update(request.merge!(options))
end
Expand Down
12 changes: 0 additions & 12 deletions elasticsearch-model/lib/elasticsearch/model/multimodel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ def index_name
models.map { |m| m.index_name }
end

# Get an Array of document types used for retrieving documents when doing a search across multiple models
#
# @return [Array] the list of document types used for retrieving documents
#
def document_type
models.map { |m| m.document_type }.compact.presence
end

# Get the client common for all models
#
# @return Elasticsearch::Transport::Client
#
def client
Elasticsearch::Model.client
end
Expand Down
45 changes: 0 additions & 45 deletions elasticsearch-model/lib/elasticsearch/model/naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,6 @@ def index_name=(name)
@index_name = name
end

# Get or set the document type
#
# @example Set the document type for the `Article` model
#
# class Article
# document_type "my-article"
# end
#
# @example Directly set the document type for the `Article` model
#
# Article.document_type "my-article"
#
def document_type name=nil
@document_type = name || @document_type || implicit(:document_type)
end


# Set the document type
#
# @see document_type
#
def document_type=(name)
@document_type = name
end

private

def implicit(prop)
Expand All @@ -98,8 +73,6 @@ def implicit(prop)
def default_index_name
self.model_name.collection.gsub(/\//, '-')
end

def default_document_type; end
end

module InstanceMethods
Expand Down Expand Up @@ -129,25 +102,7 @@ def index_name name=nil, &block
def index_name=(name)
@index_name = name
end

# @example Set the document type for an instance of the `Article` model
#
# @article.document_type "my-article"
# @article.__elasticsearch__.update_document
#
def document_type name=nil
@document_type = name || @document_type || self.class.document_type
end

# Set the document type
#
# @see document_type
#
def document_type=(name)
@document_type = name
end
end

end
end
end
5 changes: 2 additions & 3 deletions elasticsearch-model/lib/elasticsearch/model/searching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def initialize(klass, query_or_payload, options={})
@options = options

__index_name = options[:index] || klass.index_name
__document_type = options[:type] || klass.document_type

case
# search query: ...
Expand All @@ -54,9 +53,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, body: body }.update options
else
@definition = { index: __index_name, type: __document_type, q: q }.update options
@definition = { index: __index_name, q: q }.update options
end
end

Expand Down
Loading