Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Merge 8.x into main #1077

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

Merged
picandocodigo merged 38 commits into main from 8.x
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7136c13
Initial work on gemfiles
picandocodigo Jan 19, 2023
8f88d85
Rubocoping: whitespace and styling
picandocodigo Jan 19, 2023
ddbaa7d
Updates gitignore
picandocodigo Jan 19, 2023
3987c66
Updates dependency on elasticsearch gem to 8
picandocodigo Jun 20, 2023
7d52370
Adds debug gem to development/testing
picandocodigo Jun 20, 2023
447e19a
Removing type related code
picandocodigo Jun 20, 2023
7f4144f
Updates elasticsearch-model rake task, fixes dependencies
picandocodigo Jun 21, 2023
83cf958
Updates indexing spec
picandocodigo Jun 22, 2023
dd72ad0
Updates indexing spec
picandocodigo Jun 22, 2023
75466ae
Updates module_spec
picandocodigo Jun 22, 2023
f71d8d2
Updates mongoid spec
picandocodigo Jun 22, 2023
f29a427
Updates adapters/active_record/serialization spec
picandocodigo Jun 22, 2023
9fe214b
Updates parent child specs
picandocodigo Jun 22, 2023
3156f4d
Updates elasticsearch-persistence repository spec
picandocodigo Jun 22, 2023
dbb1031
Removes _type, cleans whitespace in elasticsearch-model
picandocodigo Jun 23, 2023
cee381b
elasticsearch-persistence: Updates to elasticsearch 8, removes type, ...
picandocodigo Jun 23, 2023
7a52668
elasticsearch-persistence: Update calling client transport
picandocodigo Jun 23, 2023
77299ab
elasticsearch-rails: remove type, whitespace cleanup
picandocodigo Jun 23, 2023
a269f45
Bump version to 8.0.0
picandocodigo Jun 23, 2023
7269012
elasticsearch-model: update calling transport in examples
picandocodigo Jun 23, 2023
61048b0
persistence: Updates dependency on model
picandocodigo Jun 27, 2023
893ae39
specs: removes active_record_at_least_4? function and related code
picandocodigo Jun 27, 2023
e2beeec
Adds debug gem
picandocodigo Sep 14, 2023
fc5b584
Whitespace fixes
picandocodigo Sep 14, 2023
11e63d7
Removes more type ocurrances
picandocodigo Sep 14, 2023
9988601
Code Style changes
picandocodigo Sep 14, 2023
1444e2f
Addresses client.transport access
picandocodigo Sep 14, 2023
6c1d7b6
Updates aggregation interval to calendar_interval
picandocodigo Sep 14, 2023
71b5c31
Updates MultiModel tests
picandocodigo Sep 14, 2023
bb6fbe8
[CI] Update GitHub Actions:
picandocodigo Sep 14, 2023
c1ccb4d
Handle security config for ES8
sinisterchipmunk Apr 12, 2024
fb7036d
`ruby2_keywords` is not an instance method
znz Nov 28, 2023
0547374
Test that the model namespace isn't polluted.
sinisterchipmunk Apr 12, 2024
21f992c
Require activesupport/all to more closely mirror a production Rails app.
sinisterchipmunk Apr 12, 2024
6bd63b8
Updates Ruby, Rails, Stack versions for tests
picandocodigo Apr 15, 2024
765d826
[CI] Updates GitHub Actions
picandocodigo Apr 15, 2024
ddfde7a
[DOCS] Updates README
picandocodigo Apr 15, 2024
9f31bfb
[CI] Updates GitHub Actions for JRuby, names
picandocodigo Apr 15, 2024
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
46 changes: 0 additions & 46 deletions .github/workflows/2.7.yml
View file Open in desktop

This file was deleted.

