elasticsearch-rails 7.2.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 041a9dec4e1503685e7ad4ec433c942c6d82880223362836f771993a6da414b7
4
- data.tar.gz: c55ca098f388ebce76c36b8126215b57b4b3b0bdeebd524a89d04f49cb08674a
3
+ metadata.gz: feb6cc50443134d9f6bc424aee2e46edd208f111d98b66e0bcba2c13eed8905f
4
+ data.tar.gz: bc01ddaec5725cc35431e89318eef5d021c8eadb12fe6ae047419adaec82e9d2
5
5
  SHA512:
6
- metadata.gz: c59f6fe732e9466e30190b08370f9ce90682b3738d72a118b7240995a1458d6cfb6d768f7bfd077b55dbb74244ed531a8b1ba528b7805541d12f82e2429d397e
7
- data.tar.gz: 378d3e5a1558925bc5542e1d6a20a526966c16878766738f6b172e8a21e84ca66458c385f15e851c91c0a17a7735ba08fb6ad44318a1e086bbd8f09683abb1fd
6
+ metadata.gz: daba8716f145f0b4ffbb953832eff315c3c09821a1439923fbc9ed8ac7d3e3bd2c6e9dc0a3e37f97b355d2bac828329ef0ee3b23786977d9c96117faed92ab87
7
+ data.tar.gz: d7956874bf60225e7d6d2d520951b446feb32b1b184836e86b8a04592c4d860cedbfd604be143a57d1afaf8be26118ae91dc4c6abf091a409a6556706ffa6a98
data/Gemfile CHANGED
@@ -31,5 +31,8 @@ gem 'elasticsearch-persistence',
31
31
  group :development, :testing do
32
32
  gem 'pry-nav'
33
33
  gem 'rspec'
34
- gem 'sqlite3' unless defined?(JRUBY_VERSION)
34
+ unless defined?(JRUBY_VERSION)
35
+ gem 'sqlite3', '~> 1.4'
36
+ gem 'debug'
37
+ end
35
38
  end
data/README.md CHANGED
@@ -1,24 +1,24 @@
1
1
  # Elasticsearch::Rails
2
2
 
3
3
  The `elasticsearch-rails` library is a companion for the
