chewy 5.0.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +214 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
  6. data/Appraisals +1 -17
  7. data/CHANGELOG.md +312 -356
  8. data/CODE_OF_CONDUCT.md +14 -0
  9. data/CONTRIBUTING.md +63 -0
  10. data/Gemfile +2 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +97 -92
  13. data/chewy.gemspec +5 -5
  14. data/gemfiles/rails.5.2.activerecord.gemfile +4 -3
  15. data/gemfiles/{rails.5.0.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +4 -3
  16. data/gemfiles/{rails.5.0.mongoid.6.1.gemfile → rails.6.0.activerecord.gemfile} +4 -3
  17. data/gemfiles/{rails.5.1.activerecord.gemfile → rails.6.1.activerecord.gemfile} +6 -3
  18. data/lib/chewy.rb +1 -1
  19. data/lib/chewy/backports/duplicable.rb +1 -1
  20. data/lib/chewy/config.rb +2 -20
  21. data/lib/chewy/fields/base.rb +1 -7
  22. data/lib/chewy/fields/root.rb +3 -4
  23. data/lib/chewy/index.rb +6 -15
  24. data/lib/chewy/index/actions.rb +12 -4
  25. data/lib/chewy/index/aliases.rb +14 -5
  26. data/lib/chewy/multi_search.rb +62 -0
  27. data/lib/chewy/railtie.rb +3 -19
  28. data/lib/chewy/search.rb +2 -9
  29. data/lib/chewy/search/loader.rb +3 -13
  30. data/lib/chewy/search/pagination/will_paginate.rb +1 -1
  31. data/lib/chewy/search/parameters.rb +24 -6
  32. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  33. data/lib/chewy/search/parameters/indices.rb +78 -0
  34. data/lib/chewy/search/parameters/none.rb +1 -3
  35. data/lib/chewy/search/request.rb +92 -85
  36. data/lib/chewy/search/response.rb +1 -1
  37. data/lib/chewy/search/scrolling.rb +8 -7
  38. data/lib/chewy/stash.rb +3 -6
  39. data/lib/chewy/strategy/active_job.rb +1 -1
  40. data/lib/chewy/strategy/sidekiq.rb +1 -1
  41. data/lib/chewy/type.rb +4 -1
  42. data/lib/chewy/type/adapter/active_record.rb +1 -1
  43. data/lib/chewy/type/adapter/mongoid.rb +1 -1
  44. data/lib/chewy/type/adapter/orm.rb +7 -4
  45. data/lib/chewy/type/adapter/sequel.rb +1 -1
  46. data/lib/chewy/type/import.rb +14 -4
  47. data/lib/chewy/type/import/bulk_request.rb +5 -4
  48. data/lib/chewy/type/import/journal_builder.rb +2 -3
  49. data/lib/chewy/type/import/routine.rb +3 -3
  50. data/lib/chewy/type/mapping.rb +5 -5
  51. data/lib/chewy/type/observe.rb +3 -3
  52. data/lib/chewy/type/syncer.rb +2 -6
  53. data/lib/chewy/type/witchcraft.rb +4 -2
  54. data/lib/chewy/type/wrapper.rb +12 -2
  55. data/lib/chewy/version.rb +1 -1
  56. data/lib/tasks/chewy.rake +10 -10
  57. data/migration_guide.md +37 -0
  58. data/spec/chewy/config_spec.rb +1 -22
  59. data/spec/chewy/fields/base_spec.rb +15 -13
  60. data/spec/chewy/fields/root_spec.rb +4 -4
  61. data/spec/chewy/index/actions_spec.rb +120 -33
  62. data/spec/chewy/index/aliases_spec.rb +3 -3
  63. data/spec/chewy/index/specification_spec.rb +13 -13
  64. data/spec/chewy/index_spec.rb +17 -42
  65. data/spec/chewy/journal_spec.rb +25 -21
  66. data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
  67. data/spec/chewy/multi_search_spec.rb +85 -0
  68. data/spec/chewy/rake_helper_spec.rb +102 -87
  69. data/spec/chewy/rspec/update_index_spec.rb +47 -46
  70. data/spec/chewy/runtime_spec.rb +2 -2
  71. data/spec/chewy/search/loader_spec.rb +0 -16
  72. data/spec/chewy/search/parameters/indices_spec.rb +105 -0
  73. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  74. data/spec/chewy/search/parameters_spec.rb +21 -4
  75. data/spec/chewy/search/request_spec.rb +94 -78
  76. data/spec/chewy/search/response_spec.rb +27 -17
  77. data/spec/chewy/search/scrolling_spec.rb +22 -18
  78. data/spec/chewy/search_spec.rb +45 -41
  79. data/spec/chewy/stash_spec.rb +14 -12
  80. data/spec/chewy/strategy/active_job_spec.rb +15 -2
  81. data/spec/chewy/strategy/shoryuken_spec.rb +6 -2
  82. data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
  83. data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
  84. data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
  85. data/spec/chewy/type/import/bulk_request_spec.rb +0 -6
  86. data/spec/chewy/type/import/journal_builder_spec.rb +9 -11
  87. data/spec/chewy/type/import_spec.rb +11 -2
  88. data/spec/chewy/type/mapping_spec.rb +8 -38
  89. data/spec/chewy/type/observe_spec.rb +4 -4
  90. data/spec/chewy/type/witchcraft_spec.rb +15 -0
  91. data/spec/chewy/type/wrapper_spec.rb +3 -1
  92. data/spec/chewy_spec.rb +0 -7
  93. data/spec/spec_helper.rb +4 -8
  94. data/spec/support/active_record.rb +21 -0
  95. metadata +31 -100
  96. data/.travis.yml +0 -45
  97. data/LEGACY_DSL.md +0 -497
  98. data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
  99. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  100. data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
  101. data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
  102. data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
  103. data/lib/chewy/query.rb +0 -1137
  104. data/lib/chewy/query/compose.rb +0 -68
  105. data/lib/chewy/query/criteria.rb +0 -191
  106. data/lib/chewy/query/filters.rb +0 -244
  107. data/lib/chewy/query/loading.rb +0 -110
  108. data/lib/chewy/query/nodes/and.rb +0 -25
  109. data/lib/chewy/query/nodes/base.rb +0 -17
  110. data/lib/chewy/query/nodes/bool.rb +0 -34
  111. data/lib/chewy/query/nodes/equal.rb +0 -34
  112. data/lib/chewy/query/nodes/exists.rb +0 -20
  113. data/lib/chewy/query/nodes/expr.rb +0 -28
  114. data/lib/chewy/query/nodes/field.rb +0 -110
  115. data/lib/chewy/query/nodes/has_child.rb +0 -15
  116. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  117. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  118. data/lib/chewy/query/nodes/match_all.rb +0 -11
  119. data/lib/chewy/query/nodes/missing.rb +0 -20
  120. data/lib/chewy/query/nodes/not.rb +0 -25
  121. data/lib/chewy/query/nodes/or.rb +0 -25
  122. data/lib/chewy/query/nodes/prefix.rb +0 -19
  123. data/lib/chewy/query/nodes/query.rb +0 -20
  124. data/lib/chewy/query/nodes/range.rb +0 -63
  125. data/lib/chewy/query/nodes/raw.rb +0 -15
  126. data/lib/chewy/query/nodes/regexp.rb +0 -35
  127. data/lib/chewy/query/nodes/script.rb +0 -20
  128. data/lib/chewy/query/pagination.rb +0 -25
  129. data/lib/chewy/search/parameters/types.rb +0 -20
  130. data/spec/chewy/query/criteria_spec.rb +0 -700
  131. data/spec/chewy/query/filters_spec.rb +0 -201
  132. data/spec/chewy/query/loading_spec.rb +0 -124
  133. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  134. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  135. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  136. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  137. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  138. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  139. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  140. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  141. data/spec/chewy/query/nodes/not_spec.rb +0 -14
  142. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  143. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  144. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  145. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  146. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  147. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  148. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  149. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  150. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  151. data/spec/chewy/query/pagination_spec.rb +0 -39
  152. data/spec/chewy/query_spec.rb +0 -637
  153. data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
  154. data/spec/chewy/search/parameters/types_spec.rb +0 -5
@@ -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
@@ -24,3 +24,5 @@ gem 'guard-rspec'
24
24
 
25
25
  gem 'redcarpet'
26
26
  gem 'yard'
27
+
28
+ gem 'rexml' if RUBY_VERSION >= '3.0.0'
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 pyromaniac
1
+ Copyright (c) 2013-2021 Toptal, LLC
2
2
 
3
3
  MIT License
4
4
 
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
- [![Build Status](https://travis-ci.org/toptal/chewy.svg)](https://travis-ci.org/toptal/chewy)
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 and wrapper for [the official Elasticsearch client](https://github.com/elastic/elasticsearch-ruby).
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](#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
- * [Rspec integration](#rspec-integration)
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
- * Multi-model indices.
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: the `Chewy.settings` hash and `chewy.yml`
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 this file manually or run `rails g chewy:install`.
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
- #### Aws Elastic Search
133
- 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`.
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
- Chewy.settings = {
137
- host: 'http://my-es-instance-on-aws.us-east-1.es.amazonaws.com:80',
138
- transport_options: {
139
- headers: { content_type: 'application/json' },
140
- proc: -> (f) do
141
- f.request :aws_signers_v4,
142
- service_name: 'es',
143
- region: 'us-east-1',
144
- credentials: Aws::Credentials.new(
145
- ENV['AWS_ACCESS_KEY'],
146
- ENV['AWS_SECRET_ACCESS_KEY'])
147
- end
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 `string`
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, index: 'not_analyzed'
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 types with the following API:
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 # import every defined type
614
- UsersIndex.import user: User.where('rating > 100') # import only active users to `user` type.
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
- Long story short: there is a new DSL that supports ES2 and ES5, the previous DSL version (which supports ES1 and ES2) documentation was moved to [LEGACY_DSL.md](LEGACY_DSL.md).
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
- PlaceIndex.query(match: {name: 'London'}) # returns documents of any type
899
- PlaceIndex::City.query(match: {name: 'London'}) # returns cities only.
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
- PlaceIndex
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
- PlaceIndex.limit(10).offset(30).order(:name, {population: {order: :desc}})
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
- PlacesIndex.load(scope: -> { active }).to_a # to_a returns `Chewy::Type` wrappers.
945
- PlacesIndex.load(scope: -> { active }).objects # An array of AR source objects.
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 = PlacesIndex.load(scope: -> { active })
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,places] # resets UsersIndex and PlacesIndex
982
- rake chewy:reset[-users,places] # resets every index in the application except specified ones
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,places] # upgrades UsersIndex and PlacesIndex
998
- rake chewy:upgrade[-users,places] # upgrades every index in the application except specified ones
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,places#city] # updates the whole UsersIndex and PlacesIndex::City type
1011
- rake chewy:update[-users,places#city] # updates every index in the application except every type defined in UsersIndex and the rest of the types defined in PlacesIndex
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,places#city] # synchronizes the whole UsersIndex and PlacesIndex::City type
1026
- rake chewy:sync[-users,places#city] # synchronizes every index in the application except every type defined in UsersIndex and the rest of the types defined in PlacesIndex
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,places#city]
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
- ### Rspec integration
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.