20 changes: 12 additions & 8 deletions .github/workflows/jruby.yml
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
name: JRuby
name: JRuby tests
on:
push:
branches:
- main
- 8.x
pull_request:
branches:
- main
- 8.x
workflow_dispatch:
branches:
- '*'
jobs:
tests:
env:
TEST_ES_SERVER: http://localhost:9200
RAILS_VERSIONS: '5.0,6.0'
RAILS_VERSIONS: ${{ matrix.rails }}
strategy:
fail-fast: false
matrix:
rails: [ '6.1', '7.0', '7.1' ]
ruby: ['jruby-9.4']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Increase system limits
run: |
sudo swapoff -a
Expand All @@ -27,13 +30,14 @@ 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.14.0-SNAPSHOT
security-enabled: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: jruby-9.3
ruby-version: ${{ matrix.ruby }}
- name: Bundle
run: |
sudo apt-get install libsqlite3-dev
sudo apt-get install libsqlite3-dev libcurl4-openssl-dev
gem install bundler
bundle install
bundle exec rake bundle:clean
Expand Down
23 changes: 12 additions & 11 deletions .github/workflows/2.6.yml → .github/workflows/tests.yml
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: Ruby 2.6
name: Ruby tests
on:
push:
branches:
- main
- 8.x
pull_request:
branches:
- main
workflow_dispatch:
branches:
- '*'
- 8.x
jobs:
tests:
env:
TEST_ES_SERVER: http://localhost:9200
RAILS_VERSIONS: '5.0,6.0'
ELASTICSEARCH_URL: http://localhost:9200
RAILS_VERSIONS: ${{ matrix.rails }}
strategy:
fail-fast: false
matrix:
rails: [ '6.1', '7.0', '7.1' ]
ruby: ['3.1', '3.2', '3.3']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Increase system limits
run: |
sudo swapoff -a
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.14.0-SNAPSHOT
security-enabled: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: ${{ matrix.ruby }}
- name: Bundle
run: |
sudo apt-get install libsqlite3-dev
Expand Down
1 change: 1 addition & 0 deletions .gitignore
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage/
rdoc/
doc/
Gemfile.lock
.byebug_history
3 changes: 2 additions & 1 deletion Gemfile
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ source 'https://rubygems.org'

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

group :development do
gem 'debug' unless defined?(JRUBY_VERSION)
gem 'rspec'
gem 'yard'
end
23 changes: 7 additions & 16 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Elasticsearch Rails

