chewy 5.0.0 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +214 -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/Appraisals +1 -17
- data/CHANGELOG.md +312 -356
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +97 -92
- data/chewy.gemspec +5 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +4 -3
- data/gemfiles/{rails.5.0.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +4 -3
- data/gemfiles/{rails.5.0.mongoid.6.1.gemfile → rails.6.0.activerecord.gemfile} +4 -3
- data/gemfiles/{rails.5.1.activerecord.gemfile → rails.6.1.activerecord.gemfile} +6 -3
- data/lib/chewy.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -1
- data/lib/chewy/config.rb +2 -20
- data/lib/chewy/fields/base.rb +1 -7
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +6 -15
- data/lib/chewy/index/actions.rb +12 -4
- data/lib/chewy/index/aliases.rb +14 -5
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +3 -19
- data/lib/chewy/search.rb +2 -9
- data/lib/chewy/search/loader.rb +3 -13
- 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/indices.rb +78 -0
- data/lib/chewy/search/parameters/none.rb +1 -3
- data/lib/chewy/search/request.rb +92 -85
- data/lib/chewy/search/response.rb +1 -1
- data/lib/chewy/search/scrolling.rb +8 -7
- data/lib/chewy/stash.rb +3 -6
- data/lib/chewy/strategy/active_job.rb +1 -1
- data/lib/chewy/strategy/sidekiq.rb +1 -1
- data/lib/chewy/type.rb +4 -1
- data/lib/chewy/type/adapter/active_record.rb +1 -1
- data/lib/chewy/type/adapter/mongoid.rb +1 -1
- data/lib/chewy/type/adapter/orm.rb +7 -4
- data/lib/chewy/type/adapter/sequel.rb +1 -1
- data/lib/chewy/type/import.rb +14 -4
- data/lib/chewy/type/import/bulk_request.rb +5 -4
- data/lib/chewy/type/import/journal_builder.rb +2 -3
- data/lib/chewy/type/import/routine.rb +3 -3
- data/lib/chewy/type/mapping.rb +5 -5
- data/lib/chewy/type/observe.rb +3 -3
- data/lib/chewy/type/syncer.rb +2 -6
- data/lib/chewy/type/witchcraft.rb +4 -2
- data/lib/chewy/type/wrapper.rb +12 -2
- data/lib/chewy/version.rb +1 -1
- data/lib/tasks/chewy.rake +10 -10
- data/migration_guide.md +37 -0
- data/spec/chewy/config_spec.rb +1 -22
- data/spec/chewy/fields/base_spec.rb +15 -13
- data/spec/chewy/fields/root_spec.rb +4 -4
- data/spec/chewy/index/actions_spec.rb +120 -33
- data/spec/chewy/index/aliases_spec.rb +3 -3
- data/spec/chewy/index/specification_spec.rb +13 -13
- data/spec/chewy/index_spec.rb +17 -42
- data/spec/chewy/journal_spec.rb +25 -21
- 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 +102 -87
- data/spec/chewy/rspec/update_index_spec.rb +47 -46
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +0 -16
- data/spec/chewy/search/parameters/indices_spec.rb +105 -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 +94 -78
- data/spec/chewy/search/response_spec.rb +27 -17
- data/spec/chewy/search/scrolling_spec.rb +22 -18
- data/spec/chewy/search_spec.rb +45 -41
- data/spec/chewy/stash_spec.rb +14 -12
- data/spec/chewy/strategy/active_job_spec.rb +15 -2
- data/spec/chewy/strategy/shoryuken_spec.rb +6 -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/bulk_request_spec.rb +0 -6
- data/spec/chewy/type/import/journal_builder_spec.rb +9 -11
- data/spec/chewy/type/import_spec.rb +11 -2
- data/spec/chewy/type/mapping_spec.rb +8 -38
- 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 +4 -8
- data/spec/support/active_record.rb +21 -0
- metadata +31 -100
- data/.travis.yml +0 -45
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
- data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
- data/lib/chewy/query.rb +0 -1137
- data/lib/chewy/query/compose.rb +0 -68
- data/lib/chewy/query/criteria.rb +0 -191
- data/lib/chewy/query/filters.rb +0 -244
- data/lib/chewy/query/loading.rb +0 -110
- 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/lib/chewy/search/parameters/types.rb +0 -20
- 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 -14
- 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 -637
- data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
- data/spec/chewy/search/parameters/types_spec.rb +0 -5
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
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
|
|
@@ -20,7 +17,6 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
20
17
|
* [Index definition](#index-definition)
|
21
18
|
* [Type default import options](#type-default-import-options)
|
22
19
|
* [Multi (nested) and object field types](#multi-nested-and-object-field-types)
|
23
|
-
* [Parent and children types](#parent-and-children-types)
|
24
20
|
* [Geo Point fields](#geo-point-fields)
|
25
21
|
* [Crutches™ technology](#crutches-technology)
|
26
22
|
* [Witchcraft™ technology](#witchcraft-technology)
|
@@ -34,7 +30,7 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
34
30
|
* [Non-block notation](#non-block-notation)
|
35
31
|
* [Designing your own strategies](#designing-your-own-strategies)
|
36
32
|
* [Rails application strategies integration](#rails-application-strategies-integration)
|
37
|
-
* [ActiveSupport::Notifications support](#
|
33
|
+
* [ActiveSupport::Notifications support](#activesupportnotifications-support)
|
38
34
|
* [NewRelic integration](#newrelic-integration)
|
39
35
|
* [Search requests](#search-requests)
|
40
36
|
* [Composing requests](#composing-requests)
|
@@ -42,7 +38,6 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
42
38
|
* [Named scopes](#named-scopes)
|
43
39
|
* [Scroll API](#scroll-api)
|
44
40
|
* [Loading objects](#loading-objects)
|
45
|
-
* [Legacy DSL incompatibilities](#legacy-dsl-incompatibilities)
|
46
41
|
* [Rake tasks](#rake-tasks)
|
47
42
|
* [chewy:reset](#chewyreset)
|
48
43
|
* [chewy:upgrade](#chewyupgrade)
|
@@ -51,16 +46,13 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
51
46
|
* [chewy:deploy](#chewydeploy)
|
52
47
|
* [Parallelizing rake tasks](#parallelizing-rake-tasks)
|
53
48
|
* [chewy:journal](#chewyjournal)
|
54
|
-
* [
|
49
|
+
* [RSpec integration](#rspec-integration)
|
55
50
|
* [Minitest integration](#minitest-integration)
|
56
|
-
* [TODO a.k.a coming soon](#todo-aka-coming-soon)
|
57
51
|
* [Contributing](#contributing)
|
58
52
|
|
59
53
|
## Why Chewy?
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
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.
|
55
|
+
In this section we'll cover why you might want to use Chewy instead of the official `elasticsearch-ruby` client gem.
|
64
56
|
|
65
57
|
* Every index is observable by all the related models.
|
66
58
|
|
@@ -76,10 +68,9 @@ Chewy is an ODM and wrapper for [the official Elasticsearch client](https://gith
|
|
76
68
|
|
77
69
|
* Support for ActiveRecord, [Mongoid](https://github.com/mongoid/mongoid) and [Sequel](https://github.com/jeremyevans/sequel).
|
78
70
|
|
79
|
-
|
80
71
|
## Installation
|
81
72
|
|
82
|
-
Add this line to your application's Gemfile
|
73
|
+
Add this line to your application's `Gemfile`:
|
83
74
|
|
84
75
|
gem 'chewy'
|
85
76
|
|
@@ -91,13 +82,36 @@ Or install it yourself as:
|
|
91
82
|
|
92
83
|
$ gem install chewy
|
93
84
|
|
85
|
+
## Compatibility
|
86
|
+
|
87
|
+
### Ruby
|
88
|
+
|
89
|
+
Chewy is compatible with MRI 2.5-3.0¹.
|
90
|
+
|
91
|
+
> ¹ Ruby 3 is only supported with Rails 6.1
|
92
|
+
|
93
|
+
### Elasticsearch compatibility matrix
|
94
|
+
|
95
|
+
| Chewy version | Elasticsearch version |
|
96
|
+
| ------------- | ---------------------------------- |
|
97
|
+
| 7.1.x | 7.x |
|
98
|
+
| 7.0.0 | 6.8, 7.x |
|
99
|
+
| 6.0.0 | 5.x, 6.x |
|
100
|
+
| 5.x | 5.x, limited support for 1.x & 2.x |
|
101
|
+
|
102
|
+
See [Migration guide](migration_guide.md).
|
103
|
+
|
94
104
|
## Usage
|
95
105
|
|
96
106
|
### Client settings
|
97
107
|
|
98
|
-
There are two ways to configure the Chewy client:
|
108
|
+
There are two ways to configure the Chewy client:
|
109
|
+
|
110
|
+
* via the hash `Chewy.settings`
|
111
|
+
* via the configuration file `chewy.yml`
|
99
112
|
|
100
|
-
You can create
|
113
|
+
You can create `chewy.yml` manually or run `rails g chewy:install` to
|
114
|
+
generate it.
|
101
115
|
|
102
116
|
```ruby
|
103
117
|
# config/initializers/chewy.rb
|
@@ -129,25 +143,29 @@ Chewy.logger = Logger.new(STDOUT)
|
|
129
143
|
|
130
144
|
See [config.rb](lib/chewy/config.rb) for more details.
|
131
145
|
|
132
|
-
####
|
133
|
-
|
146
|
+
#### AWS Elasticsearch
|
147
|
+
|
148
|
+
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`.
|
149
|
+
You'll need an additional gem for Faraday middleware: add `gem 'faraday_middleware-aws-sigv4'` to your Gemfile.
|
134
150
|
|
135
151
|
```ruby
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
152
|
+
require 'faraday_middleware/aws_sigv4'
|
153
|
+
|
154
|
+
Chewy.settings = {
|
155
|
+
host: 'http://my-es-instance-on-aws.us-east-1.es.amazonaws.com:80',
|
156
|
+
port: 80, # 443 for https host
|
157
|
+
transport_options: {
|
158
|
+
headers: { content_type: 'application/json' },
|
159
|
+
proc: -> (f) do
|
160
|
+
f.request :aws_sigv4,
|
161
|
+
service: 'es',
|
162
|
+
region: 'us-east-1',
|
163
|
+
access_key_id: ENV['AWS_ACCESS_KEY'],
|
164
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
165
|
+
end
|
149
166
|
}
|
150
|
-
|
167
|
+
}
|
168
|
+
```
|
151
169
|
|
152
170
|
### Index definition
|
153
171
|
|
@@ -180,7 +198,7 @@ If you would like to use AWS's ElasticSearch using an IAM user policy, you will
|
|
180
198
|
field :badges, value: ->(user) { user.badges.map(&:name) } # passing array values to index
|
181
199
|
field :projects do # the same block syntax for multi_field, if `:type` is specified
|
182
200
|
field :title
|
183
|
-
field :description # default data type is `
|
201
|
+
field :description # default data type is `text`
|
184
202
|
# additional top-level objects passed to value proc:
|
185
203
|
field :categories, value: ->(project, user) { project.categories.map(&:name) if user.active? }
|
186
204
|
end
|
@@ -337,24 +355,12 @@ To define a multi field you have to specify any type except for `object` or `nes
|
|
337
355
|
```ruby
|
338
356
|
field :full_name, type: 'text', value: ->{ full_name.strip } do
|
339
357
|
field :ordered, analyzer: 'ordered'
|
340
|
-
field :untouched,
|
358
|
+
field :untouched, type: 'keyword'
|
341
359
|
end
|
342
360
|
```
|
343
361
|
|
344
362
|
The `value:` option for internal fields will no longer be effective.
|
345
363
|
|
346
|
-
### Parent and children types
|
347
|
-
|
348
|
-
To define [parent](https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child-mapping.html) type for a given index_type, you can include root options for the type where you can specify parent_type and parent_id
|
349
|
-
|
350
|
-
```ruby
|
351
|
-
define_type User.includes(:account) do
|
352
|
-
root parent: 'account', parent_id: ->{ account_id } do
|
353
|
-
field :created_at, type: 'date'
|
354
|
-
field :task_id, type: 'integer'
|
355
|
-
end
|
356
|
-
end
|
357
|
-
```
|
358
364
|
### Geo Point fields
|
359
365
|
|
360
366
|
You can use [Elasticsearch's geo mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html) with the `geo_point` field type, allowing you to query, filter and order by latitude and longitude. You can use the following hash format:
|
@@ -580,7 +586,7 @@ Imagine that you reset your index in a zero-downtime manner (to separate index),
|
|
580
586
|
|
581
587
|
### Types access
|
582
588
|
|
583
|
-
You can access index-defined
|
589
|
+
You can access index-defined type with the following API:
|
584
590
|
|
585
591
|
```ruby
|
586
592
|
UsersIndex::User # => UsersIndex::User
|
@@ -608,11 +614,10 @@ UsersIndex::User.import # import with 0 arguments process all the data specified
|
|
608
614
|
UsersIndex::User.import User.where('rating > 100') # or import specified users scope
|
609
615
|
UsersIndex::User.import User.where('rating > 100').to_a # or import specified users array
|
610
616
|
UsersIndex::User.import [1, 2, 42] # pass even ids for import, it will be handled in the most effective way
|
611
|
-
UsersIndex::User.import User.where('rating > 100'), update_fields: [:email] # if update fields are specified - it will update their values only with the `update` bulk action
|
617
|
+
UsersIndex::User.import User.where('rating > 100'), update_fields: [:email] # if update fields are specified - it will update their values only with the `update` bulk action
|
612
618
|
|
613
|
-
UsersIndex.import #
|
614
|
-
UsersIndex.import user: User.where('rating > 100') # import only
|
615
|
-
# Other index types, if exists, will be imported with default scope from the type definition.
|
619
|
+
UsersIndex.import # same as UsersIndex::User.import
|
620
|
+
UsersIndex.import user: User.where('rating > 100') # import only specified users
|
616
621
|
UsersIndex.reset! # purges index and imports default data for all types
|
617
622
|
```
|
618
623
|
|
@@ -678,6 +683,11 @@ Chewy.strategy(:sidekiq) do
|
|
678
683
|
end
|
679
684
|
```
|
680
685
|
|
686
|
+
The default queue name is `chewy`, you can customize it in settings: `sidekiq.queue_name`
|
687
|
+
```
|
688
|
+
Chewy.settings[:sidekiq] = {queue: :low}
|
689
|
+
```
|
690
|
+
|
681
691
|
#### `:active_job`
|
682
692
|
|
683
693
|
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 +698,11 @@ Chewy.strategy(:active_job) do
|
|
688
698
|
end
|
689
699
|
```
|
690
700
|
|
701
|
+
The default queue name is `chewy`, you can customize it in settings: `active_job.queue_name`
|
702
|
+
```
|
703
|
+
Chewy.settings[:active_job] = {queue: :low}
|
704
|
+
```
|
705
|
+
|
691
706
|
#### `:shoryuken`
|
692
707
|
|
693
708
|
This does the same thing as `:atomic`, but asynchronously using shoryuken. Patch `Chewy::Strategy::Shoryuken::Worker` for index updates improving.
|
@@ -884,30 +899,32 @@ ActiveSupport::Notifications.subscribe(/.chewy$/, ChewySubscriber.new)
|
|
884
899
|
|
885
900
|
### Search requests
|
886
901
|
|
887
|
-
|
888
|
-
|
889
|
-
If you want to use the old DSL - simply do `Chewy.search_class = Chewy::Query` somewhere before indices are initialized.
|
890
|
-
|
891
|
-
The new DSL is enabled by default, here is a quick introduction.
|
902
|
+
Quick introduction.
|
892
903
|
|
893
904
|
#### Composing requests
|
894
905
|
|
895
906
|
The request DSL have the same chainable nature as AR or Mongoid ones. The main class is `Chewy::Search::Request`. It is possible to perform requests on behalf of indices or types:
|
896
907
|
|
897
908
|
```ruby
|
898
|
-
|
899
|
-
|
909
|
+
CitiesIndex.query(match: {name: 'London'}) # or
|
910
|
+
CitiesIndex::City.query(match: {name: 'London'})
|
900
911
|
```
|
901
912
|
|
902
913
|
Main methods of the request DSL are: `query`, `filter` and `post_filter`, it is possible to pass pure query hashes or use `elasticsearch-dsl`. Also, there is an additional
|
903
914
|
|
904
915
|
```ruby
|
905
|
-
|
916
|
+
CitiesIndex
|
906
917
|
.filter(term: {name: 'Bangkok'})
|
907
918
|
.query { match name: 'London' }
|
908
919
|
.query.not(range: {population: {gt: 1_000_000}})
|
909
920
|
```
|
910
921
|
|
922
|
+
You can query a set of indexes at once:
|
923
|
+
|
924
|
+
```ruby
|
925
|
+
CitiesIndex.indices(CountriesIndex).query(match: {name: 'Some'})
|
926
|
+
```
|
927
|
+
|
911
928
|
See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html and https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl for more details.
|
912
929
|
|
913
930
|
An important part of requests manipulation is merging. There are 4 methods to perform it: `merge`, `and`, `or`, `not`. See [Chewy::Search::QueryProxy](lib/chewy/search/query_proxy.rb) for details. Also, `only` and `except` methods help to remove unneeded parts of the request.
|
@@ -915,7 +932,7 @@ An important part of requests manipulation is merging. There are 4 methods to pe
|
|
915
932
|
Every other request part is covered by a bunch of additional methods, see [Chewy::Search::Request](lib/chewy/search/request.rb) for details:
|
916
933
|
|
917
934
|
```ruby
|
918
|
-
|
935
|
+
CitiesIndex.limit(10).offset(30).order(:name, {population: {order: :desc}})
|
919
936
|
```
|
920
937
|
|
921
938
|
Request DSL also provides additional scope actions, like `delete_all`, `exists?`, `count`, `pluck`, etc.
|
@@ -941,8 +958,8 @@ See [Chewy::Search::Scrolling](lib/chewy/search/scrolling.rb) for details.
|
|
941
958
|
It is possible to load ORM/ODM source objects with the `objects` method. To provide additional loading options use `load` method:
|
942
959
|
|
943
960
|
```ruby
|
944
|
-
|
945
|
-
|
961
|
+
CitiesIndex.load(scope: -> { active }).to_a # to_a returns `Chewy::Type` wrappers.
|
962
|
+
CitiesIndex.load(scope: -> { active }).objects # An array of AR source objects.
|
946
963
|
```
|
947
964
|
|
948
965
|
See [Chewy::Search::Loader](lib/chewy/search/loader.rb) for more details.
|
@@ -950,23 +967,12 @@ See [Chewy::Search::Loader](lib/chewy/search/loader.rb) for more details.
|
|
950
967
|
In case when it is necessary to iterate through both of the wrappers and objects simultaneously, `object_hash` method helps a lot:
|
951
968
|
|
952
969
|
```ruby
|
953
|
-
scope =
|
970
|
+
scope = CitiesIndex.load(scope: -> { active })
|
954
971
|
scope.each do |wrapper|
|
955
972
|
scope.object_hash[wrapper]
|
956
973
|
end
|
957
974
|
```
|
958
975
|
|
959
|
-
#### Legacy DSL incompatibilities
|
960
|
-
|
961
|
-
* Filters advanced block DSL is not supported anymore, `elasticsearch-dsl` is used instead.
|
962
|
-
* 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.
|
963
|
-
* `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.
|
964
|
-
* 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`.
|
965
|
-
* `types!` method is no more, use `except(:types).types(...)`
|
966
|
-
* Named aggregations are not supported, use named scopes instead.
|
967
|
-
* A lot of query-level methods were not ported: everything that is related to boost and scoring. Use `query` manipulation to provide them.
|
968
|
-
* `Chewy::Type#_object` returns nil always. Use `Chewy::Search::Response#object_hash` instead.
|
969
|
-
|
970
976
|
### Rake tasks
|
971
977
|
|
972
978
|
For a Rails application, some index-maintaining rake tasks are defined.
|
@@ -978,8 +984,8 @@ Performs zero-downtime reindexing as described [here](https://www.elastic.co/blo
|
|
978
984
|
```bash
|
979
985
|
rake chewy:reset # resets all the existing indices
|
980
986
|
rake chewy:reset[users] # resets UsersIndex only
|
981
|
-
rake chewy:reset[users,
|
982
|
-
rake chewy:reset[-users,
|
987
|
+
rake chewy:reset[users,cities] # resets UsersIndex and CitiesIndex
|
988
|
+
rake chewy:reset[-users,cities] # resets every index in the application except specified ones
|
983
989
|
```
|
984
990
|
|
985
991
|
#### `chewy:upgrade`
|
@@ -994,8 +1000,8 @@ See [Chewy::Stash::Specification](lib/chewy/stash.rb) and [Chewy::Index::Specifi
|
|
994
1000
|
```bash
|
995
1001
|
rake chewy:upgrade # upgrades all the existing indices
|
996
1002
|
rake chewy:upgrade[users] # upgrades UsersIndex only
|
997
|
-
rake chewy:upgrade[users,
|
998
|
-
rake chewy:upgrade[-users,
|
1003
|
+
rake chewy:upgrade[users,cities] # upgrades UsersIndex and CitiesIndex
|
1004
|
+
rake chewy:upgrade[-users,cities] # upgrades every index in the application except specified ones
|
999
1005
|
```
|
1000
1006
|
|
1001
1007
|
#### `chewy:update`
|
@@ -1007,13 +1013,13 @@ Unlike `reset` or `upgrade` tasks, it is possible to pass type references to upd
|
|
1007
1013
|
```bash
|
1008
1014
|
rake chewy:update # updates all the existing indices
|
1009
1015
|
rake chewy:update[users] # updates UsersIndex only
|
1010
|
-
rake chewy:update[users,
|
1011
|
-
rake chewy:update[-users,
|
1016
|
+
rake chewy:update[users,cities#city] # updates UsersIndex and CitiesIndex (if City type is defined on CitiesIndex)
|
1017
|
+
rake chewy:update[-users,cities#city] # updates every index in the application except UsersIndex and CitiesIndex::City
|
1012
1018
|
```
|
1013
1019
|
|
1014
1020
|
#### `chewy:sync`
|
1015
1021
|
|
1016
|
-
Provides a way to synchronize outdated indexes with the source quickly and without doing a full reset.
|
1022
|
+
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).
|
1017
1023
|
|
1018
1024
|
Arguments are similar to the ones taken by `chewy:update` task. It is possible to specify a particular type or a whole index.
|
1019
1025
|
|
@@ -1022,8 +1028,8 @@ See [Chewy::Type::Syncer](lib/chewy/type/syncer.rb) for more details.
|
|
1022
1028
|
```bash
|
1023
1029
|
rake chewy:sync # synchronizes all the existing indices
|
1024
1030
|
rake chewy:sync[users] # synchronizes UsersIndex only
|
1025
|
-
rake chewy:sync[users,
|
1026
|
-
rake chewy:sync[-users,
|
1031
|
+
rake chewy:sync[users,cities#city] # synchronizes UsersIndex and CitiesIndex (if City type is defined on CitiesIndex)
|
1032
|
+
rake chewy:sync[-users,cities#city] # synchronizes every index in the application except except UsersIndex and CitiesIndex::City
|
1027
1033
|
```
|
1028
1034
|
|
1029
1035
|
#### `chewy:deploy`
|
@@ -1047,7 +1053,7 @@ If the number of processes is not specified explicitly - `parallel` gem tries to
|
|
1047
1053
|
```bash
|
1048
1054
|
rake chewy:parallel:reset
|
1049
1055
|
rake chewy:parallel:upgrade[4]
|
1050
|
-
rake chewy:parallel:update[4,
|
1056
|
+
rake chewy:parallel:update[4,cities#city]
|
1051
1057
|
rake chewy:parallel:sync[4,-users]
|
1052
1058
|
rake chewy:parallel:deploy[4] # performs parallel upgrade and parallel sync afterwards
|
1053
1059
|
```
|
@@ -1061,7 +1067,7 @@ rake chewy:journal:apply["$(date -v-1H -u +%FT%TZ)"] # apply journaled changes f
|
|
1061
1067
|
rake chewy:journal:apply["$(date -v-1H -u +%FT%TZ)",users] # apply journaled changes for the past hour on UsersIndex only
|
1062
1068
|
```
|
1063
1069
|
|
1064
|
-
###
|
1070
|
+
### RSpec integration
|
1065
1071
|
|
1066
1072
|
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.
|
1067
1073
|
|
@@ -1082,12 +1088,6 @@ If you use `DatabaseCleaner` in your tests with [the `transaction` strategy](htt
|
|
1082
1088
|
Chewy.use_after_commit_callbacks = !Rails.env.test?
|
1083
1089
|
```
|
1084
1090
|
|
1085
|
-
## TODO a.k.a coming soon:
|
1086
|
-
|
1087
|
-
* Typecasting support
|
1088
|
-
* update_all support
|
1089
|
-
* Maybe, closer ORM/ODM integration, creating index classes implicitly
|
1090
|
-
|
1091
1091
|
## Contributing
|
1092
1092
|
|
1093
1093
|
1. Fork it (http://github.com/toptal/chewy/fork)
|
@@ -1103,3 +1103,8 @@ Use the following Rake tasks to control the Elasticsearch cluster while developi
|
|
1103
1103
|
rake elasticsearch:start # start Elasticsearch cluster on 9250 port for tests
|
1104
1104
|
rake elasticsearch:stop # stop Elasticsearch
|
1105
1105
|
```
|
1106
|
+
|
1107
|
+
## Copyright
|
1108
|
+
|
1109
|
+
Copyright (c) 2013-2021 Toptal, LLC. See [LICENSE.txt](LICENSE.txt) for
|
1110
|
+
further details.
|