chewy 0.10.1 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +240 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- data/.rubocop.yml +25 -25
- data/Appraisals +12 -10
- data/CHANGELOG.md +312 -331
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +5 -1
- data/LICENSE.txt +1 -1
- data/README.md +143 -77
- data/chewy.gemspec +10 -12
- data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.5.2.activerecord.gemfile} +6 -4
- data/gemfiles/{rails.4.2.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +6 -4
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.6.0.activerecord.gemfile} +6 -3
- data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
- data/gemfiles/sequel.4.45.gemfile +2 -2
- data/lib/chewy.rb +2 -1
- data/lib/chewy/backports/duplicable.rb +1 -1
- data/lib/chewy/config.rb +10 -39
- data/lib/chewy/fields/base.rb +9 -3
- data/lib/chewy/fields/root.rb +13 -9
- data/lib/chewy/index.rb +3 -1
- data/lib/chewy/index/actions.rb +28 -16
- data/lib/chewy/index/aliases.rb +16 -5
- data/lib/chewy/index/settings.rb +2 -0
- data/lib/chewy/index/specification.rb +12 -10
- data/lib/chewy/minitest/helpers.rb +6 -6
- data/lib/chewy/minitest/search_index_receiver.rb +17 -17
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +3 -5
- data/lib/chewy/rake_helper.rb +5 -5
- data/lib/chewy/rspec/update_index.rb +3 -5
- data/lib/chewy/search.rb +4 -11
- data/lib/chewy/search/loader.rb +1 -1
- data/lib/chewy/search/pagination/will_paginate.rb +1 -1
- data/lib/chewy/search/parameters.rb +24 -6
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
- data/lib/chewy/search/parameters/indices.rb +123 -0
- data/lib/chewy/search/parameters/none.rb +1 -3
- data/lib/chewy/search/request.rb +101 -74
- data/lib/chewy/search/scrolling.rb +7 -6
- data/lib/chewy/stash.rb +31 -22
- data/lib/chewy/strategy/active_job.rb +1 -1
- data/lib/chewy/strategy/atomic.rb +1 -1
- data/lib/chewy/strategy/sidekiq.rb +1 -1
- data/lib/chewy/type.rb +5 -2
- data/lib/chewy/type/adapter/active_record.rb +1 -1
- data/lib/chewy/type/adapter/base.rb +9 -9
- data/lib/chewy/type/adapter/mongoid.rb +2 -4
- data/lib/chewy/type/adapter/orm.rb +7 -4
- data/lib/chewy/type/adapter/sequel.rb +5 -7
- data/lib/chewy/type/crutch.rb +1 -1
- data/lib/chewy/type/import.rb +16 -5
- data/lib/chewy/type/import/bulk_builder.rb +1 -1
- data/lib/chewy/type/import/bulk_request.rb +4 -2
- data/lib/chewy/type/import/journal_builder.rb +3 -3
- data/lib/chewy/type/import/routine.rb +3 -3
- data/lib/chewy/type/mapping.rb +42 -36
- data/lib/chewy/type/observe.rb +16 -12
- data/lib/chewy/type/syncer.rb +6 -7
- data/lib/chewy/type/witchcraft.rb +5 -3
- data/lib/chewy/type/wrapper.rb +14 -4
- data/lib/chewy/version.rb +1 -1
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/migration_guide.md +34 -0
- data/spec/chewy/config_spec.rb +16 -21
- data/spec/chewy/fields/base_spec.rb +68 -70
- data/spec/chewy/fields/root_spec.rb +13 -13
- data/spec/chewy/index/actions_spec.rb +157 -38
- data/spec/chewy/index/aliases_spec.rb +3 -3
- data/spec/chewy/index/specification_spec.rb +25 -16
- data/spec/chewy/index_spec.rb +75 -45
- data/spec/chewy/journal_spec.rb +33 -29
- data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
- data/spec/chewy/multi_search_spec.rb +85 -0
- data/spec/chewy/rake_helper_spec.rb +123 -95
- data/spec/chewy/rspec/update_index_spec.rb +47 -46
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/parameters/indices_spec.rb +190 -0
- data/spec/chewy/search/parameters/none_spec.rb +1 -1
- data/spec/chewy/search/parameters_spec.rb +21 -4
- data/spec/chewy/search/request_spec.rb +103 -70
- data/spec/chewy/search/response_spec.rb +27 -17
- data/spec/chewy/search/scrolling_spec.rb +27 -17
- data/spec/chewy/search_spec.rb +49 -35
- data/spec/chewy/stash_spec.rb +15 -13
- data/spec/chewy/strategy/active_job_spec.rb +15 -2
- data/spec/chewy/strategy/shoryuken_spec.rb +8 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
- data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
- data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
- data/spec/chewy/type/import/journal_builder_spec.rb +17 -15
- data/spec/chewy/type/import_spec.rb +15 -0
- data/spec/chewy/type/mapping_spec.rb +51 -18
- data/spec/chewy/type/observe_spec.rb +4 -4
- data/spec/chewy/type/witchcraft_spec.rb +15 -0
- data/spec/chewy/type/wrapper_spec.rb +3 -1
- data/spec/chewy_spec.rb +0 -7
- data/spec/spec_helper.rb +5 -1
- data/spec/support/active_record.rb +21 -0
- metadata +51 -116
- data/.travis.yml +0 -53
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.0.mongoid.6.0.gemfile +0 -15
- data/gemfiles/rails.5.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.1.mongoid.6.1.gemfile +0 -15
- data/lib/chewy/query.rb +0 -1098
- data/lib/chewy/query/compose.rb +0 -68
- data/lib/chewy/query/criteria.rb +0 -191
- data/lib/chewy/query/filters.rb +0 -227
- data/lib/chewy/query/loading.rb +0 -111
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -34
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -110
- data/lib/chewy/query/nodes/has_child.rb +0 -15
- data/lib/chewy/query/nodes/has_parent.rb +0 -15
- data/lib/chewy/query/nodes/has_relation.rb +0 -59
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -19
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -35
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination.rb +0 -25
- data/spec/chewy/query/criteria_spec.rb +0 -700
- data/spec/chewy/query/filters_spec.rb +0 -201
- data/spec/chewy/query/loading_spec.rb +0 -124
- data/spec/chewy/query/nodes/and_spec.rb +0 -12
- data/spec/chewy/query/nodes/bool_spec.rb +0 -14
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -16
- data/spec/chewy/query/nodes/not_spec.rb +0 -13
- data/spec/chewy/query/nodes/or_spec.rb +0 -12
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
- data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
- data/spec/chewy/query/pagination_spec.rb +0 -39
- data/spec/chewy/query_spec.rb +0 -636
- data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# The Chewy Community Code of Conduct
|
2
|
+
|
3
|
+
**Note:** We have picked the following code of conduct based on [Ruby's own code of conduct](https://www.ruby-lang.org/en/conduct/).
|
4
|
+
|
5
|
+
This document provides a few simple community guidelines for a safe, respectful,
|
6
|
+
productive, and collaborative place for any person who is willing to contribute
|
7
|
+
to the Chewy community. It applies to all "collaborative spaces", which are
|
8
|
+
defined as community communications channels (such as mailing lists, submitted
|
9
|
+
patches, commit comments, etc.).
|
10
|
+
|
11
|
+
* Participants will be tolerant of opposing views.
|
12
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
13
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
14
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
If you discover issues, have ideas for improvements or new features,
|
4
|
+
please report them to the [issue tracker][1] of the repository or
|
5
|
+
submit a pull request. Please, try to follow these guidelines when you
|
6
|
+
do so.
|
7
|
+
|
8
|
+
## Issue reporting
|
9
|
+
|
10
|
+
* Check that the issue has not already been reported.
|
11
|
+
* Check that the issue has not already been fixed in the latest code
|
12
|
+
(a.k.a. `master`).
|
13
|
+
* Be clear, concise and precise in your description of the problem.
|
14
|
+
* Open an issue with a descriptive title and a summary in grammatically correct,
|
15
|
+
complete sentences.
|
16
|
+
* Include the versions of Chewy, Elasticsearch, Ruby, Rails, etc.
|
17
|
+
* Include any relevant code to the issue summary.
|
18
|
+
|
19
|
+
## Pull requests
|
20
|
+
|
21
|
+
* Read [how to properly contribute to open source projects on GitHub][2].
|
22
|
+
* Fork the project.
|
23
|
+
* Use a topic/feature branch to easily amend a pull request later, if necessary.
|
24
|
+
* Write [good commit messages][3].
|
25
|
+
* Use the same coding conventions as the rest of the project.
|
26
|
+
* Commit and push until you are happy with your contribution.
|
27
|
+
* If your change has a corresponding open GitHub issue, prefix the commit message with `[Fix #github-issue-number]`.
|
28
|
+
* Make sure to add tests for it. This is important so I don't break it
|
29
|
+
in a future version unintentionally.
|
30
|
+
* Add an entry to the [Changelog](CHANGELOG.md).
|
31
|
+
* Please try not to mess with the Rakefile, version, or history. If
|
32
|
+
you want to have your own version, or is otherwise necessary, that
|
33
|
+
is fine, but please isolate to its own commit so I can cherry-pick
|
34
|
+
around it.
|
35
|
+
* Make sure the test suite is passing and the code you wrote doesn't produce
|
36
|
+
RuboCop offenses.
|
37
|
+
* [Squash related commits together][5].
|
38
|
+
* Open a [pull request][4] that relates to *only* one subject with a clear title
|
39
|
+
and description in grammatically correct, complete sentences.
|
40
|
+
|
41
|
+
## Changelog entry format
|
42
|
+
|
43
|
+
Here are a few examples:
|
44
|
+
|
45
|
+
```
|
46
|
+
* [#753](https://github.com/toptal/chewy/pull/753): Add support for direct_import parameter to skip objects reloading. ([@TikiTDO][], [@dalthon][])
|
47
|
+
* [#739](https://github.com/toptal/chewy/pull/739): Remove explicit `main` branch dependencies on `rspec-*` gems after `rspec-mocks` 3.10.2 is released. ([@rabotyaga][])
|
48
|
+
```
|
49
|
+
|
50
|
+
* Mark it up in [Markdown syntax][6].
|
51
|
+
* The entry line should start with `* ` (an asterisk and a space).
|
52
|
+
* If the change has a related GitHub issue (e.g. a bug fix for a reported issue), put a link to the issue as `[#123](https://github.com/toptal/chewy/issues/123): `.
|
53
|
+
* Describe the brief of the change. The sentence should end with a punctuation.
|
54
|
+
* If this is a breaking change, mark it with `**(Breaking)**`.
|
55
|
+
* At the end of the entry, add an implicit link to your GitHub user page as `([@username][])`.
|
56
|
+
* If this is your first contribution to the project, add a link definition for the implicit link to the bottom of the changelog as `[@username]: https://github.com/username`.
|
57
|
+
|
58
|
+
[1]: https://github.com/toptal/chewy/issues
|
59
|
+
[2]: https://www.gun.io/blog/how-to-github-fork-branch-and-pull-request
|
60
|
+
[3]: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
61
|
+
[4]: https://help.github.com/articles/about-pull-requests
|
62
|
+
[5]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
|
63
|
+
[6]: https://daringfireball.net/projects/markdown/syntax
|
data/Gemfile
CHANGED
@@ -8,9 +8,11 @@ gem 'activerecord'
|
|
8
8
|
|
9
9
|
gem 'activejob', require: false
|
10
10
|
gem 'resque', require: false
|
11
|
-
gem 'shoryuken', require: false
|
12
11
|
gem 'sidekiq', require: false
|
13
12
|
|
13
|
+
gem 'aws-sdk-sqs', require: false
|
14
|
+
gem 'shoryuken', require: false
|
15
|
+
|
14
16
|
gem 'kaminari-core', require: false
|
15
17
|
gem 'will_paginate', require: false
|
16
18
|
|
@@ -22,3 +24,5 @@ gem 'guard-rspec'
|
|
22
24
|
|
23
25
|
gem 'redcarpet'
|
24
26
|
gem 'yard'
|
27
|
+
|
28
|
+
gem 'rexml' if RUBY_VERSION >= '3.0.0'
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/chewy.svg)](http://badge.fury.io/rb/chewy)
|
2
|
-
[![
|
2
|
+
[![CircleCI](https://circleci.com/gh/toptal/chewy/tree/master.svg?style=svg)](https://circleci.com/gh/toptal/chewy/tree/master)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/toptal/chewy.svg)](https://codeclimate.com/github/toptal/chewy)
|
4
4
|
[![Inline docs](http://inch-ci.org/github/toptal/chewy.svg?branch=master)](http://inch-ci.org/github/toptal/chewy)
|
5
5
|
|
6
|
-
<p align="right">Sponsored by</p>
|
7
|
-
<p align="right"><a href="https://www.toptal.com/"><img src="https://www.toptal.com/assets/public/blocks/logo/big.png" alt="Toptal" width="105" height="34"></a></p>
|
8
|
-
|
9
6
|
# Chewy
|
10
7
|
|
11
|
-
Chewy is an ODM
|
8
|
+
Chewy is an ODM (Object Document Mapper), built on top of the [the official Elasticsearch client](https://github.com/elastic/elasticsearch-ruby).
|
12
9
|
|
13
10
|
## Table of Contents
|
14
11
|
|
@@ -34,7 +31,7 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
34
31
|
* [Non-block notation](#non-block-notation)
|
35
32
|
* [Designing your own strategies](#designing-your-own-strategies)
|
36
33
|
* [Rails application strategies integration](#rails-application-strategies-integration)
|
37
|
-
* [ActiveSupport::Notifications support](#
|
34
|
+
* [ActiveSupport::Notifications support](#activesupportnotifications-support)
|
38
35
|
* [NewRelic integration](#newrelic-integration)
|
39
36
|
* [Search requests](#search-requests)
|
40
37
|
* [Composing requests](#composing-requests)
|
@@ -42,7 +39,6 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
42
39
|
* [Named scopes](#named-scopes)
|
43
40
|
* [Scroll API](#scroll-api)
|
44
41
|
* [Loading objects](#loading-objects)
|
45
|
-
* [Legacy DSL incompatibilities](#legacy-dsl-incompatibilities)
|
46
42
|
* [Rake tasks](#rake-tasks)
|
47
43
|
* [chewy:reset](#chewyreset)
|
48
44
|
* [chewy:upgrade](#chewyupgrade)
|
@@ -51,13 +47,14 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
51
47
|
* [chewy:deploy](#chewydeploy)
|
52
48
|
* [Parallelizing rake tasks](#parallelizing-rake-tasks)
|
53
49
|
* [chewy:journal](#chewyjournal)
|
54
|
-
* [
|
50
|
+
* [RSpec integration](#rspec-integration)
|
55
51
|
* [Minitest integration](#minitest-integration)
|
56
|
-
* [TODO a.k.a coming soon](#todo-aka-coming-soon)
|
57
52
|
* [Contributing](#contributing)
|
58
53
|
|
59
54
|
## Why Chewy?
|
60
55
|
|
56
|
+
In this section we'll cover why you might want to use Chewy instead of the official `elasticsearch-ruby` client gem.
|
57
|
+
|
61
58
|
* Multi-model indices.
|
62
59
|
|
63
60
|
Index classes are independent from ORM/ODM models. Now, implementing e.g. cross-model autocomplete is much easier. You can just define the index and work with it in an object-oriented style. You can define several types for index - one per indexed model.
|
@@ -76,10 +73,9 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
76
73
|
|
77
74
|
* Support for ActiveRecord, [Mongoid](https://github.com/mongoid/mongoid) and [Sequel](https://github.com/jeremyevans/sequel).
|
78
75
|
|
79
|
-
|
80
76
|
## Installation
|
81
77
|
|
82
|
-
Add this line to your application's Gemfile
|
78
|
+
Add this line to your application's `Gemfile`:
|
83
79
|
|
84
80
|
gem 'chewy'
|
85
81
|
|
@@ -91,13 +87,35 @@ Or install it yourself as:
|
|
91
87
|
|
92
88
|
$ gem install chewy
|
93
89
|
|
90
|
+
## Compatibility
|
91
|
+
|
92
|
+
### Ruby
|
93
|
+
|
94
|
+
Chewy is compatible with MRI 2.5-3.0¹.
|
95
|
+
|
96
|
+
> ¹ Ruby 3 is only supported with Rails 6.1
|
97
|
+
|
98
|
+
### Elasticsearch compatibility matrix
|
99
|
+
|
100
|
+
| Chewy version | Elasticsearch version |
|
101
|
+
| ------------- | ---------------------------------- |
|
102
|
+
| 7.0.0 | 6.8, 7.x |
|
103
|
+
| 6.0.0 | 5.x, 6.x |
|
104
|
+
| 5.x | 5.x, limited support for 1.x & 2.x |
|
105
|
+
|
106
|
+
See [Migration guide](migration_guide.md).
|
107
|
+
|
94
108
|
## Usage
|
95
109
|
|
96
110
|
### Client settings
|
97
111
|
|
98
|
-
There are two ways to configure the Chewy client:
|
112
|
+
There are two ways to configure the Chewy client:
|
99
113
|
|
100
|
-
|
114
|
+
* via the hash `Chewy.settings`
|
115
|
+
* via the configuration file `chewy.yml`
|
116
|
+
|
117
|
+
You can create `chewy.yml` manually or run `rails g chewy:install` to
|
118
|
+
generate it.
|
101
119
|
|
102
120
|
```ruby
|
103
121
|
# config/initializers/chewy.rb
|
@@ -129,25 +147,29 @@ Chewy.logger = Logger.new(STDOUT)
|
|
129
147
|
|
130
148
|
See [config.rb](lib/chewy/config.rb) for more details.
|
131
149
|
|
132
|
-
####
|
133
|
-
|
150
|
+
#### AWS Elasticsearch
|
151
|
+
|
152
|
+
If you would like to use AWS's Elasticsearch using an IAM user policy, you will need to sign your requests for the `es:*` action by injecting the appropriate headers passing a proc to `transport_options`.
|
153
|
+
You'll need an additional gem for Faraday middleware: add `gem 'faraday_middleware-aws-sigv4'` to your Gemfile.
|
134
154
|
|
135
155
|
```ruby
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
156
|
+
require 'faraday_middleware/aws_sigv4'
|
157
|
+
|
158
|
+
Chewy.settings = {
|
159
|
+
host: 'http://my-es-instance-on-aws.us-east-1.es.amazonaws.com:80',
|
160
|
+
port: 80, # 443 for https host
|
161
|
+
transport_options: {
|
162
|
+
headers: { content_type: 'application/json' },
|
163
|
+
proc: -> (f) do
|
164
|
+
f.request :aws_sigv4,
|
165
|
+
service: 'es',
|
166
|
+
region: 'us-east-1',
|
167
|
+
access_key_id: ENV['AWS_ACCESS_KEY'],
|
168
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
169
|
+
end
|
149
170
|
}
|
150
|
-
|
171
|
+
}
|
172
|
+
```
|
151
173
|
|
152
174
|
### Index definition
|
153
175
|
|
@@ -180,7 +202,7 @@ If you would like to use AWS's ElasticSearch using an IAM user policy, you will
|
|
180
202
|
field :badges, value: ->(user) { user.badges.map(&:name) } # passing array values to index
|
181
203
|
field :projects do # the same block syntax for multi_field, if `:type` is specified
|
182
204
|
field :title
|
183
|
-
field :description # default data type is `
|
205
|
+
field :description # default data type is `text`
|
184
206
|
# additional top-level objects passed to value proc:
|
185
207
|
field :categories, value: ->(project, user) { project.categories.map(&:name) if user.active? }
|
186
208
|
end
|
@@ -208,7 +230,7 @@ If you would like to use AWS's ElasticSearch using an IAM user policy, you will
|
|
208
230
|
|
209
231
|
define_type User.active.includes(:country, :badges, :projects) do
|
210
232
|
root date_detection: false do
|
211
|
-
template 'about_translations.*', type: '
|
233
|
+
template 'about_translations.*', type: 'text', analyzer: 'standard'
|
212
234
|
|
213
235
|
field :first_name, :last_name
|
214
236
|
field :email, analyzer: 'email'
|
@@ -335,9 +357,9 @@ This will automatically set the type or root field to `object`. You may also spe
|
|
335
357
|
To define a multi field you have to specify any type except for `object` or `nested` in the root field:
|
336
358
|
|
337
359
|
```ruby
|
338
|
-
field :full_name, type: '
|
360
|
+
field :full_name, type: 'text', value: ->{ full_name.strip } do
|
339
361
|
field :ordered, analyzer: 'ordered'
|
340
|
-
field :untouched,
|
362
|
+
field :untouched, type: 'keyword'
|
341
363
|
end
|
342
364
|
```
|
343
365
|
|
@@ -678,6 +700,11 @@ Chewy.strategy(:sidekiq) do
|
|
678
700
|
end
|
679
701
|
```
|
680
702
|
|
703
|
+
The default queue name is `chewy`, you can customize it in settings: `sidekiq.queue_name`
|
704
|
+
```
|
705
|
+
Chewy.settings[:sidekiq] = {queue: :low}
|
706
|
+
```
|
707
|
+
|
681
708
|
#### `:active_job`
|
682
709
|
|
683
710
|
This does the same thing as `:atomic`, but using ActiveJob. This will inherit the ActiveJob configuration settings including the `active_job.queue_adapter` setting for the environment. Patch `Chewy::Strategy::ActiveJob::Worker` for index updates improving.
|
@@ -688,6 +715,11 @@ Chewy.strategy(:active_job) do
|
|
688
715
|
end
|
689
716
|
```
|
690
717
|
|
718
|
+
The default queue name is `chewy`, you can customize it in settings: `active_job.queue_name`
|
719
|
+
```
|
720
|
+
Chewy.settings[:active_job] = {queue: :low}
|
721
|
+
```
|
722
|
+
|
691
723
|
#### `:shoryuken`
|
692
724
|
|
693
725
|
This does the same thing as `:atomic`, but asynchronously using shoryuken. Patch `Chewy::Strategy::Shoryuken::Worker` for index updates improving.
|
@@ -807,38 +839,84 @@ Chewy has notifying the following events:
|
|
807
839
|
To integrate with NewRelic you may use the following example source (config/initializers/chewy.rb):
|
808
840
|
|
809
841
|
```ruby
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
NewRelic::Agent.instance.transaction_sampler.notice_sql(logged, nil, duration)
|
817
|
-
NewRelic::Agent.instance.sql_sampler.notice_sql(logged, metric_name, nil, duration)
|
818
|
-
NewRelic::Agent.record_metric(metric_name, duration)
|
842
|
+
require 'new_relic/agent/instrumentation/evented_subscriber'
|
843
|
+
|
844
|
+
class ChewySubscriber < NewRelic::Agent::Instrumentation::EventedSubscriber
|
845
|
+
def start(name, id, payload)
|
846
|
+
event = ChewyEvent.new(name, Time.current, nil, id, payload)
|
847
|
+
push_event(event)
|
819
848
|
end
|
820
|
-
end
|
821
849
|
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
850
|
+
def finish(_name, id, _payload)
|
851
|
+
pop_event(id).finish
|
852
|
+
end
|
853
|
+
|
854
|
+
class ChewyEvent < NewRelic::Agent::Instrumentation::Event
|
855
|
+
OPERATIONS = {
|
856
|
+
'import_objects.chewy' => 'import',
|
857
|
+
'search_query.chewy' => 'search',
|
858
|
+
'delete_query.chewy' => 'delete'
|
859
|
+
}.freeze
|
826
860
|
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
861
|
+
def initialize(*args)
|
862
|
+
super
|
863
|
+
@segment = start_segment
|
864
|
+
end
|
865
|
+
|
866
|
+
def start_segment
|
867
|
+
segment = NewRelic::Agent::Transaction::DatastoreSegment.new product, operation, collection, host, port
|
868
|
+
if (txn = state.current_transaction)
|
869
|
+
segment.transaction = txn
|
870
|
+
end
|
871
|
+
segment.notice_sql @payload[:request].to_s
|
872
|
+
segment.start
|
873
|
+
segment
|
874
|
+
end
|
875
|
+
|
876
|
+
def finish
|
877
|
+
if (txn = state.current_transaction)
|
878
|
+
txn.add_segment @segment
|
879
|
+
end
|
880
|
+
@segment.finish
|
881
|
+
end
|
882
|
+
|
883
|
+
private
|
884
|
+
|
885
|
+
def state
|
886
|
+
@state ||= NewRelic::Agent::TransactionState.tl_get
|
887
|
+
end
|
888
|
+
|
889
|
+
def product
|
890
|
+
'Elasticsearch'
|
891
|
+
end
|
892
|
+
|
893
|
+
def operation
|
894
|
+
OPERATIONS[name]
|
895
|
+
end
|
896
|
+
|
897
|
+
def collection
|
898
|
+
payload.values_at(:type, :index)
|
899
|
+
.reject { |value| value.try(:empty?) }
|
900
|
+
.first
|
901
|
+
.to_s
|
902
|
+
end
|
903
|
+
|
904
|
+
def host
|
905
|
+
Chewy.client.transport.hosts.first[:host]
|
906
|
+
end
|
907
|
+
|
908
|
+
def port
|
909
|
+
Chewy.client.transport.hosts.first[:port]
|
910
|
+
end
|
831
911
|
end
|
832
912
|
end
|
913
|
+
|
914
|
+
ActiveSupport::Notifications.subscribe(/.chewy$/, ChewySubscriber.new)
|
833
915
|
```
|
834
916
|
|
835
917
|
### Search requests
|
836
918
|
|
837
|
-
|
838
|
-
|
839
|
-
If you want to use it - simply do `Chewy.search_class = Chewy::Query` somewhere before indices are initialized.
|
840
|
-
|
841
|
-
The new DSL is enabled by default, here is a quick introduction.
|
919
|
+
Quick introduction.
|
842
920
|
|
843
921
|
#### Composing requests
|
844
922
|
|
@@ -906,17 +984,6 @@ scope.each do |wrapper|
|
|
906
984
|
end
|
907
985
|
```
|
908
986
|
|
909
|
-
#### Legacy DSL incompatibilities
|
910
|
-
|
911
|
-
* Filters advanced block DSL is not supported anymore, `elasticsearch-dsl` is used instead.
|
912
|
-
* Things like `query_mode` and `filter_mode` are in past, use advanced DSL to achieve similar behavior. See [Chewy::Search::QueryProxy](lib/chewy/search/query_proxy.rb) for details.
|
913
|
-
* `preload` method is no more, the collection returned by scope doesn't depend on loading options, scope always returns `Chewy::Type` wrappers. To get ORM/ODM objects, use `#objects` method.
|
914
|
-
* Some of the methods have changed their purpose: `only` was used to filter fields before, now it filters the scope. To filter fields use `source` or `stored_fields`.
|
915
|
-
* `types!` method is no more, use `except(:types).types(...)`
|
916
|
-
* Named aggregations are not supported, use named scopes instead.
|
917
|
-
* A lot of query-level methods were not ported: everything that is related to boost and scoring. Use `query` manipulation to provide them.
|
918
|
-
* `Chewy::Type#_object` returns nil always. Use `Chewy::Search::Response#object_hash` instead.
|
919
|
-
|
920
987
|
### Rake tasks
|
921
988
|
|
922
989
|
For a Rails application, some index-maintaining rake tasks are defined.
|
@@ -936,9 +1003,9 @@ rake chewy:reset[-users,places] # resets every index in the application except s
|
|
936
1003
|
|
937
1004
|
Performs reset exactly the same way as `chewy:reset` does, but only when the index specification (setting or mapping) was changed.
|
938
1005
|
|
939
|
-
It works only when index specification is locked in `Chewy::Stash` index. The first run will reset all indexes and lock their specifications.
|
1006
|
+
It works only when index specification is locked in `Chewy::Stash::Specification` index. The first run will reset all indexes and lock their specifications.
|
940
1007
|
|
941
|
-
See [Chewy::Stash](lib/chewy/stash.rb) and [Chewy::Index::Specification](lib/chewy/index/specification.rb) for more details.
|
1008
|
+
See [Chewy::Stash::Specification](lib/chewy/stash.rb) and [Chewy::Index::Specification](lib/chewy/index/specification.rb) for more details.
|
942
1009
|
|
943
1010
|
|
944
1011
|
```bash
|
@@ -963,7 +1030,7 @@ rake chewy:update[-users,places#city] # updates every index in the application e
|
|
963
1030
|
|
964
1031
|
#### `chewy:sync`
|
965
1032
|
|
966
|
-
Provides a way to synchronize outdated indexes with the source quickly and without doing a full reset.
|
1033
|
+
Provides a way to synchronize outdated indexes with the source quickly and without doing a full reset. By default field `updated_at` is used to find outdated records, but this could be customized by `outdated_sync_field` as described at [Chewy::Type::Syncer](lib/chewy/type/syncer.rb).
|
967
1034
|
|
968
1035
|
Arguments are similar to the ones taken by `chewy:update` task. It is possible to specify a particular type or a whole index.
|
969
1036
|
|
@@ -1011,7 +1078,7 @@ rake chewy:journal:apply["$(date -v-1H -u +%FT%TZ)"] # apply journaled changes f
|
|
1011
1078
|
rake chewy:journal:apply["$(date -v-1H -u +%FT%TZ)",users] # apply journaled changes for the past hour on UsersIndex only
|
1012
1079
|
```
|
1013
1080
|
|
1014
|
-
###
|
1081
|
+
### RSpec integration
|
1015
1082
|
|
1016
1083
|
Just add `require 'chewy/rspec'` to your spec_helper.rb and you will get additional features: See [update_index.rb](lib/chewy/rspec/update_index.rb) for more details.
|
1017
1084
|
|
@@ -1032,12 +1099,6 @@ If you use `DatabaseCleaner` in your tests with [the `transaction` strategy](htt
|
|
1032
1099
|
Chewy.use_after_commit_callbacks = !Rails.env.test?
|
1033
1100
|
```
|
1034
1101
|
|
1035
|
-
## TODO a.k.a coming soon:
|
1036
|
-
|
1037
|
-
* Typecasting support
|
1038
|
-
* update_all support
|
1039
|
-
* Maybe, closer ORM/ODM integration, creating index classes implicitly
|
1040
|
-
|
1041
1102
|
## Contributing
|
1042
1103
|
|
1043
1104
|
1. Fork it (http://github.com/toptal/chewy/fork)
|
@@ -1053,3 +1114,8 @@ Use the following Rake tasks to control the Elasticsearch cluster while developi
|
|
1053
1114
|
rake elasticsearch:start # start Elasticsearch cluster on 9250 port for tests
|
1054
1115
|
rake elasticsearch:stop # stop Elasticsearch
|
1055
1116
|
```
|
1117
|
+
|
1118
|
+
## Copyright
|
1119
|
+
|
1120
|
+
Copyright (c) 2013-2021 Toptal, LLC. See [LICENSE.txt](LICENSE.txt) for
|
1121
|
+
further details.
|