4
- the [`elasticsearch-model`](https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model)
4
+ the [`elasticsearch-model`](https://github.com/elastic/elasticsearch-rails/tree/main/elasticsearch-model)
5
5
  library, providing features suitable for Ruby on Rails applications.
6
6
 
7
7
  ## Compatibility
8
8
 
9
- This library is compatible with Ruby 1.9.3 and higher.
9
+ This library is compatible with Ruby 3.1 and higher.
10
10
 
11
- The library version numbers follow the Elasticsearch major versions, and the `master` branch
12
- is compatible with the Elasticsearch `master` branch, therefore, with the next major version.
11
+ The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `8.x` of the Elasticsearch stack.
13
12
 
14
- | Rubygem | | Elasticsearch |
15
- |:-------------:|:-:| :-----------: |
16
- | 0.1 | → | 1.x |
17
- | 2.x | → | 2.x |
18
- | 5.x | → | 5.x |
19
- | 6.x | → | 6.x |
20
- | 7.x | → | 7.x |
21
- | master | → | master |
13
+ | Rubygem | | Elasticsearch |
14
+ |:-------:|:-:|:-------------:|
15
+ | 0.1 | → | 1.x |
16
+ | 2.x | → | 2.x |
17
+ | 5.x | → | 5.x |
18
+ | 6.x | → | 6.x |
19
+ | 7.x | → | 7.x |
20
+ | 8.x | → | 8.x |
21
+ | main | → | 8.x |
22
22
 
23
23
  ## Installation
24
24
 
@@ -101,22 +101,22 @@ You should see the duration of the request to Elasticsearch as part of each log
101
101
  You can generate a fully working example Ruby on Rails application, with an `Article` model and a search form,
102
102
  to play with (it generates the application skeleton and leaves you with a _Git_ repository to explore the
103
103
  steps and the code) with the
104
- [`01-basic.rb`](https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/01-basic.rb) template:
104
+ [`01-basic.rb`](https://github.com/elastic/elasticsearch-rails/blob/main/elasticsearch-rails/lib/rails/templates/01-basic.rb) template:
105
105
 
106
106
  ```bash
107
- rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/01-basic.rb
107
+ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/01-basic.rb
108
108
  ```
109
109
 
110
110
  Run the same command again, in the same folder, with the
111
- [`02-pretty`](https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb)
111
+ [`02-pretty`](https://github.com/elastic/elasticsearch-rails/blob/main/elasticsearch-rails/lib/rails/templates/02-pretty.rb)
112
112
  template to add features such as a custom `Article.search` method, result highlighting and
113
113
  [_Bootstrap_](http://getbootstrap.com) integration:
114
114
 
115
115
  ```bash
116
- rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb
116
+ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/02-pretty.rb
117
117
  ```
118
118
 
119
- Run the same command with the [`03-expert.rb`](https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-rails/lib/rails/templates/03-expert.rb)
119
+ Run the same command with the [`03-expert.rb`](https://github.com/elastic/elasticsearch-rails/blob/main/elasticsearch-rails/lib/rails/templates/03-expert.rb)
120
120
  template to refactor the application into a more complex use case,
121
121
  with couple of hundreds of The New York Times articles as the example content.
122
122
  The template will extract the Elasticsearch integration into a `Searchable` "concern" module,
@@ -124,7 +124,7 @@ define complex mapping, custom serialization, implement faceted navigation and s
124
124
  a complex query, and add a _Sidekiq_-based worker for updating the index in the background.
125
125
 
126
126
  ```bash
127
- rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb
127
+ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/03-expert.rb
128
128
  ```
129
129
 
130
130
  ## License
@@ -138,9 +138,9 @@ This software is licensed under the Apache 2 license, quoted below.
138
138
  the Apache License, Version 2.0 (the "License"); you may
139
139
  not use this file except in compliance with the License.
140
140
  You may obtain a copy of the License at
141
-
141
+
142
142
  http://www.apache.org/licenses/LICENSE-2.0
143
-
143
+
144
144
  Unless required by applicable law or agreed to in writing,
145
145
  software distributed under the License is distributed on an
146
146
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
data/Rakefile CHANGED
@@ -34,6 +34,8 @@ namespace :test do
34
34
  test.warning = false
35
35
  test.deps = [:spec] unless defined?(JRUBY_VERSION)
36
36
  end
37
+
38
+ task unit: :spec
37
39
  end
38
40
 
39
41
  namespace :bundle do
@@ -23,15 +23,15 @@ require 'elasticsearch/rails/version'
23
23
  Gem::Specification.new do |s|
24
24
  s.name = 'elasticsearch-rails'
25
25
  s.version = Elasticsearch::Rails::VERSION
26
- s.authors = ['Karel Minarik']
27
- s.email = ['karel.minarik@elasticsearch.org']
26
+ s.authors = ['Elastic Client Library Maintainers']
27
+ s.email = ['client-libs@elastic.co']
28
28
  s.description = 'Ruby on Rails integrations for Elasticsearch.'
29
29
  s.summary = 'Ruby on Rails integrations for Elasticsearch.'
30
30
  s.homepage = 'https://github.com/elasticsearch/elasticsearch-rails/'
31
31
  s.license = 'Apache 2'
32
32
  s.metadata = {
33
33
  'homepage_uri' => 'https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/ruby_on_rails.html',
34
- 'changelog_uri' => 'https://github.com/elastic/elasticsearch-rails/blob/master/CHANGELOG.md',
34
+ 'changelog_uri' => 'https://github.com/elastic/elasticsearch-rails/blob/main/CHANGELOG.md',
35
35
  'source_code_uri' => 'https://github.com/elastic/elasticsearch-rails/',
36
36
  'bug_tracker_uri' => 'https://github.com/elastic/elasticsearch-rails/issues'
37
37
  }
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
45
45
  s.rdoc_options = ['--charset=UTF-8']
46
46
 
47
- s.required_ruby_version = '>= 2.4'
47
+ s.required_ruby_version = '>= 3'
48
48
 
49
49
  s.add_development_dependency 'bundler'
50
50
  s.add_development_dependency 'cane'
@@ -46,8 +46,19 @@ module Elasticsearch
46
46
  payload = event.payload
47
47
  name = "#{payload[:klass]} #{payload[:name]} (#{event.duration.round(1)}ms)"
48
48
  search = payload[:search].inspect.gsub(/:(\w+)=>/, '\1: ')
49
+ debug %Q| #{color(name, GREEN, color_option(true))} #{colorize_logging ? "\e[2m#{search}\e[0m" : search}|
50
+ end
51
+
52
+ private
53
+
54
+ def color_option(bold_value)
55
+ new_color_syntax? ? { bold: bold_value } : bold_value
56
+ end
57
+
58
+ def new_color_syntax?
59
+ return @new_color_syntax if defined?(@new_color_syntax)
49
60
 
50
- debug %Q| #{color(name, GREEN, true)} #{colorize_logging ? "\e[2m#{search}\e[0m" : search}|
61
+ @new_color_syntax = ::Rails.respond_to?(:gem_version) && ::Rails.gem_version >= '7.1'
51
62
  end
52
63
  end
53
64
 
@@ -57,7 +57,7 @@ namespace :elasticsearch do
57
57
  $ rake environment elasticsearch:import:model CLASS='Article' SCOPE='published'
58
58
  DESC
59
59
  desc import_model_desc
60
- task :model do
60
+ task model: :environment do
61
61
  if ENV['CLASS'].to_s == ''
62
62
  puts '='*90, 'USAGE', '='*90, import_model_desc, ""
63
63
  exit(1)
@@ -97,7 +97,7 @@ namespace :elasticsearch do
97
97
 
98
98
  $ rake environment elasticsearch:import:all DIR=app/models
99
99
  DESC
100
- task :all do
100
+ task all: :environment do
101
101
  dir = ENV['DIR'].to_s != '' ? ENV['DIR'] : Rails.root.join("app/models")
102
102
 
103
103
  puts "[IMPORT] Loading models from: #{dir}"
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Rails
20
- VERSION = "7.2.0"
20
+ VERSION = '8.0.0'.freeze
21
21
  end
22
22
  end
@@ -32,7 +32,7 @@
32
32
  # Usage:
33
33
  # ------
34
34
  #
35
- # $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/01-basic.rb
35
+ # $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/01-basic.rb
36
36
  #
37
37
  # =====================================================================================================
38
38
 
@@ -112,7 +112,7 @@ This application is an example of integrating the {Elasticsearch}[https://www.el
112
112
  search engine with the {Ruby On Rails}[http://rubyonrails.org] web framework.
113
113
 
114
114
  It has been generated by application templates available at
115
- https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-rails/lib/rails/templates.
115
+ https://github.com/elasticsearch/elasticsearch-rails/tree/main/elasticsearch-rails/lib/rails/templates.
116
116
 
117
117
  ## [1] Basic
118
118
 
@@ -157,8 +157,8 @@ say_status "Rubygems", "Adding Elasticsearch libraries into Gemfile...\n", :yel
157
157
  puts '-'*80, ''; sleep 0.75
158
158
 
159
159
  gem 'elasticsearch'
160
- gem 'elasticsearch-model', git: 'https://github.com/elasticsearch/elasticsearch-rails.git'
161
- gem 'elasticsearch-rails', git: 'https://github.com/elasticsearch/elasticsearch-rails.git'
160
+ gem 'elasticsearch-model', git: 'https://github.com/elasticsearch/elasticsearch-rails.git', branch: 'main'
161
+ gem 'elasticsearch-rails', git: 'https://github.com/elasticsearch/elasticsearch-rails.git', branch: 'main'
162
162
 
163
163
 
164
164
  git add: "Gemfile*"
@@ -15,7 +15,7 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- # $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb
18
+ # $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/02-pretty.rb
19
19
 
20
20
  unless File.read('README.md').include? '## [1] Basic'
21
21
  say_status "ERROR", "You have to run the 01-basic.rb template first.", :red
@@ -15,7 +15,7 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- # $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb
18
+ # $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/03-expert.rb
19
19
 
20
20
  unless File.read('README.md').include? '## [2] Pretty'
21
21
  say_status "ERROR", "You have to run the 01-basic.rb and 02-pretty.rb templates first.", :red
@@ -181,7 +181,7 @@ CODE
181
181
  gsub_file "test/models/article_test.rb", %r{assert_equal 'foo', definition\[:query\]\[:multi_match\]\[:query\]}, "assert_equal 'foo', definition.to_hash[:query][:bool][:should][0][:multi_match][:query]"
182
182
 
183
183
  # copy_file File.expand_path('../searchable.rb', __FILE__), 'app/models/concerns/searchable.rb'
184
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/searchable.rb', 'app/models/concerns/searchable.rb'
184
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/searchable.rb', 'app/models/concerns/searchable.rb'
185
185
 
186
186
  insert_into_file "app/models/article.rb", after: "ActiveRecord::Base" do
187
187
  <<-CODE
@@ -209,7 +209,7 @@ gem "sidekiq"
209
209
  run "bundle install"
210
210
 
211
211
  # copy_file File.expand_path('../indexer.rb', __FILE__), 'app/workers/indexer.rb'
212
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/indexer.rb', 'app/workers/indexer.rb'
212
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/indexer.rb', 'app/workers/indexer.rb'
213
213
 
214
214
  insert_into_file "test/test_helper.rb",
215
215
  "require 'sidekiq/testing'\n\n",
@@ -244,16 +244,16 @@ create_file 'app/controllers/search_controller.rb' do
244
244
  end
245
245
 
246
246
  # copy_file File.expand_path('../search_controller_test.rb', __FILE__), 'test/controllers/search_controller_test.rb'
247
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/search_controller_test.rb', 'test/controllers/search_controller_test.rb'
247
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/search_controller_test.rb', 'test/controllers/search_controller_test.rb'
248
248
 
249
249
  route "get '/search', to: 'search#index', as: 'search'"
250
250
  gsub_file 'config/routes.rb', %r{root to: 'articles#index'$}, "root to: 'search#index'"
251
251
 
252
252
  # copy_file File.expand_path('../index.html.erb', __FILE__), 'app/views/search/index.html.erb'
253
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/index.html.erb', 'app/views/search/index.html.erb'
253
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/index.html.erb', 'app/views/search/index.html.erb'
254
254
 
255
255
  # copy_file File.expand_path('../search.css', __FILE__), 'app/assets/stylesheets/search.css'
256
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/search.css', 'app/assets/stylesheets/search.css'
256
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/search.css', 'app/assets/stylesheets/search.css'
257
257
 
258
258
  git add: "app/controllers/ test/controllers/ config/routes.rb"
259
259
  git add: "app/views/search/ app/assets/stylesheets/search.css"
@@ -315,11 +315,11 @@ say_status "Database", "Re-creating the database with data and importing into E
315
315
  puts '-'*80, ''; sleep 0.25
316
316
 
317
317
  # copy_file File.expand_path('../articles.yml.gz', __FILE__), 'db/articles.yml.gz'
318
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/articles.yml.gz', 'db/articles.yml.gz'
318
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/articles.yml.gz', 'db/articles.yml.gz'
319
319
 
320
320
  remove_file 'db/seeds.rb'
321
321
  # copy_file File.expand_path('../seeds.rb', __FILE__), 'db/seeds.rb'
322
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/seeds.rb', 'db/seeds.rb'
322
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/seeds.rb', 'db/seeds.rb'
323
323
 
324
324
  rake "db:reset"
325
325
  rake "environment elasticsearch:import:model CLASS='Article' BATCH=100 FORCE=y"
@@ -15,7 +15,7 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- # $ rails new searchapp --skip --skip-bundle --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/04-dsl.rb
18
+ # $ rails new searchapp --skip --skip-bundle --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/04-dsl.rb
19
19
 
20
20
  unless File.read('README.md').include? '## [3] Expert'
21
21
  say_status "ERROR", "You have to run the 01-basic.rb, 02-pretty.rb and 03-expert.rb templates first.", :red
@@ -27,7 +27,7 @@ append_to_file 'README.md', <<-README
27
27
  ## [4] DSL
28
28
 
29
29
  The `dsl` template refactors the search definition in SearchController#index
30
- to use the [`elasticsearch-dsl`](https://github.com/elastic/elasticsearch-ruby/tree/dsl/elasticsearch-dsl)
30
+ to use the [`elasticsearch-dsl`](https://github.com/elastic/elasticsearch-dsl-ruby)
31
31
  Rubygem for better expresivity and readability of the code.
32
32
 
33
33
  README
@@ -44,7 +44,7 @@ puts
44
44
  say_status "Rubygems", "Adding Rubygems into Gemfile...\n", :yellow
45
45
  puts '-'*80, ''; sleep 0.25
46
46
 
47
- gem "elasticsearch-dsl", git: "git://github.com/elastic/elasticsearch-ruby.git"
47
+ gem "elasticsearch-dsl", git: "git://github.com/elastic/elasticsearch-dsl-ruby.git"
48
48
 
49
49
  git add: "Gemfile*"
50
50
  git commit: "-m 'Added the `elasticsearch-dsl` gem'"
@@ -56,10 +56,10 @@ run "bundle install"
56
56
  # ----- Change the search definition implementation and associated views and tests ----------------
57
57
 
58
58
  # copy_file File.expand_path('../searchable.dsl.rb', __FILE__), 'app/models/concerns/searchable.rb', force: true
59
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/searchable.dsl.rb', 'app/models/concerns/searchable.rb', force: true
59
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/searchable.dsl.rb', 'app/models/concerns/searchable.rb', force: true
60
60
 
61
61
  # copy_file File.expand_path('../index.html.dsl.erb', __FILE__), 'app/views/search/index.html.erb', force: true
62
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/index.html.dsl.erb', 'app/views/search/index.html.erb', force: true
62
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/index.html.dsl.erb', 'app/views/search/index.html.erb', force: true
63
63
 
64
64
  gsub_file "test/controllers/search_controller_test.rb", %r{test "should return facets" do.*?end}m, <<-CODE
65
65
  test "should return aggregations" do
@@ -15,7 +15,7 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- # $ rails new searchapp --skip --skip-bundle --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/05-settings-files.rb
18
+ # $ rails new searchapp --skip --skip-bundle --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/05-settings-files.rb
19
19
 
20
20
  # (See: 01-basic.rb, 02-pretty.rb, 03-expert.rb, 04-dsl.rb)
21
21
 
@@ -43,7 +43,7 @@ git commit: "-m 'Setup the Searchable module to load settings from file'"
43
43
  # ----- Copy the articles_settings.json file -------------------------------------------------------
44
44
 
45
45
  # copy_file File.expand_path('../articles_settings.json', __FILE__), 'config/elasticsearch/articles_settings.json'
46
- get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/articles_settings.json',
46
+ get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/main/elasticsearch-rails/lib/rails/templates/articles_settings.json',
47
47
  'config/elasticsearch/articles_settings.json', force: true
48
48
 
49
49
  git add: "config/elasticsearch/articles_settings.json"
@@ -37,7 +37,7 @@ class Indexer
37
37
  record.__elasticsearch__.client = Client
38
38
  record.__elasticsearch__.__send__ "#{operation}_document"
39
39
  when /delete/
40
- Client.delete index: klass.constantize.index_name, type: klass.constantize.document_type, id: record_id
40
+ Client.delete index: klass.constantize.index_name, id: record_id
41
41
  else raise ArgumentError, "Unknown operation '#{operation}'"
42
42
  end
43
43
  end
@@ -0,0 +1,57 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ require 'spec_helper'
19
+ require 'elasticsearch/rails/instrumentation/log_subscriber'
20
+
21
+ describe Elasticsearch::Rails::Instrumentation::LogSubscriber do
22
+ subject(:instance) { described_class.new }
23
+
24
+ let(:logger) { instance_double(Logger) }
25
+
26
+ before do
27
+ allow(instance).to receive(:logger) { logger }
28
+ end
29
+
30
+ describe "#search" do
31
+ subject { instance.search(event) }
32
+
33
+ let(:event) { double("search.elasticsearch", duration: 1.2345, payload: { name: "execute", search: { query: { match_all: {}}}}) }
34
+
35
+ it "logs the event" do
36
+ expect(instance).to receive(:color).with(" execute (1.2ms)", described_class::GREEN, { bold: true }).and_call_original
37
+ expect(logger).to receive(:debug?) { true }
38
+ expect(logger).to receive(:debug).with(" \e[1m\e[32m execute (1.2ms)\e[0m \e[2m{query: {match_all: {}}}\e[0m")
39
+ subject
40
+ end
41
+
42
+ context "when Rails version is older" do
43
+ let(:rails_version) { "7.0.0" }
44
+
45
+ before do
46
+ allow(::Rails).to receive(:gem_version) { Gem::Version.new(rails_version) }
47
+ end
48
+
49
+ it "logs the event" do
50
+ expect(instance).to receive(:color).with(" execute (1.2ms)", described_class::GREEN, true).and_call_original
51
+ expect(logger).to receive(:debug?) { true }
52
+ expect(logger).to receive(:debug).with(" \e[1m\e[32m execute (1.2ms)\e[0m \e[2m{query: {match_all: {}}}\e[0m")
53
+ subject
54
+ end
55
+ end
56
+ end
57
+ end
@@ -18,13 +18,10 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe 'ActiveSupport::Instrumentation integration' do
21
-
22
21
  before(:all) do
23
22
  class DummyInstrumentationModel
24
23
  extend Elasticsearch::Model::Searching::ClassMethods
25
-
26
- def self.index_name; 'foo'; end
27
- def self.document_type; 'bar'; end
24
+ def self.index_name; 'foo'; end
28
25
  end
29
26
  end
30
27
 
@@ -33,10 +30,14 @@ describe 'ActiveSupport::Instrumentation integration' do
33
30
  end
34
31
 
35
32
  let(:response_document) do
36
- { 'took' => '5ms',
37
- 'hits' => { 'total' => 123,
38
- 'max_score' => 456,
39
- 'hits' => [] } }
33
+ {
34
+ 'took' => '5ms',
35
+ 'hits' => {
36
+ 'total' => 123,
37
+ 'max_score' => 456,
38
+ 'hits' => []
39
+ }
40
+ }
40
41
  end
41
42
 
42
43
  let(:search) do
@@ -53,7 +54,6 @@ describe 'ActiveSupport::Instrumentation integration' do
53
54
  end
54
55
 
55
56
  context 'SearchRequest#execute!' do
56
-
57
57
  it 'wraps the method with instrumentation' do
58
58
  expect(search).to respond_to(:execute_without_instrumentation!)
59
59
  expect(search).to respond_to(:execute_with_instrumentation!)
@@ -61,14 +61,19 @@ describe 'ActiveSupport::Instrumentation integration' do
61
61
  end
62
62
 
63
63
  context 'Model#search' do
64
-
65
64
  before do
66
- expect(ActiveSupport::Notifications).to receive(:instrument).with('search.elasticsearch',
67
- { klass: 'DummyInstrumentationModel',
68
- name: 'Search',
69
- search: { body: query,
70
- index: 'foo',
71
- type: 'bar' } }).and_return({})
65
+ expect(ActiveSupport::Notifications).
66
+ to receive(:instrument).
67
+ with('search.elasticsearch',
68
+ {
69
+ klass: 'DummyInstrumentationModel',
70
+ name: 'Search',
71
+ search: {
72
+ body: query,
73
+ index: 'foo',
74
+ }
75
+ }
76
+ ).and_return({})
72
77
  end
73
78
 
74
79
  let(:query) do
data/spec/lograge_spec.rb CHANGED
@@ -38,14 +38,15 @@ require 'lograge'
38
38
  require 'elasticsearch/rails/lograge'
39
39
 
40
40
  describe 'ActiveSupport::Instrumentation integration' do
41
-
42
41
  before do
43
42
  Elasticsearch::Rails::Lograge::Railtie.run_initializers
44
43
  end
45
44
 
46
45
  it 'customizes the Lograge configuration' do
47
- expect(Elasticsearch::Rails::Lograge::Railtie.initializers
48
- .select { |i| i.name == 'elasticsearch.lograge' }
49
- .first).not_to be_nil
46
+ expect(
47
+ Elasticsearch::Rails::Lograge::Railtie.initializers
48
+ .select { |i| i.name == 'elasticsearch.lograge' }
49
+ .first
50
+ ).not_to be_nil
50
51
  end
51
52
  end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,7 @@ require 'active_record'
20
20
  require 'elasticsearch/model'
21
21
  require 'elasticsearch/rails'
22
22
  require 'rails/railtie'
23
+ require 'rails/version'
23
24
  require 'elasticsearch/rails/instrumentation'
24
25
 
25
26
 
@@ -36,7 +37,8 @@ RSpec.configure do |config|
36
37
  tracer = ::Logger.new(STDERR)
37
38
  tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
38
39
  Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
39
- tracer: (ENV['QUIET'] ? nil : tracer)
40
+ tracer: (ENV['QUIET'] ? nil : tracer),
41
+ transport_options: { :ssl => { verify: false } }
40
42
  puts "Elasticsearch Version: #{Elasticsearch::Model.client.info['version']}"
41
43
 
42
44
  unless ActiveRecord::Base.connected?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.0
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Karel Minarik
7
+ - Elastic Client Library Maintainers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-11 00:00:00.000000000 Z
11
+ date: 2024-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -236,7 +236,7 @@ dependencies:
236
236
  version: '0'
237
237
  description: Ruby on Rails integrations for Elasticsearch.
238
238
  email:
239
- - karel.minarik@elasticsearch.org
239
+ - client-libs@elastic.co
240
240
  executables: []
241
241
  extensions: []
242
242
  extra_rdoc_files:
@@ -275,6 +275,7 @@ files:
275
275
  - lib/rails/templates/searchable.dsl.rb
276
276
  - lib/rails/templates/searchable.rb
277
277
  - lib/rails/templates/seeds.rb
278
+ - spec/instrumentation/log_subscriber_spec.rb
278
279
  - spec/instrumentation_spec.rb
279
280
  - spec/lograge_spec.rb
280
281
  - spec/spec_helper.rb
@@ -283,7 +284,7 @@ licenses:
283
284
  - Apache 2
284
285
  metadata:
285
286
  homepage_uri: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/ruby_on_rails.html
286
- changelog_uri: https://github.com/elastic/elasticsearch-rails/blob/master/CHANGELOG.md
287
+ changelog_uri: https://github.com/elastic/elasticsearch-rails/blob/main/CHANGELOG.md
287
288
  source_code_uri: https://github.com/elastic/elasticsearch-rails/
288
289
  bug_tracker_uri: https://github.com/elastic/elasticsearch-rails/issues
289
290
  post_install_message:
@@ -295,18 +296,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
295
296
  requirements:
296
297
  - - ">="
297
298
  - !ruby/object:Gem::Version
298
- version: '2.4'
299
+ version: '3'
299
300
  required_rubygems_version: !ruby/object:Gem::Requirement
300
301
  requirements:
301
302
  - - ">="
302
303
  - !ruby/object:Gem::Version
303
304
  version: '0'
304
305
  requirements: []
305
- rubygems_version: 3.1.6
306
+ rubygems_version: 3.5.9
306
307
  signing_key:
307
308
  specification_version: 4
308
309
  summary: Ruby on Rails integrations for Elasticsearch.
309
310
  test_files:
311
+ - spec/instrumentation/log_subscriber_spec.rb
310
312
  - spec/instrumentation_spec.rb
311
313
  - spec/lograge_spec.rb
312
314
  - spec/spec_helper.rb