chewy 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/README.md +30 -16
- data/lib/chewy/errors.rb +3 -0
- data/lib/chewy/fields/root.rb +3 -3
- data/lib/chewy/index/crutch.rb +12 -2
- data/lib/chewy/index/import/bulk_builder.rb +4 -3
- data/lib/chewy/index/import/routine.rb +2 -1
- data/lib/chewy/index/import.rb +4 -4
- data/lib/chewy/index/witchcraft.rb +24 -8
- data/lib/chewy/multi_search.rb +1 -1
- data/lib/chewy/search/parameters/runtime_mappings.rb +14 -0
- data/lib/chewy/search/request.rb +18 -2
- data/lib/chewy/search/scrolling.rb +14 -6
- data/lib/chewy/stash.rb +10 -6
- data/lib/chewy/version.rb +1 -1
- metadata +5 -131
- data/.github/CODEOWNERS +0 -1
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -39
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -16
- data/.github/dependabot.yml +0 -42
- data/.github/workflows/ruby.yml +0 -61
- data/.gitignore +0 -22
- data/.rspec +0 -2
- data/.rubocop.yml +0 -64
- data/.rubocop_todo.yml +0 -225
- data/.yardopts +0 -5
- data/CODE_OF_CONDUCT.md +0 -14
- data/CONTRIBUTING.md +0 -63
- data/Gemfile +0 -22
- data/Guardfile +0 -25
- data/Rakefile +0 -17
- data/chewy.gemspec +0 -24
- data/docker-compose.yml +0 -14
- data/docs/README.md +0 -16
- data/docs/configuration.md +0 -440
- data/docs/import.md +0 -122
- data/docs/indexing.md +0 -329
- data/docs/querying.md +0 -72
- data/docs/rake_tasks.md +0 -108
- data/docs/testing.md +0 -41
- data/docs/troubleshooting.md +0 -101
- data/filters +0 -78
- data/gemfiles/base.gemfile +0 -12
- data/gemfiles/rails.7.2.activerecord.gemfile +0 -14
- data/gemfiles/rails.8.0.activerecord.gemfile +0 -14
- data/migration_guide.md +0 -56
- data/spec/chewy/config_spec.rb +0 -110
- data/spec/chewy/elastic_client_spec.rb +0 -26
- data/spec/chewy/fields/base_spec.rb +0 -700
- data/spec/chewy/fields/root_spec.rb +0 -142
- data/spec/chewy/fields/time_fields_spec.rb +0 -28
- data/spec/chewy/index/actions_spec.rb +0 -851
- data/spec/chewy/index/adapter/active_record_spec.rb +0 -663
- data/spec/chewy/index/adapter/object_spec.rb +0 -243
- data/spec/chewy/index/aliases_spec.rb +0 -49
- data/spec/chewy/index/import/bulk_builder_spec.rb +0 -494
- data/spec/chewy/index/import/bulk_request_spec.rb +0 -95
- data/spec/chewy/index/import/journal_builder_spec.rb +0 -87
- data/spec/chewy/index/import/routine_spec.rb +0 -110
- data/spec/chewy/index/import_spec.rb +0 -615
- data/spec/chewy/index/mapping_spec.rb +0 -135
- data/spec/chewy/index/observe/active_record_methods_spec.rb +0 -68
- data/spec/chewy/index/observe/callback_spec.rb +0 -139
- data/spec/chewy/index/observe_spec.rb +0 -143
- data/spec/chewy/index/settings_spec.rb +0 -136
- data/spec/chewy/index/specification_spec.rb +0 -156
- data/spec/chewy/index/syncer_spec.rb +0 -118
- data/spec/chewy/index/witchcraft_spec.rb +0 -245
- data/spec/chewy/index/wrapper_spec.rb +0 -100
- data/spec/chewy/index_spec.rb +0 -269
- data/spec/chewy/journal_spec.rb +0 -223
- data/spec/chewy/minitest/helpers_spec.rb +0 -194
- data/spec/chewy/minitest/search_index_receiver_spec.rb +0 -120
- data/spec/chewy/multi_search_spec.rb +0 -84
- data/spec/chewy/rake_helper_spec.rb +0 -656
- data/spec/chewy/repository_spec.rb +0 -50
- data/spec/chewy/rspec/build_query_spec.rb +0 -34
- data/spec/chewy/rspec/helpers_spec.rb +0 -61
- data/spec/chewy/rspec/update_index_spec.rb +0 -313
- data/spec/chewy/runtime/version_spec.rb +0 -48
- data/spec/chewy/runtime_spec.rb +0 -9
- data/spec/chewy/search/loader_spec.rb +0 -83
- data/spec/chewy/search/pagination/kaminari_examples.rb +0 -69
- data/spec/chewy/search/pagination/kaminari_spec.rb +0 -21
- data/spec/chewy/search/parameters/aggs_spec.rb +0 -5
- data/spec/chewy/search/parameters/bool_storage_examples.rb +0 -53
- data/spec/chewy/search/parameters/collapse_spec.rb +0 -5
- data/spec/chewy/search/parameters/docvalue_fields_spec.rb +0 -5
- data/spec/chewy/search/parameters/explain_spec.rb +0 -5
- data/spec/chewy/search/parameters/filter_spec.rb +0 -5
- data/spec/chewy/search/parameters/hash_storage_examples.rb +0 -59
- data/spec/chewy/search/parameters/highlight_spec.rb +0 -5
- data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +0 -67
- data/spec/chewy/search/parameters/indices_spec.rb +0 -99
- data/spec/chewy/search/parameters/integer_storage_examples.rb +0 -32
- data/spec/chewy/search/parameters/knn_spec.rb +0 -5
- data/spec/chewy/search/parameters/limit_spec.rb +0 -5
- data/spec/chewy/search/parameters/load_spec.rb +0 -60
- data/spec/chewy/search/parameters/min_score_spec.rb +0 -32
- data/spec/chewy/search/parameters/none_spec.rb +0 -5
- data/spec/chewy/search/parameters/offset_spec.rb +0 -5
- data/spec/chewy/search/parameters/order_spec.rb +0 -72
- data/spec/chewy/search/parameters/post_filter_spec.rb +0 -5
- data/spec/chewy/search/parameters/preference_spec.rb +0 -5
- data/spec/chewy/search/parameters/profile_spec.rb +0 -5
- data/spec/chewy/search/parameters/query_spec.rb +0 -5
- data/spec/chewy/search/parameters/query_storage_examples.rb +0 -434
- data/spec/chewy/search/parameters/request_cache_spec.rb +0 -67
- data/spec/chewy/search/parameters/rescore_spec.rb +0 -62
- data/spec/chewy/search/parameters/script_fields_spec.rb +0 -5
- data/spec/chewy/search/parameters/search_after_spec.rb +0 -35
- data/spec/chewy/search/parameters/search_type_spec.rb +0 -5
- data/spec/chewy/search/parameters/source_spec.rb +0 -162
- data/spec/chewy/search/parameters/storage_spec.rb +0 -60
- data/spec/chewy/search/parameters/stored_fields_spec.rb +0 -126
- data/spec/chewy/search/parameters/string_array_storage_examples.rb +0 -63
- data/spec/chewy/search/parameters/string_storage_examples.rb +0 -32
- data/spec/chewy/search/parameters/suggest_spec.rb +0 -5
- data/spec/chewy/search/parameters/terminate_after_spec.rb +0 -5
- data/spec/chewy/search/parameters/timeout_spec.rb +0 -5
- data/spec/chewy/search/parameters/track_scores_spec.rb +0 -5
- data/spec/chewy/search/parameters/track_total_hits_spec.rb +0 -5
- data/spec/chewy/search/parameters/version_spec.rb +0 -5
- data/spec/chewy/search/parameters_spec.rb +0 -161
- data/spec/chewy/search/query_proxy_spec.rb +0 -95
- data/spec/chewy/search/request_spec.rb +0 -886
- data/spec/chewy/search/response_spec.rb +0 -180
- data/spec/chewy/search/scrolling_spec.rb +0 -171
- data/spec/chewy/search_spec.rb +0 -127
- data/spec/chewy/stash_spec.rb +0 -85
- data/spec/chewy/strategy/active_job_spec.rb +0 -73
- data/spec/chewy/strategy/atomic_no_refresh_spec.rb +0 -60
- data/spec/chewy/strategy/atomic_spec.rb +0 -61
- data/spec/chewy/strategy/delayed_sidekiq_spec.rb +0 -225
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +0 -214
- data/spec/chewy/strategy/sidekiq_spec.rb +0 -52
- data/spec/chewy/strategy_spec.rb +0 -125
- data/spec/chewy_spec.rb +0 -100
- data/spec/spec_helper.rb +0 -69
- data/spec/support/active_record.rb +0 -124
- data/spec/support/class_helpers.rb +0 -16
- data/spec/support/fail_helpers.rb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 702dbe73f6b523156348491049ed540490d755d66c3242a2422c4da92090346c
|
|
4
|
+
data.tar.gz: 730beaf500e9d4feeafc5033bd028abc67662f9ae3299a95aa5d3f323f6ee011
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87105fad14e8959fabbad411e3b22af813b6261c0cff1a45f14205819e5564f03d936acf6fcd909ac152d98325c2619628c3732fa1eb628d6edb42a5b9670a95
|
|
7
|
+
data.tar.gz: b9f693b6e4180e9c2023456439e1de74c86dff2a453f50be369c50f30f7b419eab75173f2071707cf922457dc69fb9fc26cf0e82ad79034e3eea79212091a791
|
data/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## master (unreleased)
|
|
4
|
+
|
|
5
|
+
### New Features
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
### Changes
|
|
10
|
+
|
|
11
|
+
## 8.1.0 (2026-05-28)
|
|
12
|
+
|
|
13
|
+
### New Features
|
|
14
|
+
|
|
15
|
+
* [#887](https://github.com/toptal/chewy/pull/887): Add support [runtime_mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html). ([@TakuyaKurimoto](https://github.com/TakuyaKurimoto))
|
|
16
|
+
* [#996](https://github.com/toptal/chewy/pull/996): Add `context:` option to `import`/`import!` for passing custom data to crutch blocks and field value procs without redundant DB queries.
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* [#878](https://github.com/toptal/chewy/issues/878): Flatten `Chewy::Stash::Journal.for` to use a single `terms` filter instead of a chain of `bool.should` clauses. Fixes Elasticsearch `indices.query.bool.max_nested_depth` errors when applying or cleaning the journal across many indices.
|
|
21
|
+
|
|
22
|
+
### Changes
|
|
23
|
+
|
|
24
|
+
* [#916](https://github.com/toptal/chewy/pull/916): Raise error in #scroll_batches when search backend returns a failure. ([@tomdev][])
|
|
25
|
+
* [#1008](https://github.com/toptal/chewy/pull/1008): Promote Elasticsearch to a native GitHub Actions service with a health-check gate, replacing the fragile `docker compose` + `sleep 15` approach. ([@mattmenefee][])
|
|
26
|
+
* [#1010](https://github.com/toptal/chewy/pull/1010): Add Chewy 7/ES 7 to Chewy 8/ES 8 migration guide and fix stale `Elasticsearch::Transport` namespace references in docs. ([@mattmenefee][])
|
|
27
|
+
* [#1011](https://github.com/toptal/chewy/pull/1011): Replace deprecated `Sidekiq::Testing` API with new `Sidekiq 8.1+` testing API and silence Sidekiq logger during spec runs. ([@mattmenefee][], [@mjankowski][])
|
|
28
|
+
* [#1013](https://github.com/toptal/chewy/pull/1013): Fix `drop_indices` test helper to use `format: 'json'` for ES version portability. If you define a custom `drop_indices` helper in your test suite, update it to use `Chewy.client.cat.indices(format: 'json')` instead of parsing the text-format response. ([@mattmenefee][])
|
|
29
|
+
* [#1014](https://github.com/toptal/chewy/pull/1014): Improve contributing documentation with development setup instructions, PR workflow, and grammar fixes. ([@mattmenefee][])
|
|
30
|
+
|
|
31
|
+
## 8.0.1 (2026-03-12)
|
|
32
|
+
|
|
33
|
+
### New Features
|
|
34
|
+
|
|
35
|
+
### Changes
|
|
36
|
+
|
|
37
|
+
* [#1003](https://github.com/toptal/chewy/pull/1003): Ruby 4.0 support added [@mjankowski](https://github.com/mjankowski)
|
|
38
|
+
|
|
39
|
+
### Bugs Fixed
|
|
40
|
+
|
|
3
41
|
## 8.0.0 (2026-02-25)
|
|
4
42
|
|
|
5
43
|
### New Features
|
|
6
44
|
|
|
7
45
|
### Changes
|
|
46
|
+
* [#977](https://github.com/toptal/chewy/pull/977): Fewer files on gem installation [@ericproulx](https://github.com/ericproulx).
|
|
8
47
|
|
|
9
48
|
* **(Breaking)** Drop support for Ruby < 3.2 and Rails < 7.2. Chewy now requires Ruby ~> 3.2 and ActiveSupport >= 7.2. ([@bbatsov][])
|
|
10
49
|
|
|
@@ -863,10 +902,12 @@
|
|
|
863
902
|
[@marshall]: https://github.com/marshall
|
|
864
903
|
[@matchbookmac]: https://github.com/matchbookmac
|
|
865
904
|
[@matthee]: https://github.com/matthee
|
|
905
|
+
[@mattmenefee]: https://github.com/mattmenefee
|
|
866
906
|
[@mattzollinhofer]: https://github.com/mattzollinhofer
|
|
867
907
|
[@menglewis]: https://github.com/menglewis
|
|
868
908
|
[@mikeyhogarth]: https://github.com/mikeyhogarth
|
|
869
909
|
[@milk1000cc]: https://github.com/milk1000cc
|
|
910
|
+
[@mjankowski]: https://github.com/mjankowski
|
|
870
911
|
[@mkcode]: https://github.com/mkcode
|
|
871
912
|
[@mpeychich]: https://github.com/mpeychich
|
|
872
913
|
[@mrbrdo]: https://github.com/mrbrdo
|
|
@@ -890,6 +931,7 @@
|
|
|
890
931
|
[@socialchorus]: https://github.com/socialchorus
|
|
891
932
|
[@taylor-au]: https://github.com/taylor-au
|
|
892
933
|
[@TikiTDO]: https://github.com/TikiTDO
|
|
934
|
+
[@tomdev]: https://github.com/tomdev
|
|
893
935
|
[@undr]: https://github.com/undr
|
|
894
936
|
[@Vitalina-Vakulchyk]: https://github.com/Vitalina-Vakulchyk
|
|
895
937
|
[@webgago]: https://github.com/webgago
|
data/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
[](http://badge.fury.io/rb/chewy)
|
|
2
2
|
[](https://github.com/toptal/chewy/actions/workflows/ruby.yml)
|
|
3
|
-
[](https://codeclimate.com/github/toptal/chewy)
|
|
4
|
-
[](http://inch-ci.org/github/toptal/chewy)
|
|
5
3
|
|
|
6
4
|
# Chewy
|
|
7
5
|
|
|
@@ -47,13 +45,13 @@ Chewy aims to support all Ruby and Rails versions that are currently maintained
|
|
|
47
45
|
|
|
48
46
|
### Ruby
|
|
49
47
|
|
|
50
|
-
Chewy is compatible with MRI 3.2-
|
|
48
|
+
Chewy is compatible with MRI 3.2-4.0.
|
|
51
49
|
|
|
52
50
|
### Elasticsearch compatibility matrix
|
|
53
51
|
|
|
54
52
|
| Chewy version | Elasticsearch version |
|
|
55
53
|
| ------------- | ---------------------------------- |
|
|
56
|
-
| 8.0.
|
|
54
|
+
| 8.0.x | 8.x |
|
|
57
55
|
| 7.2.x | 7.x |
|
|
58
56
|
| 7.1.x | 7.x |
|
|
59
57
|
| 7.0.x | 6.8, 7.x |
|
|
@@ -236,6 +234,7 @@ end
|
|
|
236
234
|
|
|
237
235
|
## Documentation
|
|
238
236
|
|
|
237
|
+
- [Getting Started](docs/getting_started.md) — end-to-end tutorial building search for a media library
|
|
239
238
|
- [Configuration](docs/configuration.md) — client settings, update strategies, notifications, integrations
|
|
240
239
|
- [Indexing](docs/indexing.md) — index definition, field types, crutches, witchcraft, index manipulation
|
|
241
240
|
- [Import](docs/import.md) — import options, raw import, journaling
|
|
@@ -243,22 +242,37 @@ end
|
|
|
243
242
|
- [Rake Tasks](docs/rake_tasks.md) — all rake tasks and parallelization
|
|
244
243
|
- [Testing](docs/testing.md) — RSpec, Minitest, DatabaseCleaner
|
|
245
244
|
- [Troubleshooting](docs/troubleshooting.md) — pre-request filter
|
|
245
|
+
- [Non-Rails Usage](docs/non_rails.md) — using Chewy without Rails
|
|
246
246
|
|
|
247
|
-
##
|
|
247
|
+
## FAQ
|
|
248
248
|
|
|
249
|
-
|
|
250
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
251
|
-
3. Implement your changes, cover it with specs and make sure old specs are passing
|
|
252
|
-
4. Commit your changes (`git commit -am 'Add some feature'`)
|
|
253
|
-
5. Push to the branch (`git push origin my-new-feature`)
|
|
254
|
-
6. Create new Pull Request
|
|
249
|
+
**Can I use Chewy without Rails?**
|
|
255
250
|
|
|
256
|
-
|
|
251
|
+
Yes. ActiveSupport and the elasticsearch gem are the only hard dependencies; the Rails railtie loads conditionally. See the [Non-Rails Usage](docs/non_rails.md) guide.
|
|
257
252
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
253
|
+
**Does Chewy follow SemVer?**
|
|
254
|
+
|
|
255
|
+
No. The major version tracks the newest supported Elasticsearch version and minor version bumps may include breaking changes. Always check the [release notes](https://github.com/toptal/chewy/releases) before upgrading.
|
|
256
|
+
|
|
257
|
+
**Which versions of Ruby, Rails and Elasticsearch are supported?**
|
|
258
|
+
|
|
259
|
+
See the [Compatibility](#compatibility) section above. When a Ruby or Rails version reaches end-of-life we may drop support in a future release.
|
|
260
|
+
|
|
261
|
+
**What's the `UndefinedUpdateStrategy` error?**
|
|
262
|
+
|
|
263
|
+
Chewy raises this when you save a model with an `update_index` callback and no strategy is active. Wrap your code in `Chewy.strategy(:atomic) { ... }` or set `Chewy.root_strategy = :bypass`. See [Troubleshooting](docs/troubleshooting.md#undefinedupdatestrategy-error) for details.
|
|
264
|
+
|
|
265
|
+
**Can I use Chewy with OpenSearch?**
|
|
266
|
+
|
|
267
|
+
OpenSearch is not officially supported or tested. Chewy depends on the official `elasticsearch` Ruby client and targets Elasticsearch.
|
|
268
|
+
|
|
269
|
+
**How do I connect to Elastic Cloud?**
|
|
270
|
+
|
|
271
|
+
Use the standard client settings with your Cloud credentials (API key or user/password). See [Configuration](docs/configuration.md#client-settings) for examples.
|
|
272
|
+
|
|
273
|
+
## Contributing
|
|
274
|
+
|
|
275
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup instructions, how to run tests, and the pull request workflow.
|
|
262
276
|
|
|
263
277
|
## Copyright
|
|
264
278
|
|
data/lib/chewy/errors.rb
CHANGED
data/lib/chewy/fields/root.rb
CHANGED
|
@@ -61,8 +61,8 @@ module Chewy
|
|
|
61
61
|
# @param fields [Array<Symbol>] a list of fields to compose, every field will be composed if empty
|
|
62
62
|
# @return [Hash] JSON-ready hash with stringified keys
|
|
63
63
|
#
|
|
64
|
-
def compose(object, crutches = nil, fields: [])
|
|
65
|
-
result = evaluate([object, crutches])
|
|
64
|
+
def compose(object, crutches = nil, fields: [], context: {})
|
|
65
|
+
result = evaluate([object, crutches, context])
|
|
66
66
|
|
|
67
67
|
if children.present?
|
|
68
68
|
child_fields = if fields.present?
|
|
@@ -72,7 +72,7 @@ module Chewy
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
child_fields.each_with_object({}) do |field, memo|
|
|
75
|
-
memo.merge!(field.compose(result, crutches) || {})
|
|
75
|
+
memo.merge!(field.compose(result, crutches, context) || {})
|
|
76
76
|
end.as_json
|
|
77
77
|
elsif fields.present?
|
|
78
78
|
result.as_json(only: fields, root: false)
|
data/lib/chewy/index/crutch.rb
CHANGED
|
@@ -9,9 +9,12 @@ module Chewy
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
class Crutches
|
|
12
|
-
|
|
12
|
+
attr_reader :context
|
|
13
|
+
|
|
14
|
+
def initialize(index, collection, context = {})
|
|
13
15
|
@index = index
|
|
14
16
|
@collection = collection
|
|
17
|
+
@context = context
|
|
15
18
|
@crutches_instances = {}
|
|
16
19
|
end
|
|
17
20
|
|
|
@@ -26,7 +29,14 @@ module Chewy
|
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
def [](name)
|
|
29
|
-
@crutches_instances[name] ||=
|
|
32
|
+
@crutches_instances[name] ||= begin
|
|
33
|
+
block = @index._crutches[:"#{name}"]
|
|
34
|
+
if block.arity > 1 || block.arity < -1
|
|
35
|
+
block.call(@collection, @context)
|
|
36
|
+
else
|
|
37
|
+
block.call(@collection)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
30
40
|
end
|
|
31
41
|
end
|
|
32
42
|
|
|
@@ -13,11 +13,12 @@ module Chewy
|
|
|
13
13
|
# @param to_index [Array<Object>] objects to index
|
|
14
14
|
# @param delete [Array<Object>] objects or ids to delete
|
|
15
15
|
# @param fields [Array<Symbol, String>] and array of fields for documents update
|
|
16
|
-
def initialize(index, to_index: [], delete: [], fields: [])
|
|
16
|
+
def initialize(index, to_index: [], delete: [], fields: [], context: {})
|
|
17
17
|
@index = index
|
|
18
18
|
@to_index = to_index
|
|
19
19
|
@delete = delete
|
|
20
20
|
@fields = fields.map!(&:to_sym)
|
|
21
|
+
@context = context
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
# Returns ES API-ready bulk requiest body.
|
|
@@ -42,7 +43,7 @@ module Chewy
|
|
|
42
43
|
private
|
|
43
44
|
|
|
44
45
|
def crutches_for_index
|
|
45
|
-
@crutches_for_index ||= Chewy::Index::Crutch::Crutches.new @index, @to_index
|
|
46
|
+
@crutches_for_index ||= Chewy::Index::Crutch::Crutches.new @index, @to_index, @context
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
def index_entry(object)
|
|
@@ -257,7 +258,7 @@ module Chewy
|
|
|
257
258
|
end
|
|
258
259
|
|
|
259
260
|
def data_for(object, fields: [], crutches: crutches_for_index)
|
|
260
|
-
@index.compose(object, crutches, fields: fields)
|
|
261
|
+
@index.compose(object, crutches, fields: fields, context: @context)
|
|
261
262
|
end
|
|
262
263
|
|
|
263
264
|
def parent_changed?(data, old_parent)
|
|
@@ -56,6 +56,7 @@ module Chewy
|
|
|
56
56
|
{}
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
|
+
@context = @options[:context] || {}
|
|
59
60
|
@errors = []
|
|
60
61
|
@stats = {}
|
|
61
62
|
@leftovers = []
|
|
@@ -78,7 +79,7 @@ module Chewy
|
|
|
78
79
|
# @param delete [Array<Object>] any acceptable objects for deleting
|
|
79
80
|
# @return [true, false] the result of the request, true if no errors
|
|
80
81
|
def process(index: [], delete: [])
|
|
81
|
-
bulk_builder = BulkBuilder.new(@index, to_index: index, delete: delete, fields: @options[:update_fields])
|
|
82
|
+
bulk_builder = BulkBuilder.new(@index, to_index: index, delete: delete, fields: @options[:update_fields], context: @context)
|
|
82
83
|
bulk_body = bulk_builder.bulk_body
|
|
83
84
|
|
|
84
85
|
if @options[:journal]
|
data/lib/chewy/index/import.rb
CHANGED
|
@@ -115,13 +115,13 @@ module Chewy
|
|
|
115
115
|
# @param crutches [Object] optional crutches object; if omitted - a crutch for the single passed object is created as a fallback
|
|
116
116
|
# @param fields [Array<Symbol>] and array of fields to restrict the generated document
|
|
117
117
|
# @return [Hash] a JSON-ready hash
|
|
118
|
-
def compose(object, crutches = nil, fields: [])
|
|
119
|
-
crutches ||= Chewy::Index::Crutch::Crutches.new self, [object]
|
|
118
|
+
def compose(object, crutches = nil, fields: [], context: {})
|
|
119
|
+
crutches ||= Chewy::Index::Crutch::Crutches.new self, [object], context
|
|
120
120
|
|
|
121
121
|
if witchcraft? && root.children.present?
|
|
122
|
-
cauldron(fields: fields).brew(object, crutches)
|
|
122
|
+
cauldron(fields: fields).brew(object, crutches, context)
|
|
123
123
|
else
|
|
124
|
-
root.compose(object, crutches, fields: fields)
|
|
124
|
+
root.compose(object, crutches, fields: fields, context: context)
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
begin
|
|
2
2
|
require 'method_source'
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'prism'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require 'parser/current'
|
|
7
|
+
end
|
|
4
8
|
require 'unparser'
|
|
5
9
|
rescue LoadError
|
|
6
10
|
nil
|
|
@@ -24,7 +28,11 @@ module Chewy
|
|
|
24
28
|
def check_requirements!
|
|
25
29
|
messages = []
|
|
26
30
|
messages << "MethodSource gem is required for the Witchcraft, please add `gem 'method_source'` to your Gemfile" unless Proc.method_defined?(:source)
|
|
27
|
-
|
|
31
|
+
if RUBY_VERSION >= '3.3'
|
|
32
|
+
messages << "Prism gem is required for the Witchcraft, please add `gem 'prism'` to your Gemfile" unless '::Prism'.safe_constantize
|
|
33
|
+
else
|
|
34
|
+
messages << "Parser gem is required for the Witchcraft, please add `gem 'parser'` to your Gemfile" unless '::Parser'.safe_constantize
|
|
35
|
+
end
|
|
28
36
|
messages << "Unparser gem is required for the Witchcraft, please add `gem 'unparser'` to your Gemfile" unless '::Unparser'.safe_constantize
|
|
29
37
|
messages = messages.join("\n")
|
|
30
38
|
|
|
@@ -51,15 +59,15 @@ module Chewy
|
|
|
51
59
|
@fields = fields
|
|
52
60
|
end
|
|
53
61
|
|
|
54
|
-
def brew(object, crutches = nil)
|
|
55
|
-
alicorn.call(locals, object, crutches).as_json
|
|
62
|
+
def brew(object, crutches = nil, context = {})
|
|
63
|
+
alicorn.call(locals, object, crutches, context).as_json
|
|
56
64
|
end
|
|
57
65
|
|
|
58
66
|
private
|
|
59
67
|
|
|
60
68
|
def alicorn
|
|
61
69
|
@alicorn ||= singleton_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
62
|
-
-> (locals, object0, crutches) do
|
|
70
|
+
-> (locals, object0, crutches, context) do
|
|
63
71
|
#{composed_values(@index.root, 0)}
|
|
64
72
|
end
|
|
65
73
|
RUBY
|
|
@@ -163,9 +171,8 @@ module Chewy
|
|
|
163
171
|
end
|
|
164
172
|
end
|
|
165
173
|
|
|
166
|
-
def source_for(proc, nesting)
|
|
167
|
-
|
|
168
|
-
lambdas = exctract_lambdas(ast)
|
|
174
|
+
def source_for(proc, nesting) # rubocop:disable Metrics/AbcSize
|
|
175
|
+
lambdas = exctract_lambdas(ast_from_proc(proc))
|
|
169
176
|
|
|
170
177
|
raise "No lambdas found, try to reformat your code:\n`#{proc.source}`" unless lambdas
|
|
171
178
|
|
|
@@ -182,6 +189,7 @@ module Chewy
|
|
|
182
189
|
source = replace_lvar(source, proc_params[n], :"object#{n}") if proc_params[n]
|
|
183
190
|
end
|
|
184
191
|
source = replace_lvar(source, proc_params[nesting + 1], :crutches) if proc_params[nesting + 1]
|
|
192
|
+
source = replace_lvar(source, proc_params[nesting + 2], :context) if proc_params[nesting + 2]
|
|
185
193
|
|
|
186
194
|
binding_variable_list(source).each do |variable|
|
|
187
195
|
locals.push(proc.binding.eval(variable.to_s))
|
|
@@ -192,6 +200,14 @@ module Chewy
|
|
|
192
200
|
Unparser.unparse(source)
|
|
193
201
|
end
|
|
194
202
|
|
|
203
|
+
def ast_from_proc(proc)
|
|
204
|
+
if defined?(Prism)
|
|
205
|
+
Prism::Translation::ParserCurrent.parse(proc.source)
|
|
206
|
+
else
|
|
207
|
+
Parser::CurrentRuby.parse(proc.source)
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
195
211
|
def exctract_lambdas(node)
|
|
196
212
|
return unless node.is_a?(Parser::AST::Node)
|
|
197
213
|
|
data/lib/chewy/multi_search.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Chewy
|
|
|
11
11
|
# Instantiate a new MultiSearch instance.
|
|
12
12
|
#
|
|
13
13
|
# @param queries [Array<Chewy::Search::Request>]
|
|
14
|
-
# @option [Elasticsearch::
|
|
14
|
+
# @option [Elasticsearch::Client] :client (Chewy.client)
|
|
15
15
|
# The Elasticsearch client that should be used for issuing requests.
|
|
16
16
|
def initialize(queries, client: Chewy.client)
|
|
17
17
|
@client = client
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Chewy
|
|
2
|
+
module Search
|
|
3
|
+
class Parameters
|
|
4
|
+
# Just a standard hash storage. Nothing to see here.
|
|
5
|
+
#
|
|
6
|
+
# @see Chewy::Search::Parameters::HashStorage
|
|
7
|
+
# @see Chewy::Search::Request#runtime_mappings
|
|
8
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html
|
|
9
|
+
class RuntimeMappings < Storage
|
|
10
|
+
include HashStorage
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/chewy/search/request.rb
CHANGED
|
@@ -25,7 +25,7 @@ module Chewy
|
|
|
25
25
|
search_type preference limit offset terminate_after
|
|
26
26
|
timeout min_score source stored_fields search_after
|
|
27
27
|
load script_fields suggest aggs aggregations collapse none
|
|
28
|
-
indices_boost rescore highlight total total_count
|
|
28
|
+
indices_boost rescore highlight runtime_mappings total total_count
|
|
29
29
|
total_entries indices types delete_all count exists?
|
|
30
30
|
exist? find pluck scroll_batches scroll_hits
|
|
31
31
|
scroll_results scroll_wrappers ignore_unavailable
|
|
@@ -656,7 +656,23 @@ module Chewy
|
|
|
656
656
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
|
|
657
657
|
# @param value [Hash]
|
|
658
658
|
# @return [Chewy::Search::Request]
|
|
659
|
-
|
|
659
|
+
#
|
|
660
|
+
# @!method runtime_mappings(value)
|
|
661
|
+
# Add a `runtime_mappings` part to the request. Further
|
|
662
|
+
# call values are merged to the storage hash.
|
|
663
|
+
#
|
|
664
|
+
# @example
|
|
665
|
+
# PlacesIndex
|
|
666
|
+
# .runtime_mappings(field1: {type: "keyword", script: {lang: "painless", source: "emit('some script here')"}})
|
|
667
|
+
# .runtime_mappings(field2: {type: "keyword", script: {lang: "painless", source: "emit('some script here')"}})
|
|
668
|
+
# # => <PlacesIndex::Query {..., :body=>{:runtime_mappings=>{
|
|
669
|
+
# # "field1"=>{:type=>"keyword", :script=>{:lang=>"painless", :source=>"emit('some script here')"}},
|
|
670
|
+
# # "field2"=>{:type=>"keyword", :script=>{:lang=>"painless", :source=>"emit('some script here')"}}}}}>
|
|
671
|
+
# @see Chewy::Search::Parameters::RuntimeMappings
|
|
672
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html
|
|
673
|
+
# @param value [Hash]
|
|
674
|
+
# @return [Chewy::Search::Request]
|
|
675
|
+
%i[script_fields indices_boost rescore highlight runtime_mappings].each do |name|
|
|
660
676
|
define_method name do |value|
|
|
661
677
|
modify(name) { update!(value) }
|
|
662
678
|
end
|
|
@@ -29,20 +29,28 @@ module Chewy
|
|
|
29
29
|
|
|
30
30
|
result = perform(size: batch_size, scroll: scroll)
|
|
31
31
|
total = [raw_limit_value, result.fetch('hits', {}).fetch('total', {}).fetch('value', 0)].compact.min
|
|
32
|
+
|
|
33
|
+
total_batches = total / batch_size
|
|
32
34
|
last_batch_size = total % batch_size
|
|
33
|
-
|
|
35
|
+
|
|
36
|
+
total_batches += 1 if last_batch_size != 0
|
|
37
|
+
|
|
34
38
|
scroll_id = nil
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
total_batches.times do |batch_counter|
|
|
41
|
+
last_run = total_batches - 1 == batch_counter
|
|
42
|
+
|
|
37
43
|
hits = result.fetch('hits', {}).fetch('hits', [])
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
hits = hits.first(last_batch_size) if last_run && last_batch_size != 0
|
|
45
|
+
|
|
46
|
+
raise Chewy::MissingHitsInScrollError if hits.empty?
|
|
47
|
+
|
|
40
48
|
yield(hits) if hits.present?
|
|
41
49
|
scroll_id = result['_scroll_id']
|
|
42
50
|
|
|
43
|
-
break if result['terminated_early']
|
|
51
|
+
break if result['terminated_early']
|
|
44
52
|
|
|
45
|
-
result = perform_scroll(scroll: scroll, scroll_id: scroll_id)
|
|
53
|
+
result = perform_scroll(scroll: scroll, scroll_id: scroll_id) unless last_run
|
|
46
54
|
end
|
|
47
55
|
ensure
|
|
48
56
|
Chewy.client.clear_scroll(body: {scroll_id: scroll_id}) if scroll_id
|
data/lib/chewy/stash.rb
CHANGED
|
@@ -38,17 +38,21 @@ module Chewy
|
|
|
38
38
|
|
|
39
39
|
# Selects all the journal entries for the specified indices.
|
|
40
40
|
#
|
|
41
|
+
# Uses a single `terms` filter rather than a chain of `bool.should`
|
|
42
|
+
# clauses so the query depth stays constant regardless of how many
|
|
43
|
+
# indices are passed. Avoids hitting the Elasticsearch
|
|
44
|
+
# `indices.query.bool.max_nested_depth` limit (default 30) when
|
|
45
|
+
# cleaning or applying journals across many indices.
|
|
46
|
+
#
|
|
41
47
|
# @param indices [Chewy::Index, Array<Chewy::Index>]
|
|
42
48
|
def self.for(*something)
|
|
43
49
|
something = something.flatten.compact
|
|
50
|
+
return all if something.empty?
|
|
51
|
+
|
|
44
52
|
indexes = something.flat_map { |s| Chewy.derive_name(s) }
|
|
45
|
-
return none if
|
|
53
|
+
return none if indexes.blank?
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
indexes.each do |index|
|
|
49
|
-
scope = scope.or(filter(term: {index_name: index.derivable_name}))
|
|
50
|
-
end
|
|
51
|
-
scope
|
|
55
|
+
filter(terms: {index_name: indexes.map(&:derivable_name).uniq})
|
|
52
56
|
end
|
|
53
57
|
|
|
54
58
|
default_import_options journal: false
|
data/lib/chewy/version.rb
CHANGED