[![Ruby 2.7](https://github.com/elastic/elasticsearch-rails/workflows/Ruby%202.7/badge.svg)](https://github.com/elastic/elasticsearch-rails/actions)
[![Ruby 2.6](https://github.com/elastic/elasticsearch-rails/workflows/Ruby%202.6/badge.svg)](https://github.com/elastic/elasticsearch-rails/actions)
[![Ruby 2.5](https://github.com/elastic/elasticsearch-rails/workflows/Ruby%202.5/badge.svg)](https://github.com/elastic/elasticsearch-rails/actions)
[![Ruby 2.4](https://github.com/elastic/elasticsearch-rails/workflows/Ruby%202.4/badge.svg)](https://github.com/elastic/elasticsearch-rails/actions)
[![JRuby](https://github.com/elastic/elasticsearch-rails/workflows/JRuby/badge.svg)](https://github.com/elastic/elasticsearch-rails/actions)
[![Code Climate](https://codeclimate.com/github/elastic/elasticsearch-rails/badges/gpa.svg)](https://codeclimate.com/github/elastic/elasticsearch-rails)
[![Ruby tests](https://github.com/elastic/elasticsearch-rails/actions/workflows/tests.yml/badge.svg)](https://github.com/elastic/elasticsearch-rails/actions/workflows/tests.yml)
[![JRuby tests](https://github.com/elastic/elasticsearch-rails/actions/workflows/jruby.yml/badge.svg)](https://github.com/elastic/elasticsearch-rails/actions/workflows/jruby.yml)

This repository contains various Ruby and Rails integrations for [Elasticsearch](http://elasticsearch.org):

Expand All @@ -29,28 +25,23 @@ Install each library from [Rubygems](https://rubygems.org/gems/elasticsearch):
gem install elasticsearch-model
gem install elasticsearch-rails

To use an unreleased version, add it to your `Gemfile` for [Bundler](http://bundler.io):

```ruby
gem 'elasticsearch-model', github: 'elastic/elasticsearch-rails', branch: '5.x'
gem 'elasticsearch-rails', github: 'elastic/elasticsearch-rails', branch: '5.x'
```

## Compatibility

The libraries are compatible with Ruby 2.4 and higher.
The libraries are compatible with Ruby 3.0 and higher.

We follow Ruby’s own maintenance policy and officially support all currently maintained versions per [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/).

The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `7.x` of the Elasticsearch stack. **We haven't tested and updated the code for Elasticsearch `8.0` yet**.
The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `8.x` of the Elasticsearch stack.

| Rubygem | | Elasticsearch |
|:-------------:|:-:| :-----------: |
| 0.1 | → | 1.x |
| 2.x | → | 2.x |
| 5.x | → | 5.x |
| 6.x | → | 6.x |
| main | → | 7.x |
| 7.x | → | 7.x |
| 8.x | → | 8.x |
| main | → | 8.x |

Check out [Elastic product end of life dates](https://www.elastic.co/support/eol) to learn which releases are still actively supported and tested.

Expand Down
20 changes: 11 additions & 9 deletions Rakefile
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ def admin_client

if test_suite == 'security'
transport_options.merge!(:ssl => { verify: false,
ca_path: CERT_DIR })
ca_path: defined?(CERT_DIR) ? CERT_DIR : nil
}.compact)

password = ENV['ELASTIC_PASSWORD']
user = ENV['ELASTIC_USER'] || 'elastic'
url = "https://#{user}:#{password}@#{host}:#{port}"
url = "https://#{user}:#{password}@#{host || 'localhost'}:#{port || 9200}"
else
url = "http://#{host || 'localhost'}:#{port || 9200}"
end
ENV['ELASTICSEARCH_URL'] ||= url
Elasticsearch::Client.new(host: url, transport_options: transport_options)
end
end
Expand Down Expand Up @@ -140,7 +142,7 @@ namespace :test do
end

desc "Run all tests in all subprojects"
task all: :wait_for_green do
task all: :wait_for_green_or_yellow do
subprojects.each do |project|
puts '-'*80
sh "cd #{project} && " +
Expand All @@ -151,20 +153,20 @@ namespace :test do
end
end

desc "Wait for elasticsearch cluster to be in green state"
task :wait_for_green do
desc "Wait for elasticsearch cluster to be in green or yellow state"
task :wait_for_green_or_yellow do
require 'elasticsearch'

ready = nil
5.times do |i|
begin
puts "Attempting to wait for green status: #{i + 1}"
if admin_client.cluster.health(wait_for_status: 'green', timeout: '50s')
puts "Attempting to wait for green or yellow status: #{i + 1}"
if admin_client.cluster.health(wait_for_status: 'yellow', timeout: '50s')
ready = true
break
end
rescue Elasticsearch::Transport::Transport::Errors::RequestTimeout => ex
puts "Couldn't confirm green status.\n#{ex.inspect}."
rescue Elastic::Transport::Transport::Errors::RequestTimeout => ex
puts "Couldn't confirm green or yellow status.\n#{ex.inspect}."
rescue Faraday::ConnectionFailed => ex
puts "Couldn't connect to Elasticsearch.\n#{ex.inspect}."
sleep(30)
Expand Down
1 change: 1 addition & 0 deletions elasticsearch-model/Gemfile
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ source 'https://rubygems.org'
gemspec

group :development, :testing do
gem 'debug' unless defined?(JRUBY_VERSION)
gem 'pry-nav'
gem 'rspec'
end
35 changes: 17 additions & 18 deletions elasticsearch-model/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ It aims to simplify integration of Ruby classes ("models"), commonly found e.g.

## Compatibility

This library is compatible with Ruby 2.4 and higher.
This library is compatible with Ruby 3 and higher.

The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `7.x` of the Elasticsearch stack. **We haven't tested and updated the code for Elasticsearch `8.0` yet**.

| Rubygem | | Elasticsearch |
|:-------------:|:-:| :-----------: |
| 0.1 | → | 1.x |
| 2.x | → | 2.x |
| 5.x | → | 5.x |
| 6.x | → | 6.x |
| 7.x | → | 7.x |
| main | → | 7.x |
| Rubygem | | Elasticsearch |
|:-------:|:-:|:-------------:|
| 0.1 | → | 1.x |
| 2.x | → | 2.x |
| 5.x | → | 5.x |
| 6.x | → | 6.x |
| 7.x | → | 7.x |
| 8.x | → | 8.x |
| main | → | 8.x |

## Installation

Expand Down Expand Up @@ -268,8 +269,8 @@ It is possible to search across multiple models with the module method:
```ruby
Elasticsearch::Model.search('fox', [Article, Comment]).results.to_a.map(&:to_hash)
# => [
# {"_index"=>"articles", "_type"=>"article", "_id"=>"1", "_score"=>0.35136628, "_source"=>...},
# {"_index"=>"comments", "_type"=>"comment", "_id"=>"1", "_score"=>0.35136628, "_source"=>...}
# {"_index"=>"articles", "_id"=>"1", "_score"=>0.35136628, "_source"=>...},
# {"_index"=>"comments", "_id"=>"1", "_score"=>0.35136628, "_source"=>...}
# ]

Elasticsearch::Model.search('fox', [Article, Comment]).records.to_a
Expand Down Expand Up @@ -414,13 +415,11 @@ Article.__elasticsearch__.create_index! force: true
Article.__elasticsearch__.refresh_index!
```

By default, index name and document type will be inferred from your class name,
you can set it explicitly, however:
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 @@ -528,11 +527,11 @@ class Indexer
case operation.to_s
when /index/
record = Article.find(record_id)
Client.index index: 'articles', type: 'article', id: record.id, body: record.__elasticsearch__.as_indexed_json
Client.index index: 'articles', id: record.id, body: record.__elasticsearch__.as_indexed_json
when /delete/
begin
Client.delete index: 'articles', type: 'article', id: record_id
rescue Elasticsearch::Transport::Transport::Errors::NotFound
Client.delete index: 'articles', id: record_id
rescue Elastic::Transport::Transport::Errors::NotFound
logger.debug "Article not found, ID: #{record_id}"
end
else raise ArgumentError, "Unknown operation '#{operation}'"
Expand All @@ -554,7 +553,7 @@ You'll see the job being processed in the console where you started the _Sidekiq
Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: ["index", "ID: 7"]
Indexer JID-eb7e2daf389a1e5e83697128 INFO: PUT http://localhost:9200/articles/article/1 [status:200, request:0.004s, query:n/a]
Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: > {"id":1,"title":"Updated", ...}
Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: < {"ok":true,"_index":"articles","_type":"article","_id":"1","_version":6}
Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: < {"ok":true,"_index":"articles","_id":"1","_version":6}
Indexer JID-eb7e2daf389a1e5e83697128 INFO: done: 0.006 sec
```

Expand Down
7 changes: 4 additions & 3 deletions elasticsearch-model/Rakefile
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ desc 'Run unit tests'
task default: 'test:all'
task test: 'test:all'

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

namespace :bundle do
Expand All @@ -47,7 +46,7 @@ end
require 'rake/testtask'
namespace :test do
desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
task :all, [:rails_versions] do |task, args|
task :all do |task, args|
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile" } : GEMFILES
puts '-' * 80
gemfiles.each do |gemfile|
Expand All @@ -57,6 +56,8 @@ namespace :test do
puts '-' * 80
end
end

task unit: :all
end

# ----- Documentation tasks ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-model/elasticsearch-model.gemspec
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Gem::Specification.new do |s|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
s.rdoc_options = ['--charset=UTF-8']

s.required_ruby_version = '>= 2.4'
s.required_ruby_version = '>= 3'

s.add_dependency 'activesupport', '> 3'
s.add_dependency 'elasticsearch', '~> 7'
s.add_dependency 'elasticsearch', '~> 8'
s.add_dependency 'hashie'

s.add_development_dependency 'activemodel', '> 3'
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /