chewy 0.10.1 → 7.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -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/.github/workflows/ruby.yml +74 -0
- data/.rubocop.yml +28 -23
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +480 -298
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +3 -5
- data/Guardfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +571 -333
- data/chewy.gemspec +12 -15
- data/gemfiles/rails.5.2.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
- data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
- data/lib/chewy/config.rb +48 -77
- data/lib/chewy/errors.rb +4 -10
- data/lib/chewy/fields/base.rb +88 -16
- data/lib/chewy/fields/root.rb +15 -21
- data/lib/chewy/index/actions.rb +67 -38
- data/lib/chewy/{type → index}/adapter/active_record.rb +18 -4
- data/lib/chewy/{type → index}/adapter/base.rb +11 -12
- data/lib/chewy/{type → index}/adapter/object.rb +28 -32
- data/lib/chewy/{type → index}/adapter/orm.rb +26 -24
- data/lib/chewy/index/aliases.rb +14 -5
- data/lib/chewy/index/crutch.rb +40 -0
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/{type → index}/import/bulk_request.rb +10 -9
- data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
- data/lib/chewy/{type → index}/import/routine.rb +19 -18
- data/lib/chewy/{type → index}/import.rb +82 -36
- data/lib/chewy/{type → index}/mapping.rb +63 -62
- data/lib/chewy/index/observe/active_record_methods.rb +87 -0
- data/lib/chewy/index/observe/callback.rb +34 -0
- data/lib/chewy/index/observe.rb +17 -0
- data/lib/chewy/index/settings.rb +2 -0
- data/lib/chewy/index/specification.rb +13 -10
- data/lib/chewy/{type → index}/syncer.rb +62 -63
- data/lib/chewy/{type → index}/witchcraft.rb +15 -9
- data/lib/chewy/{type → index}/wrapper.rb +16 -6
- data/lib/chewy/index.rb +68 -93
- data/lib/chewy/journal.rb +25 -14
- data/lib/chewy/minitest/helpers.rb +91 -18
- data/lib/chewy/minitest/search_index_receiver.rb +29 -33
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +8 -24
- data/lib/chewy/rake_helper.rb +141 -112
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +58 -49
- data/lib/chewy/rspec.rb +2 -0
- data/lib/chewy/runtime.rb +1 -1
- data/lib/chewy/search/loader.rb +19 -41
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/collapse.rb +16 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +6 -5
- data/lib/chewy/search/parameters/ignore_unavailable.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/parameters/order.rb +6 -19
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
- data/lib/chewy/search/parameters.rb +28 -8
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +207 -157
- data/lib/chewy/search/response.rb +5 -5
- data/lib/chewy/search/scoping.rb +7 -8
- data/lib/chewy/search/scrolling.rb +14 -13
- data/lib/chewy/search.rb +7 -26
- data/lib/chewy/stash.rb +27 -29
- data/lib/chewy/strategy/active_job.rb +2 -2
- data/lib/chewy/strategy/atomic.rb +1 -1
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +10 -0
- data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +148 -0
- data/lib/chewy/strategy/delayed_sidekiq/worker.rb +52 -0
- data/lib/chewy/strategy/delayed_sidekiq.rb +17 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +3 -2
- data/lib/chewy/strategy.rb +6 -19
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +37 -80
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +26 -32
- data/migration_guide.md +56 -0
- data/spec/chewy/config_spec.rb +27 -57
- data/spec/chewy/fields/base_spec.rb +457 -174
- data/spec/chewy/fields/root_spec.rb +24 -32
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +425 -60
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +110 -44
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/index/aliases_spec.rb +3 -3
- data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -12
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +22 -30
- data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
- data/spec/chewy/{type → index}/import_spec.rb +154 -95
- data/spec/chewy/index/mapping_spec.rb +135 -0
- data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
- data/spec/chewy/index/observe/callback_spec.rb +139 -0
- data/spec/chewy/index/observe_spec.rb +143 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +32 -33
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +34 -21
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +99 -114
- data/spec/chewy/journal_spec.rb +56 -101
- data/spec/chewy/minitest/helpers_spec.rb +122 -14
- data/spec/chewy/minitest/search_index_receiver_spec.rb +24 -26
- data/spec/chewy/multi_search_spec.rb +84 -0
- data/spec/chewy/rake_helper_spec.rb +325 -101
- data/spec/chewy/rspec/build_query_spec.rb +34 -0
- data/spec/chewy/rspec/helpers_spec.rb +61 -0
- data/spec/chewy/rspec/update_index_spec.rb +106 -102
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +19 -53
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
- data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
- data/spec/chewy/search/parameters/indices_spec.rb +99 -0
- data/spec/chewy/search/parameters/none_spec.rb +1 -1
- data/spec/chewy/search/parameters/order_spec.rb +18 -11
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +39 -8
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +360 -149
- data/spec/chewy/search/response_spec.rb +35 -25
- data/spec/chewy/search/scrolling_spec.rb +28 -26
- data/spec/chewy/search_spec.rb +73 -53
- data/spec/chewy/stash_spec.rb +16 -26
- data/spec/chewy/strategy/active_job_spec.rb +23 -10
- data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/delayed_sidekiq_spec.rb +190 -0
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +14 -10
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +17 -110
- data/spec/spec_helper.rb +7 -22
- data/spec/support/active_record.rb +43 -5
- metadata +123 -198
- data/.travis.yml +0 -53
- data/Appraisals +0 -79
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.0.activerecord.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.gemfile +0 -15
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.0.mongoid.6.0.gemfile +0 -15
- data/gemfiles/rails.5.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.5.1.mongoid.6.1.gemfile +0 -15
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/backports/deep_dup.rb +0 -46
- data/lib/chewy/backports/duplicable.rb +0 -91
- data/lib/chewy/query/compose.rb +0 -68
- data/lib/chewy/query/criteria.rb +0 -191
- data/lib/chewy/query/filters.rb +0 -227
- data/lib/chewy/query/loading.rb +0 -111
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -34
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -110
- data/lib/chewy/query/nodes/has_child.rb +0 -15
- data/lib/chewy/query/nodes/has_parent.rb +0 -15
- data/lib/chewy/query/nodes/has_relation.rb +0 -59
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -19
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -35
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination.rb +0 -25
- data/lib/chewy/query.rb +0 -1098
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/search/parameters/types.rb +0 -20
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -69
- data/lib/chewy/type/adapter/sequel.rb +0 -95
- data/lib/chewy/type/crutch.rb +0 -32
- data/lib/chewy/type/import/bulk_builder.rb +0 -122
- data/lib/chewy/type/observe.rb +0 -78
- data/lib/chewy/type.rb +0 -117
- data/lib/sequel/plugins/chewy_observe.rb +0 -78
- data/spec/chewy/query/criteria_spec.rb +0 -700
- data/spec/chewy/query/filters_spec.rb +0 -201
- data/spec/chewy/query/loading_spec.rb +0 -124
- data/spec/chewy/query/nodes/and_spec.rb +0 -12
- data/spec/chewy/query/nodes/bool_spec.rb +0 -14
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -16
- data/spec/chewy/query/nodes/not_spec.rb +0 -13
- data/spec/chewy/query/nodes/or_spec.rb +0 -12
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
- data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
- data/spec/chewy/query/pagination_spec.rb +0 -39
- data/spec/chewy/query_spec.rb +0 -636
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
- data/spec/chewy/search/parameters/types_spec.rb +0 -5
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -64
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/import/bulk_builder_spec.rb +0 -279
- data/spec/chewy/type/mapping_spec.rb +0 -142
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -98
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
data/lib/chewy/search/request.rb
CHANGED
@@ -1,33 +1,34 @@
|
|
1
1
|
module Chewy
|
2
2
|
module Search
|
3
|
-
# The main
|
4
|
-
# Supports
|
3
|
+
# The main request DSL class. Supports multiple index requests.
|
4
|
+
# Supports ES5 search API and query DSL.
|
5
5
|
#
|
6
6
|
# @note The class tries to be as immutable as possible,
|
7
7
|
# so most of the methods return a new instance of the class.
|
8
8
|
# @see Chewy::Search
|
9
9
|
# @example
|
10
10
|
# scope = Chewy::Search::Request.new(PlacesIndex)
|
11
|
-
# # => <Chewy::Search::Request {:index=>["places"], :
|
11
|
+
# # => <Chewy::Search::Request {:index=>["places"], :body=>{}}>
|
12
12
|
# scope.limit(20)
|
13
|
-
# # => <Chewy::Search::Request {:index=>["places"], :
|
13
|
+
# # => <Chewy::Search::Request {:index=>["places"], :body=>{:size=>20}}>
|
14
14
|
# scope.order(:name).offset(10)
|
15
|
-
# # => <Chewy::Search::Request {:index=>["places"], :
|
15
|
+
# # => <Chewy::Search::Request {:index=>["places"], :body=>{:sort=>["name"], :from=>10}}>
|
16
16
|
class Request
|
17
17
|
include Enumerable
|
18
18
|
include Scoping
|
19
19
|
include Scrolling
|
20
20
|
UNDEFINED = Class.new.freeze
|
21
|
-
EVERFIELDS = %w[_index _type _id _parent].freeze
|
21
|
+
EVERFIELDS = %w[_index _type _id _parent _routing].freeze
|
22
22
|
DELEGATED_METHODS = %i[
|
23
23
|
query filter post_filter order reorder docvalue_fields
|
24
|
-
track_scores request_cache explain version profile
|
24
|
+
track_scores track_total_hits request_cache explain version profile
|
25
25
|
search_type preference limit offset terminate_after
|
26
26
|
timeout min_score source stored_fields search_after
|
27
|
-
load script_fields suggest aggs aggregations none
|
27
|
+
load script_fields suggest aggs aggregations collapse none
|
28
28
|
indices_boost rescore highlight total total_count
|
29
|
-
total_entries types delete_all count exists?
|
30
|
-
scroll_batches scroll_hits
|
29
|
+
total_entries indices types delete_all count exists?
|
30
|
+
exist? find pluck scroll_batches scroll_hits
|
31
|
+
scroll_results scroll_wrappers ignore_unavailable
|
31
32
|
].to_set.freeze
|
32
33
|
DEFAULT_BATCH_SIZE = 1000
|
33
34
|
DEFAULT_PLUCK_BATCH_SIZE = 10_000
|
@@ -40,35 +41,33 @@ module Chewy
|
|
40
41
|
EXTRA_STORAGES = %i[aggs suggest].freeze
|
41
42
|
# An array of storage names that are changing the returned hist collection in any way.
|
42
43
|
WHERE_STORAGES = %i[
|
43
|
-
query filter post_filter none
|
44
|
+
query filter post_filter none min_score rescore indices_boost collapse
|
44
45
|
].freeze
|
45
46
|
|
46
47
|
delegate :hits, :wrappers, :objects, :records, :documents,
|
47
|
-
|
48
|
-
|
48
|
+
:object_hash, :record_hash, :document_hash,
|
49
|
+
:total, :max_score, :took, :timed_out?, to: :response
|
49
50
|
delegate :each, :size, :to_a, :[], to: :wrappers
|
50
51
|
alias_method :to_ary, :to_a
|
51
52
|
alias_method :total_count, :total
|
52
53
|
alias_method :total_entries, :total
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
#
|
57
|
-
# types, which are later used to compose requests.
|
55
|
+
# The class is initialized with the list of chewy indexes,
|
56
|
+
# which are later used to compose requests.
|
57
|
+
# Any symbol/string passed is treated as an index identifier.
|
58
58
|
#
|
59
59
|
# @example
|
60
|
+
# Chewy::Search::Request.new(:places)
|
61
|
+
# # => <Chewy::Search::Request {:index=>["places"], :body=>{}}>
|
60
62
|
# Chewy::Search::Request.new(PlacesIndex)
|
61
|
-
# # => <Chewy::Search::Request {:index=>["places"], :
|
62
|
-
# Chewy::Search::Request.new(PlacesIndex
|
63
|
-
# # => <Chewy::Search::Request {:index=>["places"], :
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@_indexes = indexes_or_types.select { |klass| klass < Chewy::Index }
|
70
|
-
@_types |= @_indexes.flat_map(&:types)
|
71
|
-
@_indexes |= @_types.map(&:index)
|
63
|
+
# # => <Chewy::Search::Request {:index=>["places"], :body=>{}}>
|
64
|
+
# Chewy::Search::Request.new(UsersIndex, PlacesIndex)
|
65
|
+
# # => <Chewy::Search::Request {:index=>["users", "places"], :body=>{}}>
|
66
|
+
# @param indexes [Array<Chewy::Index, String, Symbol>] indexes
|
67
|
+
def initialize(*indexes)
|
68
|
+
parameters.modify!(:indices) do
|
69
|
+
replace!(indices: indexes)
|
70
|
+
end
|
72
71
|
end
|
73
72
|
|
74
73
|
# Underlying parameter storage collection.
|
@@ -103,14 +102,23 @@ module Chewy
|
|
103
102
|
# @see Chewy::Search::Response
|
104
103
|
# @return [Chewy::Search::Response] a response object instance
|
105
104
|
def response
|
106
|
-
@response ||=
|
105
|
+
@response ||= build_response(perform)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Wraps and sets the raw Elasticsearch response to provide access
|
109
|
+
# to convenience methods.
|
110
|
+
#
|
111
|
+
# @see Chewy::Search::Response
|
112
|
+
# @param from_elasticsearch [Hash] An Elasticsearch response
|
113
|
+
def response=(from_elasticsearch)
|
114
|
+
@response = build_response(from_elasticsearch)
|
107
115
|
end
|
108
116
|
|
109
117
|
# ES request body
|
110
118
|
#
|
111
119
|
# @return [Hash] request body
|
112
120
|
def render
|
113
|
-
@render ||=
|
121
|
+
@render ||= parameters.render
|
114
122
|
end
|
115
123
|
|
116
124
|
# Includes the class name and the result of rendering.
|
@@ -120,17 +128,17 @@ module Chewy
|
|
120
128
|
"<#{self.class} #{render}>"
|
121
129
|
end
|
122
130
|
|
123
|
-
# @!group Chainable request
|
131
|
+
# @!group Chainable request modifications
|
124
132
|
|
125
133
|
# @!method query(query_hash=nil, &block)
|
126
|
-
# Adds `
|
134
|
+
# Adds `query` parameter to the search request body.
|
127
135
|
#
|
128
136
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-query.html
|
129
137
|
# @see Chewy::Search::Parameters::Query
|
130
138
|
# @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
|
131
139
|
#
|
132
140
|
# @overload query(query_hash)
|
133
|
-
# If pure hash is passed it goes straight to the `
|
141
|
+
# If pure hash is passed it goes straight to the `query` parameter storage.
|
134
142
|
# Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
|
135
143
|
#
|
136
144
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
|
@@ -149,7 +157,7 @@ module Chewy
|
|
149
157
|
# @example
|
150
158
|
# PlacesIndex.query { match name: 'Moscow' }
|
151
159
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:match=>{:name=>"Moscow"}}}}>
|
152
|
-
# @yield the block is processed by `elasticsearch-
|
160
|
+
# @yield the block is processed by `elasticsearch-dsl` gem
|
153
161
|
# @return [Chewy::Search::Request]
|
154
162
|
#
|
155
163
|
# @overload query
|
@@ -165,7 +173,7 @@ module Chewy
|
|
165
173
|
# @return [Chewy::Search::QueryProxy]
|
166
174
|
#
|
167
175
|
# @!method filter(query_hash=nil, &block)
|
168
|
-
# Adds `
|
176
|
+
# Adds `filter` context of the `query` parameter at the
|
169
177
|
# search request body.
|
170
178
|
#
|
171
179
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html
|
@@ -173,7 +181,7 @@ module Chewy
|
|
173
181
|
# @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
|
174
182
|
#
|
175
183
|
# @overload filter(query_hash)
|
176
|
-
# If pure hash is passed it goes straight to the `
|
184
|
+
# If pure hash is passed it goes straight to the `filter` context of the `query` parameter storage.
|
177
185
|
# Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
|
178
186
|
#
|
179
187
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
|
@@ -194,7 +202,7 @@ module Chewy
|
|
194
202
|
# PlacesIndex.filter { match name: 'Moscow' }
|
195
203
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
196
204
|
# # :filter=>{:match=>{:name=>"Moscow"}}}}}}>
|
197
|
-
# @yield the block is processed by `elasticsearch-
|
205
|
+
# @yield the block is processed by `elasticsearch-dsl` gem
|
198
206
|
# @return [Chewy::Search::Request]
|
199
207
|
#
|
200
208
|
# @overload filter
|
@@ -212,7 +220,7 @@ module Chewy
|
|
212
220
|
# @!method post_filter(query_hash=nil, &block)
|
213
221
|
# Adds `post_filter` parameter to the search request body.
|
214
222
|
#
|
215
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-
|
223
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-search-results.html#post-filter
|
216
224
|
# @see Chewy::Search::Parameters::PostFilter
|
217
225
|
# @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
|
218
226
|
#
|
@@ -236,7 +244,7 @@ module Chewy
|
|
236
244
|
# @example
|
237
245
|
# PlacesIndex.post_filter { match name: 'Moscow' }
|
238
246
|
# # => <PlacesIndex::Query {..., :body=>{:post_filter=>{:match=>{:name=>"Moscow"}}}}>
|
239
|
-
# @yield the block is processed by `elasticsearch-
|
247
|
+
# @yield the block is processed by `elasticsearch-dsl` gem
|
240
248
|
# @return [Chewy::Search::Request]
|
241
249
|
#
|
242
250
|
# @overload post_filter
|
@@ -267,7 +275,7 @@ module Chewy
|
|
267
275
|
# PlacesIndex.order(:name, population: {order: :asc}).order(:coordinates)
|
268
276
|
# # => <PlacesIndex::Query {..., :body=>{:sort=>["name", {"population"=>{:order=>:asc}}, "coordinates"]}}>
|
269
277
|
# @see Chewy::Search::Parameters::Order
|
270
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-
|
278
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html
|
271
279
|
# @param values [Array<Hash, String, Symbol>] sort fields and options
|
272
280
|
# @return [Chewy::Search::Request]
|
273
281
|
#
|
@@ -278,27 +286,29 @@ module Chewy
|
|
278
286
|
# PlacesIndex.docvalue_fields(:name).docvalue_fields(:population, :coordinates)
|
279
287
|
# # => <PlacesIndex::Query {..., :body=>{:docvalue_fields=>["name", "population", "coordinates"]}}>
|
280
288
|
# @see Chewy::Search::Parameters::DocvalueFields
|
281
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-
|
289
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#docvalue-fields
|
282
290
|
# @param values [Array<String, Symbol>] field names
|
283
291
|
# @return [Chewy::Search::Request]
|
284
|
-
|
285
|
-
# @!method types(*values)
|
286
|
-
# Modifies `types` request parameter. Updates the storage on every call.
|
287
|
-
# Constrains types passed on the request initialization.
|
288
|
-
#
|
289
|
-
# @example
|
290
|
-
# PlacesIndex.types(:city).types(:unexistent)
|
291
|
-
# # => <PlacesIndex::Query {:index=>["places"], :type=>["city"]}>
|
292
|
-
# @see Chewy::Search::Parameters::Types
|
293
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
|
294
|
-
# @param values [Array<String, Symbol>] type names
|
295
|
-
# @return [Chewy::Search::Request]
|
296
|
-
%i[order docvalue_fields types].each do |name|
|
292
|
+
%i[order docvalue_fields].each do |name|
|
297
293
|
define_method name do |value, *values|
|
298
294
|
modify(name) { update!([value, *values]) }
|
299
295
|
end
|
300
296
|
end
|
301
297
|
|
298
|
+
# Modifies `index` request parameter. Updates the storage on every call.
|
299
|
+
# Added passed indexes to the parameter list.
|
300
|
+
#
|
301
|
+
# @example
|
302
|
+
# UsersIndex.indices(CitiesIndex).indices(:another)
|
303
|
+
# # => <UsersIndex::Query {:index=>["another", "cities", "users"]}>
|
304
|
+
# @see Chewy::Search::Parameters::Indices
|
305
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
|
306
|
+
# @param values [Array<Chewy::Index, String, Symbol>] index names
|
307
|
+
# @return [Chewy::Search::Request]
|
308
|
+
def indices(value, *values)
|
309
|
+
modify(:indices) { update!(indices: [value, *values]) }
|
310
|
+
end
|
311
|
+
|
302
312
|
# @overload reorder(*values)
|
303
313
|
# Replaces the value of the `sort` parameter with the provided value.
|
304
314
|
#
|
@@ -306,7 +316,7 @@ module Chewy
|
|
306
316
|
# PlacesIndex.order(:name, population: {order: :asc}).reorder(:coordinates)
|
307
317
|
# # => <PlacesIndex::Query {..., :body=>{:sort=>["coordinates"]}}>
|
308
318
|
# @see Chewy::Search::Parameters::Order
|
309
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-
|
319
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html
|
310
320
|
# @param values [Array<Hash, String, Symbol>] sort fields and options
|
311
321
|
# @return [Chewy::Search::Request]
|
312
322
|
def reorder(value, *values)
|
@@ -320,9 +330,22 @@ module Chewy
|
|
320
330
|
# PlacesIndex.track_scores
|
321
331
|
# # => <PlacesIndex::Query {..., :body=>{:track_scores=>true}}>
|
322
332
|
# PlacesIndex.track_scores.track_scores(false)
|
323
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
333
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
324
334
|
# @see Chewy::Search::Parameters::TrackScores
|
325
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
335
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html#_track_scores
|
336
|
+
# @param value [true, false]
|
337
|
+
# @return [Chewy::Search::Request]
|
338
|
+
#
|
339
|
+
# @!method track_total_hits(value = true)
|
340
|
+
# Replaces the value of the `track_total_hits` parameter with the provided value.
|
341
|
+
#
|
342
|
+
# @example
|
343
|
+
# PlacesIndex.track_total_hits
|
344
|
+
# # => <PlacesIndex::Query {..., :body=>{:track_total_hits=>true}}>
|
345
|
+
# PlacesIndex.track_total_hits.track_total_hits(false)
|
346
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
347
|
+
# @see Chewy::Search::Parameters::TrackTotalHits
|
348
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html#track-total-hits
|
326
349
|
# @param value [true, false]
|
327
350
|
# @return [Chewy::Search::Request]
|
328
351
|
#
|
@@ -333,9 +356,9 @@ module Chewy
|
|
333
356
|
# PlacesIndex.explain
|
334
357
|
# # => <PlacesIndex::Query {..., :body=>{:explain=>true}}>
|
335
358
|
# PlacesIndex.explain.explain(false)
|
336
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
359
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
337
360
|
# @see Chewy::Search::Parameters::Explain
|
338
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
361
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html
|
339
362
|
# @param value [true, false]
|
340
363
|
# @return [Chewy::Search::Request]
|
341
364
|
#
|
@@ -346,9 +369,9 @@ module Chewy
|
|
346
369
|
# PlacesIndex.version
|
347
370
|
# # => <PlacesIndex::Query {..., :body=>{:version=>true}}>
|
348
371
|
# PlacesIndex.version.version(false)
|
349
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
372
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
350
373
|
# @see Chewy::Search::Parameters::Version
|
351
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
374
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
|
352
375
|
# @param value [true, false]
|
353
376
|
# @return [Chewy::Search::Request]
|
354
377
|
#
|
@@ -359,9 +382,9 @@ module Chewy
|
|
359
382
|
# PlacesIndex.profile
|
360
383
|
# # => <PlacesIndex::Query {..., :body=>{:profile=>true}}>
|
361
384
|
# PlacesIndex.profile.profile(false)
|
362
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
385
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
363
386
|
# @see Chewy::Search::Parameters::Profile
|
364
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
387
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html
|
365
388
|
# @param value [true, false]
|
366
389
|
# @return [Chewy::Search::Request]
|
367
390
|
#
|
@@ -378,7 +401,7 @@ module Chewy
|
|
378
401
|
# @see https://en.wikipedia.org/wiki/Null_Object_pattern
|
379
402
|
# @param value [true, false]
|
380
403
|
# @return [Chewy::Search::Request]
|
381
|
-
%i[track_scores explain version profile none].each do |name|
|
404
|
+
%i[track_scores track_total_hits explain version profile none].each do |name|
|
382
405
|
define_method name do |value = true|
|
383
406
|
modify(name) { replace!(value) }
|
384
407
|
end
|
@@ -395,7 +418,7 @@ module Chewy
|
|
395
418
|
# PlacesIndex.request_cache(false)
|
396
419
|
# # => <PlacesIndex::Query {..., :body=>{:request_cache=>false}}>
|
397
420
|
# @see Chewy::Search::Parameters::RequestCache
|
398
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
421
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-request-cache.html#_enabling_and_disabling_caching_per_request
|
399
422
|
# @param value [true, false, nil]
|
400
423
|
# @return [Chewy::Search::Request]
|
401
424
|
#
|
@@ -406,7 +429,7 @@ module Chewy
|
|
406
429
|
# PlacesIndex.search_type(:dfs_query_then_fetch)
|
407
430
|
# # => <PlacesIndex::Query {..., :body=>{:search_type=>"dfs_query_then_fetch"}}>
|
408
431
|
# @see Chewy::Search::Parameters::SearchType
|
409
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
432
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-type
|
410
433
|
# @param value [String, Symbol]
|
411
434
|
# @return [Chewy::Search::Request]
|
412
435
|
#
|
@@ -417,7 +440,7 @@ module Chewy
|
|
417
440
|
# PlacesIndex.preference(:_primary_first)
|
418
441
|
# # => <PlacesIndex::Query {..., :body=>{:preference=>"_primary_first"}}>
|
419
442
|
# @see Chewy::Search::Parameters::Preference
|
420
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
443
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-preference
|
421
444
|
# @param value [String, Symbol]
|
422
445
|
# @return [Chewy::Search::Request]
|
423
446
|
#
|
@@ -428,7 +451,7 @@ module Chewy
|
|
428
451
|
# PlacesIndex.timeout('1m')
|
429
452
|
# <PlacesIndex::Query {..., :body=>{:timeout=>"1m"}}>
|
430
453
|
# @see Chewy::Search::Parameters::Timeout
|
431
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
454
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
|
432
455
|
# @param value [String, Symbol]
|
433
456
|
# @return [Chewy::Search::Request]
|
434
457
|
#
|
@@ -439,7 +462,7 @@ module Chewy
|
|
439
462
|
# PlacesIndex.limit(10)
|
440
463
|
# <PlacesIndex::Query {..., :body=>{:size=>10}}>
|
441
464
|
# @see Chewy::Search::Parameters::Limit
|
442
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
465
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
|
443
466
|
# @param value [String, Integer]
|
444
467
|
# @return [Chewy::Search::Request]
|
445
468
|
#
|
@@ -450,7 +473,7 @@ module Chewy
|
|
450
473
|
# PlacesIndex.offset(10)
|
451
474
|
# <PlacesIndex::Query {..., :body=>{:from=>10}}>
|
452
475
|
# @see Chewy::Search::Parameters::Offset
|
453
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
476
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
|
454
477
|
# @param value [String, Integer]
|
455
478
|
# @return [Chewy::Search::Request]
|
456
479
|
#
|
@@ -461,7 +484,7 @@ module Chewy
|
|
461
484
|
# PlacesIndex.terminate_after(10)
|
462
485
|
# <PlacesIndex::Query {..., :body=>{:terminate_after=>10}}>
|
463
486
|
# @see Chewy::Search::Parameters::Offset
|
464
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
487
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html#quickly-check-for-matching-docs
|
465
488
|
# @param value [String, Integer]
|
466
489
|
# @return [Chewy::Search::Request]
|
467
490
|
#
|
@@ -472,10 +495,32 @@ module Chewy
|
|
472
495
|
# PlacesIndex.min_score(2)
|
473
496
|
# <PlacesIndex::Query {..., :body=>{:min_score=>2.0}}>
|
474
497
|
# @see Chewy::Search::Parameters::Offset
|
475
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
498
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-api-min-score
|
476
499
|
# @param value [String, Integer, Float]
|
477
500
|
# @return [Chewy::Search::Request]
|
478
|
-
|
501
|
+
#
|
502
|
+
# @!method ignore_unavailable(value)
|
503
|
+
# Replaces the value of the `ignore_unavailable` request part.
|
504
|
+
#
|
505
|
+
# @example
|
506
|
+
# PlacesIndex.ignore_unavailable(true)
|
507
|
+
# <PlacesIndex::Query {..., :ignore_unavailable => true, :body=>{ ... }}>
|
508
|
+
# @see Chewy::Search::Parameters::IgnoreUnavailable
|
509
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html#multi-index
|
510
|
+
# @param value [true, false, nil]
|
511
|
+
# @return [Chewy::Search::Request]
|
512
|
+
#
|
513
|
+
# @!method collapse(value)
|
514
|
+
# Replaces the value of the `collapse` request part.
|
515
|
+
#
|
516
|
+
# @example
|
517
|
+
# PlacesIndex.collapse(field: :name)
|
518
|
+
# # => <PlacesIndex::Query {..., :body=>{:collapse=>{"field"=>:name}}}>
|
519
|
+
# @see Chewy::Search::Parameters::Collapse
|
520
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
|
521
|
+
# @param value [Hash]
|
522
|
+
# @return [Chewy::Search::Request]
|
523
|
+
%i[request_cache search_type preference timeout limit offset terminate_after min_score ignore_unavailable collapse].each do |name|
|
479
524
|
define_method name do |value|
|
480
525
|
modify(name) { replace!(value) }
|
481
526
|
end
|
@@ -484,7 +529,7 @@ module Chewy
|
|
484
529
|
# @!method source(*values)
|
485
530
|
# Updates `_source` request part. Accepts either an array
|
486
531
|
# of field names/templates or a hash with `includes` and `excludes`
|
487
|
-
# keys. Source also can be disabled
|
532
|
+
# keys. Source also can be disabled entirely or enabled again.
|
488
533
|
#
|
489
534
|
# @example
|
490
535
|
# PlacesIndex.source(:name).source(includes: [:popularity], excludes: :description)
|
@@ -492,13 +537,13 @@ module Chewy
|
|
492
537
|
# PlacesIndex.source(false)
|
493
538
|
# # => <PlacesIndex::Query {..., :body=>{:_source=>false}}>
|
494
539
|
# @see Chewy::Search::Parameters::Source
|
495
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
540
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#source-filtering
|
496
541
|
# @param values [true, false, {Symbol => Array<String, Symbol>, String, Symbol}, Array<String, Symbol>, String, Symbol]
|
497
542
|
# @return [Chewy::Search::Request]
|
498
543
|
#
|
499
544
|
# @!method stored_fields(*values)
|
500
545
|
# Updates `stored_fields` request part. Accepts an array of field
|
501
|
-
# names. Can be
|
546
|
+
# names. Can be entirely disabled and enabled back.
|
502
547
|
#
|
503
548
|
# @example
|
504
549
|
# PlacesIndex.stored_fields(:name).stored_fields(:description)
|
@@ -506,7 +551,7 @@ module Chewy
|
|
506
551
|
# PlacesIndex.stored_fields(false)
|
507
552
|
# # => <PlacesIndex::Query {..., :body=>{:stored_fields=>"_none_"}}>
|
508
553
|
# @see Chewy::Search::Parameters::StoredFields
|
509
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
554
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#stored-fields
|
510
555
|
# @param values [true, false, String, Symbol, Array<String, Symbol>]
|
511
556
|
# @return [Chewy::Search::Request]
|
512
557
|
%i[source stored_fields].each do |name|
|
@@ -522,7 +567,7 @@ module Chewy
|
|
522
567
|
# PlacesIndex.search_after(42, 'Moscow').search_after('London')
|
523
568
|
# # => <PlacesIndex::Query {..., :body=>{:search_after=>["London"]}}>
|
524
569
|
# @see Chewy::Search::Parameters::SearchAfter
|
525
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
570
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
|
526
571
|
# @param value [Array, Object]
|
527
572
|
# @return [Chewy::Search::Request]
|
528
573
|
def search_after(value, *values)
|
@@ -530,9 +575,9 @@ module Chewy
|
|
530
575
|
end
|
531
576
|
|
532
577
|
# Stores ORM/ODM objects loading options. Options
|
533
|
-
# might be define per-
|
578
|
+
# might be define per-index or be global, depends on the adapter
|
534
579
|
# loading implementation. Also, there are 2 loading options to select
|
535
|
-
# or exclude
|
580
|
+
# or exclude indexes from loading: `only` and `except` respectively.
|
536
581
|
# Options are updated on further method calls.
|
537
582
|
#
|
538
583
|
# @example
|
@@ -557,7 +602,7 @@ module Chewy
|
|
557
602
|
# # "field1"=>{:script=>{:lang=>"painless", :inline=>"some script here"}},
|
558
603
|
# # "field2"=>{:script=>{:lang=>"painless", :inline=>"some script here"}}}}}>
|
559
604
|
# @see Chewy::Search::Parameters::ScriptFields
|
560
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
605
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#script-fields
|
561
606
|
# @param value [Hash]
|
562
607
|
# @return [Chewy::Search::Request]
|
563
608
|
#
|
@@ -569,7 +614,7 @@ module Chewy
|
|
569
614
|
# PlacesIndex.indices_boost(index1: 1.2, index2: 1.3).indices_boost(index1: 1.5)
|
570
615
|
# # => <PlacesIndex::Query {..., :body=>{:indices_boost=>[{"index2"=>1.3}, {"index1"=>1.5}]}}>
|
571
616
|
# @see Chewy::Search::Parameters::IndicesBoost
|
572
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
617
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multiple-indices.html#index-boost
|
573
618
|
# @param value [{String, Symbol => String, Integer, Float}]
|
574
619
|
# @return [Chewy::Search::Request]
|
575
620
|
#
|
@@ -581,7 +626,7 @@ module Chewy
|
|
581
626
|
# PlacesIndex.rescore(window_size: 100, query: {}).rescore(window_size: 200, query: {})
|
582
627
|
# # => <PlacesIndex::Query {..., :body=>{:rescore=>[{:window_size=>100, :query=>{}}, {:window_size=>200, :query=>{}}]}}>
|
583
628
|
# @see Chewy::Search::Parameters::Rescore
|
584
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
629
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-search-results.html#rescore
|
585
630
|
# @param value [Hash, Array<Hash>]
|
586
631
|
# @return [Chewy::Search::Request]
|
587
632
|
#
|
@@ -597,7 +642,7 @@ module Chewy
|
|
597
642
|
# # "fields"=>{:description=>{:type=>"plain"}},
|
598
643
|
# # "pre_tags"=>["<em>"], "post_tags"=>["</em>"]}}}>
|
599
644
|
# @see Chewy::Search::Parameters::Highlight
|
600
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
645
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
|
601
646
|
# @param value [Hash]
|
602
647
|
# @return [Chewy::Search::Request]
|
603
648
|
%i[script_fields indices_boost rescore highlight].each do |name|
|
@@ -620,7 +665,7 @@ module Chewy
|
|
620
665
|
# # "names"=>{:text=>"tring out Elasticsearch"},
|
621
666
|
# # "descriptions"=>{:text=>"some other text"}}}}>
|
622
667
|
# @see Chewy::Search::Parameters::Suggest
|
623
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
668
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
|
624
669
|
# @param value [Hash]
|
625
670
|
# @return [Chewy::Search::Request]
|
626
671
|
#
|
@@ -706,7 +751,10 @@ module Chewy
|
|
706
751
|
# scope1.and(scope2)
|
707
752
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
708
753
|
# # :must=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
|
709
|
-
# # :filter=>{
|
754
|
+
# # :filter=>{
|
755
|
+
# # :bool=>{:must=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
|
756
|
+
# # }
|
757
|
+
# # }}}}>
|
710
758
|
# @param other [Chewy::Search::Request] scope to merge
|
711
759
|
# @return [Chewy::Search::Request] new scope
|
712
760
|
#
|
@@ -723,7 +771,10 @@ module Chewy
|
|
723
771
|
# scope1.or(scope2)
|
724
772
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
725
773
|
# # :should=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
|
726
|
-
# # :filter=>{
|
774
|
+
# # :filter=>{
|
775
|
+
# # :bool=>{:should=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
|
776
|
+
# # }
|
777
|
+
# # }}}}>
|
727
778
|
# @param other [Chewy::Search::Request] scope to merge
|
728
779
|
# @return [Chewy::Search::Request] new scope
|
729
780
|
#
|
@@ -740,7 +791,13 @@ module Chewy
|
|
740
791
|
# scope1.not(scope2)
|
741
792
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
742
793
|
# # :must=>{:match=>{:name=>"London"}}, :must_not=>{:match=>{:name=>"Washington"}},
|
743
|
-
# # :filter=>{
|
794
|
+
# # :filter=>{
|
795
|
+
# # :bool=>{
|
796
|
+
# # :must=>{:term=>{:name=>"Moscow"}},
|
797
|
+
# # :must_not=>{:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}
|
798
|
+
# # }
|
799
|
+
# # }
|
800
|
+
# # }}}}>
|
744
801
|
# @param other [Chewy::Search::Request] scope to merge
|
745
802
|
# @return [Chewy::Search::Request] new scope
|
746
803
|
%i[and or not].each do |name|
|
@@ -754,19 +811,19 @@ module Chewy
|
|
754
811
|
# Returns a new scope containing only specified storages.
|
755
812
|
#
|
756
813
|
# @example
|
757
|
-
# PlacesIndex.limit(10).offset(10).order(:name).
|
758
|
-
# # => <PlacesIndex::Query {..., :body=>{:
|
814
|
+
# PlacesIndex.limit(10).offset(10).order(:name).only(:offset, :order)
|
815
|
+
# # => <PlacesIndex::Query {..., :body=>{:from=>10, :sort=>["name"]}}>
|
759
816
|
# @param values [Array<String, Symbol>]
|
760
817
|
# @return [Chewy::Search::Request] new scope
|
761
818
|
def only(*values)
|
762
|
-
chain { parameters.only!(values.flatten(1)) }
|
819
|
+
chain { parameters.only!(values.flatten(1) + [:indices]) }
|
763
820
|
end
|
764
821
|
|
765
822
|
# Returns a new scope containing all the storages except specified.
|
766
823
|
#
|
767
824
|
# @example
|
768
|
-
# PlacesIndex.limit(10).offset(10).order(:name).
|
769
|
-
# # => <PlacesIndex::Query {..., :body=>{:
|
825
|
+
# PlacesIndex.limit(10).offset(10).order(:name).except(:offset, :order)
|
826
|
+
# # => <PlacesIndex::Query {..., :body=>{:size=>10}}>
|
770
827
|
# @param values [Array<String, Symbol>]
|
771
828
|
# @return [Chewy::Search::Request] new scope
|
772
829
|
def except(*values)
|
@@ -812,14 +869,14 @@ module Chewy
|
|
812
869
|
# @overload first
|
813
870
|
# If nothing is passed - it returns a single object.
|
814
871
|
#
|
815
|
-
# @return [Chewy::
|
872
|
+
# @return [Chewy::Index] result document
|
816
873
|
#
|
817
874
|
# @overload first(limit)
|
818
875
|
# If limit is provided - it returns the limit amount or less
|
819
876
|
# of wrapper objects.
|
820
877
|
#
|
821
878
|
# @param limit [Integer] amount of requested results
|
822
|
-
# @return [Array<Chewy::
|
879
|
+
# @return [Array<Chewy::Index>] result document collection
|
823
880
|
def first(limit = UNDEFINED)
|
824
881
|
request_limit = limit == UNDEFINED ? 1 : limit
|
825
882
|
|
@@ -838,7 +895,7 @@ module Chewy
|
|
838
895
|
# If single id is passed - it returns a single object.
|
839
896
|
#
|
840
897
|
# @param id [Integer, String] id of the desired document
|
841
|
-
# @return [Chewy::
|
898
|
+
# @return [Chewy::Index] result document
|
842
899
|
#
|
843
900
|
# @overload find(*ids)
|
844
901
|
# If several field are passed - it returns an array of wrappers.
|
@@ -846,7 +903,7 @@ module Chewy
|
|
846
903
|
# batch size - uses scroll API to retrieve everything.
|
847
904
|
#
|
848
905
|
# @param ids [Array<Integer, String>] ids of the desired documents
|
849
|
-
# @return [Array<Chewy::
|
906
|
+
# @return [Array<Chewy::Index>] result documents
|
850
907
|
def find(*ids)
|
851
908
|
return super if block_given?
|
852
909
|
|
@@ -868,7 +925,7 @@ module Chewy
|
|
868
925
|
|
869
926
|
# Returns and array of values for specified fields.
|
870
927
|
# Uses `source` to restrict the list of returned fields.
|
871
|
-
# Fields `_id`, `_type` and `_index` are also supported.
|
928
|
+
# Fields `_id`, `_type`, `_routing` and `_index` are also supported.
|
872
929
|
#
|
873
930
|
# @overload pluck(field)
|
874
931
|
# If single field is passed - it returns and array of values.
|
@@ -901,26 +958,37 @@ module Chewy
|
|
901
958
|
end
|
902
959
|
|
903
960
|
# Deletes all the documents from the specified scope it uses
|
904
|
-
# `delete_by_query`
|
905
|
-
# plugin, which requires additional installation effort.
|
961
|
+
# `delete_by_query`
|
906
962
|
#
|
907
963
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
|
908
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/plugins/2.0/plugins-delete-by-query.html
|
909
964
|
# @note The result hash is different for different API used.
|
910
|
-
# @param refresh [true, false]
|
965
|
+
# @param refresh [true, false] Refreshes all shards involved in the delete by query
|
966
|
+
# @param wait_for_completion [true, false] wait for request completion or run it asynchronously
|
967
|
+
# and return task reference at `.tasks/task/${taskId}`.
|
968
|
+
# @param requests_per_second [Float] The throttle for this request in sub-requests per second
|
969
|
+
# @param scroll_size [Integer] Size of the scroll request that powers the operation
|
970
|
+
|
911
971
|
# @return [Hash] the result of query execution
|
912
|
-
def delete_all(refresh: true)
|
913
|
-
request_body = only(WHERE_STORAGES).render.merge(
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
972
|
+
def delete_all(refresh: true, wait_for_completion: nil, requests_per_second: nil, scroll_size: nil)
|
973
|
+
request_body = only(WHERE_STORAGES).render.merge(
|
974
|
+
{
|
975
|
+
refresh: refresh,
|
976
|
+
wait_for_completion: wait_for_completion,
|
977
|
+
requests_per_second: requests_per_second,
|
978
|
+
scroll_size: scroll_size
|
979
|
+
}.compact
|
980
|
+
)
|
981
|
+
ActiveSupport::Notifications.instrument 'delete_query.chewy', notification_payload(request: request_body) do
|
982
|
+
request_body[:body] = {query: {match_all: {}}} if request_body[:body].empty?
|
983
|
+
Chewy.client.delete_by_query(request_body)
|
984
|
+
end
|
985
|
+
end
|
986
|
+
|
987
|
+
# Returns whether or not the query has been performed.
|
988
|
+
#
|
989
|
+
# @return [true, false]
|
990
|
+
def performed?
|
991
|
+
!@response.nil?
|
924
992
|
end
|
925
993
|
|
926
994
|
protected
|
@@ -932,10 +1000,12 @@ module Chewy
|
|
932
1000
|
|
933
1001
|
private
|
934
1002
|
|
1003
|
+
def build_response(raw_response)
|
1004
|
+
Response.new(raw_response, loader, collection_paginator)
|
1005
|
+
end
|
1006
|
+
|
935
1007
|
def compare_internals(other)
|
936
|
-
|
937
|
-
_types.sort_by(&:derivable_name) == other._types.sort_by(&:derivable_name) &&
|
938
|
-
parameters == other.parameters
|
1008
|
+
parameters == other.parameters
|
939
1009
|
end
|
940
1010
|
|
941
1011
|
def modify(name, &block)
|
@@ -947,58 +1017,42 @@ module Chewy
|
|
947
1017
|
end
|
948
1018
|
|
949
1019
|
def reset
|
950
|
-
@response, @render, @
|
1020
|
+
@response, @render, @loader = nil
|
951
1021
|
end
|
952
1022
|
|
953
1023
|
def perform(additional = {})
|
954
1024
|
request_body = render.merge(additional)
|
955
|
-
ActiveSupport::Notifications.instrument 'search_query.chewy',
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
begin
|
960
|
-
Chewy.client.search(request_body)
|
961
|
-
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
962
|
-
{}
|
963
|
-
end
|
1025
|
+
ActiveSupport::Notifications.instrument 'search_query.chewy', notification_payload(request: request_body) do
|
1026
|
+
Chewy.client.search(request_body)
|
1027
|
+
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
1028
|
+
{}
|
964
1029
|
end
|
965
1030
|
end
|
966
1031
|
|
967
|
-
def
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
parameters[:offset].value
|
1032
|
+
def notification_payload(additional)
|
1033
|
+
{
|
1034
|
+
indexes: _indices,
|
1035
|
+
index: _indices.one? ? _indices.first : _indices
|
1036
|
+
}.merge(additional)
|
973
1037
|
end
|
974
1038
|
|
975
|
-
def
|
976
|
-
|
1039
|
+
def _indices
|
1040
|
+
parameters[:indices].indices
|
977
1041
|
end
|
978
1042
|
|
979
|
-
def
|
980
|
-
|
981
|
-
_types.map(&:type_name).uniq & parameters[:types].value
|
982
|
-
else
|
983
|
-
_types.map(&:type_name).uniq
|
984
|
-
end
|
985
|
-
end
|
986
|
-
|
987
|
-
def render_base
|
988
|
-
@render_base ||= {index: index_names, type: type_names, body: {}}
|
1043
|
+
def raw_limit_value
|
1044
|
+
parameters[:limit].value
|
989
1045
|
end
|
990
1046
|
|
991
|
-
def
|
992
|
-
|
993
|
-
Elasticsearch::API::Utils.__listify(request[:index]),
|
994
|
-
Elasticsearch::API::Utils.__listify(request[:type]),
|
995
|
-
'_query'
|
996
|
-
)
|
997
|
-
Chewy.client.perform_request(Elasticsearch::API::HTTP_DELETE, path, {}, request[:body]).body
|
1047
|
+
def raw_offset_value
|
1048
|
+
parameters[:offset].value
|
998
1049
|
end
|
999
1050
|
|
1000
1051
|
def loader
|
1001
|
-
@loader ||= Loader.new(
|
1052
|
+
@loader ||= Loader.new(
|
1053
|
+
indexes: parameters[:indices].indices,
|
1054
|
+
**parameters[:load].value
|
1055
|
+
)
|
1002
1056
|
end
|
1003
1057
|
|
1004
1058
|
def fetch_field(hit, field)
|
@@ -1009,10 +1063,6 @@ module Chewy
|
|
1009
1063
|
end
|
1010
1064
|
end
|
1011
1065
|
|
1012
|
-
def performed?
|
1013
|
-
!@response.nil?
|
1014
|
-
end
|
1015
|
-
|
1016
1066
|
def collection_paginator
|
1017
1067
|
method(:paginated_collection).to_proc if respond_to?(:paginated_collection, true)
|
1018
1068
|
end
|