chewy 5.1.0 → 7.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +73 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +449 -347
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +3 -7
- data/Guardfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +423 -311
- data/chewy.gemspec +8 -10
- data/gemfiles/rails.5.2.activerecord.gemfile +9 -14
- 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 +42 -60
- data/lib/chewy/errors.rb +4 -10
- data/lib/chewy/fields/base.rb +80 -20
- data/lib/chewy/fields/root.rb +7 -17
- data/lib/chewy/index/actions.rb +62 -35
- data/lib/chewy/{type → index}/adapter/active_record.rb +18 -4
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- 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/{type → index}/crutch.rb +5 -5
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -7
- data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
- data/lib/chewy/{type → index}/import/routine.rb +17 -16
- data/lib/chewy/{type → index}/import.rb +51 -33
- data/lib/chewy/{type → index}/mapping.rb +32 -37
- 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/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +61 -62
- data/lib/chewy/{type → index}/witchcraft.rb +15 -9
- data/lib/chewy/{type → index}/wrapper.rb +13 -3
- data/lib/chewy/index.rb +46 -96
- data/lib/chewy/journal.rb +25 -14
- data/lib/chewy/minitest/helpers.rb +86 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +6 -20
- data/lib/chewy/rake_helper.rb +136 -108
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +55 -44
- 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/collapse.rb +16 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/indices.rb +12 -57
- 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 +7 -4
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +180 -154
- data/lib/chewy/search/response.rb +5 -5
- data/lib/chewy/search/scoping.rb +7 -8
- data/lib/chewy/search/scrolling.rb +16 -13
- data/lib/chewy/search.rb +7 -22
- data/lib/chewy/stash.rb +19 -30
- data/lib/chewy/strategy/active_job.rb +2 -2
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +10 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +3 -2
- data/lib/chewy/strategy.rb +5 -19
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +36 -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 +15 -61
- data/spec/chewy/fields/base_spec.rb +432 -145
- data/spec/chewy/fields/root_spec.rb +20 -28
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +388 -55
- 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 +14 -22
- data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
- data/spec/chewy/{type → index}/import_spec.rb +149 -96
- 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 +20 -30
- 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 +69 -137
- data/spec/chewy/journal_spec.rb +46 -91
- 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 +293 -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 +26 -118
- 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 +23 -7
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +344 -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 +69 -59
- 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/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 +6 -29
- data/spec/support/active_record.rb +43 -5
- metadata +102 -198
- data/.travis.yml +0 -45
- data/Appraisals +0 -81
- data/LEGACY_DSL.md +0 -497
- data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.mongoid.6.1.gemfile +0 -16
- data/gemfiles/rails.5.1.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
- 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 -244
- data/lib/chewy/query/loading.rb +0 -110
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -34
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -110
- data/lib/chewy/query/nodes/has_child.rb +0 -15
- data/lib/chewy/query/nodes/has_parent.rb +0 -15
- data/lib/chewy/query/nodes/has_relation.rb +0 -59
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -19
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -35
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination.rb +0 -25
- data/lib/chewy/query.rb +0 -1142
- 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 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/chewy/type/import/bulk_builder.rb +0 -122
- data/lib/chewy/type/observe.rb +0 -82
- data/lib/chewy/type.rb +0 -117
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/query/criteria_spec.rb +0 -700
- data/spec/chewy/query/filters_spec.rb +0 -201
- data/spec/chewy/query/loading_spec.rb +0 -124
- data/spec/chewy/query/nodes/and_spec.rb +0 -12
- data/spec/chewy/query/nodes/bool_spec.rb +0 -14
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -16
- data/spec/chewy/query/nodes/not_spec.rb +0 -14
- data/spec/chewy/query/nodes/or_spec.rb +0 -12
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
- data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
- data/spec/chewy/query/pagination_spec.rb +0 -39
- data/spec/chewy/query_spec.rb +0 -637
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- 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 -66
- 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 -173
- 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,34 +1,34 @@
|
|
1
1
|
module Chewy
|
2
2
|
module Search
|
3
3
|
# The main request DSL class. Supports multiple index requests.
|
4
|
-
# Supports
|
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
29
|
total_entries indices types delete_all count exists?
|
30
30
|
exist? find pluck scroll_batches scroll_hits
|
31
|
-
scroll_results scroll_wrappers
|
31
|
+
scroll_results scroll_wrappers ignore_unavailable
|
32
32
|
].to_set.freeze
|
33
33
|
DEFAULT_BATCH_SIZE = 1000
|
34
34
|
DEFAULT_PLUCK_BATCH_SIZE = 10_000
|
@@ -41,42 +41,32 @@ module Chewy
|
|
41
41
|
EXTRA_STORAGES = %i[aggs suggest].freeze
|
42
42
|
# An array of storage names that are changing the returned hist collection in any way.
|
43
43
|
WHERE_STORAGES = %i[
|
44
|
-
query filter post_filter none
|
44
|
+
query filter post_filter none min_score rescore indices_boost collapse
|
45
45
|
].freeze
|
46
46
|
|
47
47
|
delegate :hits, :wrappers, :objects, :records, :documents,
|
48
|
-
|
49
|
-
|
48
|
+
:object_hash, :record_hash, :document_hash,
|
49
|
+
:total, :max_score, :took, :timed_out?, to: :response
|
50
50
|
delegate :each, :size, :to_a, :[], to: :wrappers
|
51
51
|
alias_method :to_ary, :to_a
|
52
52
|
alias_method :total_count, :total
|
53
53
|
alias_method :total_entries, :total
|
54
54
|
|
55
|
-
# The class is initialized with the list of chewy indexes
|
56
|
-
#
|
55
|
+
# The class is initialized with the list of chewy indexes,
|
56
|
+
# which are later used to compose requests.
|
57
57
|
# Any symbol/string passed is treated as an index identifier.
|
58
58
|
#
|
59
59
|
# @example
|
60
60
|
# Chewy::Search::Request.new(:places)
|
61
|
-
# # => <Chewy::Search::Request {:index=>["places"]}>
|
61
|
+
# # => <Chewy::Search::Request {:index=>["places"], :body=>{}}>
|
62
62
|
# Chewy::Search::Request.new(PlacesIndex)
|
63
|
-
# # => <Chewy::Search::Request {:index=>["places"], :
|
64
|
-
# Chewy::Search::Request.new(PlacesIndex
|
65
|
-
# # => <Chewy::Search::Request {:index=>["places"], :
|
66
|
-
#
|
67
|
-
|
68
|
-
# @param indexes_or_types [Array<Chewy::Index, Chewy::Type, String, Symbol>] indices and types in any combinations
|
69
|
-
def initialize(*indices_or_types)
|
70
|
-
indices = indices_or_types.reject do |klass|
|
71
|
-
klass.is_a?(Class) && klass < Chewy::Type
|
72
|
-
end
|
73
|
-
|
74
|
-
types = indices_or_types.select do |klass|
|
75
|
-
klass.is_a?(Class) && klass < Chewy::Type
|
76
|
-
end
|
77
|
-
|
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)
|
78
68
|
parameters.modify!(:indices) do
|
79
|
-
replace!(indices:
|
69
|
+
replace!(indices: indexes)
|
80
70
|
end
|
81
71
|
end
|
82
72
|
|
@@ -112,7 +102,16 @@ module Chewy
|
|
112
102
|
# @see Chewy::Search::Response
|
113
103
|
# @return [Chewy::Search::Response] a response object instance
|
114
104
|
def response
|
115
|
-
@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)
|
116
115
|
end
|
117
116
|
|
118
117
|
# ES request body
|
@@ -129,17 +128,17 @@ module Chewy
|
|
129
128
|
"<#{self.class} #{render}>"
|
130
129
|
end
|
131
130
|
|
132
|
-
# @!group Chainable request
|
131
|
+
# @!group Chainable request modifications
|
133
132
|
|
134
133
|
# @!method query(query_hash=nil, &block)
|
135
|
-
# Adds `
|
134
|
+
# Adds `query` parameter to the search request body.
|
136
135
|
#
|
137
136
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-query.html
|
138
137
|
# @see Chewy::Search::Parameters::Query
|
139
138
|
# @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
|
140
139
|
#
|
141
140
|
# @overload query(query_hash)
|
142
|
-
# If pure hash is passed it goes straight to the `
|
141
|
+
# If pure hash is passed it goes straight to the `query` parameter storage.
|
143
142
|
# Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
|
144
143
|
#
|
145
144
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
|
@@ -158,7 +157,7 @@ module Chewy
|
|
158
157
|
# @example
|
159
158
|
# PlacesIndex.query { match name: 'Moscow' }
|
160
159
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:match=>{:name=>"Moscow"}}}}>
|
161
|
-
# @yield the block is processed by `elasticsearch-
|
160
|
+
# @yield the block is processed by `elasticsearch-dsl` gem
|
162
161
|
# @return [Chewy::Search::Request]
|
163
162
|
#
|
164
163
|
# @overload query
|
@@ -174,7 +173,7 @@ module Chewy
|
|
174
173
|
# @return [Chewy::Search::QueryProxy]
|
175
174
|
#
|
176
175
|
# @!method filter(query_hash=nil, &block)
|
177
|
-
# Adds `
|
176
|
+
# Adds `filter` context of the `query` parameter at the
|
178
177
|
# search request body.
|
179
178
|
#
|
180
179
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html
|
@@ -182,7 +181,7 @@ module Chewy
|
|
182
181
|
# @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
|
183
182
|
#
|
184
183
|
# @overload filter(query_hash)
|
185
|
-
# 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.
|
186
185
|
# Acts exactly the same way as {Chewy::Search::QueryProxy#must}.
|
187
186
|
#
|
188
187
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
|
@@ -203,7 +202,7 @@ module Chewy
|
|
203
202
|
# PlacesIndex.filter { match name: 'Moscow' }
|
204
203
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
205
204
|
# # :filter=>{:match=>{:name=>"Moscow"}}}}}}>
|
206
|
-
# @yield the block is processed by `elasticsearch-
|
205
|
+
# @yield the block is processed by `elasticsearch-dsl` gem
|
207
206
|
# @return [Chewy::Search::Request]
|
208
207
|
#
|
209
208
|
# @overload filter
|
@@ -221,7 +220,7 @@ module Chewy
|
|
221
220
|
# @!method post_filter(query_hash=nil, &block)
|
222
221
|
# Adds `post_filter` parameter to the search request body.
|
223
222
|
#
|
224
|
-
# @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
|
225
224
|
# @see Chewy::Search::Parameters::PostFilter
|
226
225
|
# @return [Chewy::Search::Request, Chewy::Search::QueryProxy]
|
227
226
|
#
|
@@ -245,7 +244,7 @@ module Chewy
|
|
245
244
|
# @example
|
246
245
|
# PlacesIndex.post_filter { match name: 'Moscow' }
|
247
246
|
# # => <PlacesIndex::Query {..., :body=>{:post_filter=>{:match=>{:name=>"Moscow"}}}}>
|
248
|
-
# @yield the block is processed by `elasticsearch-
|
247
|
+
# @yield the block is processed by `elasticsearch-dsl` gem
|
249
248
|
# @return [Chewy::Search::Request]
|
250
249
|
#
|
251
250
|
# @overload post_filter
|
@@ -276,7 +275,7 @@ module Chewy
|
|
276
275
|
# PlacesIndex.order(:name, population: {order: :asc}).order(:coordinates)
|
277
276
|
# # => <PlacesIndex::Query {..., :body=>{:sort=>["name", {"population"=>{:order=>:asc}}, "coordinates"]}}>
|
278
277
|
# @see Chewy::Search::Parameters::Order
|
279
|
-
# @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
|
280
279
|
# @param values [Array<Hash, String, Symbol>] sort fields and options
|
281
280
|
# @return [Chewy::Search::Request]
|
282
281
|
#
|
@@ -287,7 +286,7 @@ module Chewy
|
|
287
286
|
# PlacesIndex.docvalue_fields(:name).docvalue_fields(:population, :coordinates)
|
288
287
|
# # => <PlacesIndex::Query {..., :body=>{:docvalue_fields=>["name", "population", "coordinates"]}}>
|
289
288
|
# @see Chewy::Search::Parameters::DocvalueFields
|
290
|
-
# @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
|
291
290
|
# @param values [Array<String, Symbol>] field names
|
292
291
|
# @return [Chewy::Search::Request]
|
293
292
|
%i[order docvalue_fields].each do |name|
|
@@ -296,34 +295,18 @@ module Chewy
|
|
296
295
|
end
|
297
296
|
end
|
298
297
|
|
299
|
-
#
|
300
|
-
#
|
301
|
-
# Added passed indexes to the parameter list.
|
298
|
+
# Modifies `index` request parameter. Updates the storage on every call.
|
299
|
+
# Added passed indexes to the parameter list.
|
302
300
|
#
|
303
|
-
#
|
304
|
-
#
|
305
|
-
#
|
306
|
-
#
|
307
|
-
#
|
308
|
-
#
|
309
|
-
#
|
310
|
-
|
311
|
-
|
312
|
-
# Modifies `type` request parameter. Updates the storage on every call.
|
313
|
-
# Constrains types passed on the request initialization or adds them
|
314
|
-
# to the list depending on circumstances.
|
315
|
-
#
|
316
|
-
# @example
|
317
|
-
# UsersIndex.types(CitiesIndex::City).types(:unexistent)
|
318
|
-
# # => <UsersIndex::Query {:index=>["cities", "users"], :type=>["city", "user"]}>
|
319
|
-
# @see Chewy::Search::Parameters::Indices
|
320
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
|
321
|
-
# @param values [Array<Chewy::Type, String, Symbol>] type names
|
322
|
-
# @return [Chewy::Search::Request]
|
323
|
-
%i[indices types].each do |name|
|
324
|
-
define_method name do |value, *values|
|
325
|
-
modify(:indices) { update!(name => [value, *values]) }
|
326
|
-
end
|
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]) }
|
327
310
|
end
|
328
311
|
|
329
312
|
# @overload reorder(*values)
|
@@ -333,7 +316,7 @@ module Chewy
|
|
333
316
|
# PlacesIndex.order(:name, population: {order: :asc}).reorder(:coordinates)
|
334
317
|
# # => <PlacesIndex::Query {..., :body=>{:sort=>["coordinates"]}}>
|
335
318
|
# @see Chewy::Search::Parameters::Order
|
336
|
-
# @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
|
337
320
|
# @param values [Array<Hash, String, Symbol>] sort fields and options
|
338
321
|
# @return [Chewy::Search::Request]
|
339
322
|
def reorder(value, *values)
|
@@ -347,9 +330,22 @@ module Chewy
|
|
347
330
|
# PlacesIndex.track_scores
|
348
331
|
# # => <PlacesIndex::Query {..., :body=>{:track_scores=>true}}>
|
349
332
|
# PlacesIndex.track_scores.track_scores(false)
|
350
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
333
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
351
334
|
# @see Chewy::Search::Parameters::TrackScores
|
352
|
-
# @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
|
353
349
|
# @param value [true, false]
|
354
350
|
# @return [Chewy::Search::Request]
|
355
351
|
#
|
@@ -360,9 +356,9 @@ module Chewy
|
|
360
356
|
# PlacesIndex.explain
|
361
357
|
# # => <PlacesIndex::Query {..., :body=>{:explain=>true}}>
|
362
358
|
# PlacesIndex.explain.explain(false)
|
363
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
359
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
364
360
|
# @see Chewy::Search::Parameters::Explain
|
365
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
361
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html
|
366
362
|
# @param value [true, false]
|
367
363
|
# @return [Chewy::Search::Request]
|
368
364
|
#
|
@@ -373,9 +369,9 @@ module Chewy
|
|
373
369
|
# PlacesIndex.version
|
374
370
|
# # => <PlacesIndex::Query {..., :body=>{:version=>true}}>
|
375
371
|
# PlacesIndex.version.version(false)
|
376
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
372
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
377
373
|
# @see Chewy::Search::Parameters::Version
|
378
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
374
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
|
379
375
|
# @param value [true, false]
|
380
376
|
# @return [Chewy::Search::Request]
|
381
377
|
#
|
@@ -386,9 +382,9 @@ module Chewy
|
|
386
382
|
# PlacesIndex.profile
|
387
383
|
# # => <PlacesIndex::Query {..., :body=>{:profile=>true}}>
|
388
384
|
# PlacesIndex.profile.profile(false)
|
389
|
-
# # => <PlacesIndex::Query {:index=>["places"]
|
385
|
+
# # => <PlacesIndex::Query {:index=>["places"]}>
|
390
386
|
# @see Chewy::Search::Parameters::Profile
|
391
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
387
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html
|
392
388
|
# @param value [true, false]
|
393
389
|
# @return [Chewy::Search::Request]
|
394
390
|
#
|
@@ -405,7 +401,7 @@ module Chewy
|
|
405
401
|
# @see https://en.wikipedia.org/wiki/Null_Object_pattern
|
406
402
|
# @param value [true, false]
|
407
403
|
# @return [Chewy::Search::Request]
|
408
|
-
%i[track_scores explain version profile none].each do |name|
|
404
|
+
%i[track_scores track_total_hits explain version profile none].each do |name|
|
409
405
|
define_method name do |value = true|
|
410
406
|
modify(name) { replace!(value) }
|
411
407
|
end
|
@@ -422,7 +418,7 @@ module Chewy
|
|
422
418
|
# PlacesIndex.request_cache(false)
|
423
419
|
# # => <PlacesIndex::Query {..., :body=>{:request_cache=>false}}>
|
424
420
|
# @see Chewy::Search::Parameters::RequestCache
|
425
|
-
# @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
|
426
422
|
# @param value [true, false, nil]
|
427
423
|
# @return [Chewy::Search::Request]
|
428
424
|
#
|
@@ -433,7 +429,7 @@ module Chewy
|
|
433
429
|
# PlacesIndex.search_type(:dfs_query_then_fetch)
|
434
430
|
# # => <PlacesIndex::Query {..., :body=>{:search_type=>"dfs_query_then_fetch"}}>
|
435
431
|
# @see Chewy::Search::Parameters::SearchType
|
436
|
-
# @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
|
437
433
|
# @param value [String, Symbol]
|
438
434
|
# @return [Chewy::Search::Request]
|
439
435
|
#
|
@@ -444,7 +440,7 @@ module Chewy
|
|
444
440
|
# PlacesIndex.preference(:_primary_first)
|
445
441
|
# # => <PlacesIndex::Query {..., :body=>{:preference=>"_primary_first"}}>
|
446
442
|
# @see Chewy::Search::Parameters::Preference
|
447
|
-
# @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
|
448
444
|
# @param value [String, Symbol]
|
449
445
|
# @return [Chewy::Search::Request]
|
450
446
|
#
|
@@ -455,7 +451,7 @@ module Chewy
|
|
455
451
|
# PlacesIndex.timeout('1m')
|
456
452
|
# <PlacesIndex::Query {..., :body=>{:timeout=>"1m"}}>
|
457
453
|
# @see Chewy::Search::Parameters::Timeout
|
458
|
-
# @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
|
459
455
|
# @param value [String, Symbol]
|
460
456
|
# @return [Chewy::Search::Request]
|
461
457
|
#
|
@@ -466,7 +462,7 @@ module Chewy
|
|
466
462
|
# PlacesIndex.limit(10)
|
467
463
|
# <PlacesIndex::Query {..., :body=>{:size=>10}}>
|
468
464
|
# @see Chewy::Search::Parameters::Limit
|
469
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
465
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
|
470
466
|
# @param value [String, Integer]
|
471
467
|
# @return [Chewy::Search::Request]
|
472
468
|
#
|
@@ -477,7 +473,7 @@ module Chewy
|
|
477
473
|
# PlacesIndex.offset(10)
|
478
474
|
# <PlacesIndex::Query {..., :body=>{:from=>10}}>
|
479
475
|
# @see Chewy::Search::Parameters::Offset
|
480
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
476
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html
|
481
477
|
# @param value [String, Integer]
|
482
478
|
# @return [Chewy::Search::Request]
|
483
479
|
#
|
@@ -488,7 +484,7 @@ module Chewy
|
|
488
484
|
# PlacesIndex.terminate_after(10)
|
489
485
|
# <PlacesIndex::Query {..., :body=>{:terminate_after=>10}}>
|
490
486
|
# @see Chewy::Search::Parameters::Offset
|
491
|
-
# @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
|
492
488
|
# @param value [String, Integer]
|
493
489
|
# @return [Chewy::Search::Request]
|
494
490
|
#
|
@@ -499,10 +495,32 @@ module Chewy
|
|
499
495
|
# PlacesIndex.min_score(2)
|
500
496
|
# <PlacesIndex::Query {..., :body=>{:min_score=>2.0}}>
|
501
497
|
# @see Chewy::Search::Parameters::Offset
|
502
|
-
# @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
|
503
499
|
# @param value [String, Integer, Float]
|
504
500
|
# @return [Chewy::Search::Request]
|
505
|
-
|
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|
|
506
524
|
define_method name do |value|
|
507
525
|
modify(name) { replace!(value) }
|
508
526
|
end
|
@@ -511,7 +529,7 @@ module Chewy
|
|
511
529
|
# @!method source(*values)
|
512
530
|
# Updates `_source` request part. Accepts either an array
|
513
531
|
# of field names/templates or a hash with `includes` and `excludes`
|
514
|
-
# keys. Source also can be disabled
|
532
|
+
# keys. Source also can be disabled entirely or enabled again.
|
515
533
|
#
|
516
534
|
# @example
|
517
535
|
# PlacesIndex.source(:name).source(includes: [:popularity], excludes: :description)
|
@@ -519,13 +537,13 @@ module Chewy
|
|
519
537
|
# PlacesIndex.source(false)
|
520
538
|
# # => <PlacesIndex::Query {..., :body=>{:_source=>false}}>
|
521
539
|
# @see Chewy::Search::Parameters::Source
|
522
|
-
# @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
|
523
541
|
# @param values [true, false, {Symbol => Array<String, Symbol>, String, Symbol}, Array<String, Symbol>, String, Symbol]
|
524
542
|
# @return [Chewy::Search::Request]
|
525
543
|
#
|
526
544
|
# @!method stored_fields(*values)
|
527
545
|
# Updates `stored_fields` request part. Accepts an array of field
|
528
|
-
# names. Can be
|
546
|
+
# names. Can be entirely disabled and enabled back.
|
529
547
|
#
|
530
548
|
# @example
|
531
549
|
# PlacesIndex.stored_fields(:name).stored_fields(:description)
|
@@ -533,7 +551,7 @@ module Chewy
|
|
533
551
|
# PlacesIndex.stored_fields(false)
|
534
552
|
# # => <PlacesIndex::Query {..., :body=>{:stored_fields=>"_none_"}}>
|
535
553
|
# @see Chewy::Search::Parameters::StoredFields
|
536
|
-
# @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
|
537
555
|
# @param values [true, false, String, Symbol, Array<String, Symbol>]
|
538
556
|
# @return [Chewy::Search::Request]
|
539
557
|
%i[source stored_fields].each do |name|
|
@@ -549,7 +567,7 @@ module Chewy
|
|
549
567
|
# PlacesIndex.search_after(42, 'Moscow').search_after('London')
|
550
568
|
# # => <PlacesIndex::Query {..., :body=>{:search_after=>["London"]}}>
|
551
569
|
# @see Chewy::Search::Parameters::SearchAfter
|
552
|
-
# @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
|
553
571
|
# @param value [Array, Object]
|
554
572
|
# @return [Chewy::Search::Request]
|
555
573
|
def search_after(value, *values)
|
@@ -557,9 +575,9 @@ module Chewy
|
|
557
575
|
end
|
558
576
|
|
559
577
|
# Stores ORM/ODM objects loading options. Options
|
560
|
-
# might be define per-
|
578
|
+
# might be define per-index or be global, depends on the adapter
|
561
579
|
# loading implementation. Also, there are 2 loading options to select
|
562
|
-
# or exclude
|
580
|
+
# or exclude indexes from loading: `only` and `except` respectively.
|
563
581
|
# Options are updated on further method calls.
|
564
582
|
#
|
565
583
|
# @example
|
@@ -584,7 +602,7 @@ module Chewy
|
|
584
602
|
# # "field1"=>{:script=>{:lang=>"painless", :inline=>"some script here"}},
|
585
603
|
# # "field2"=>{:script=>{:lang=>"painless", :inline=>"some script here"}}}}}>
|
586
604
|
# @see Chewy::Search::Parameters::ScriptFields
|
587
|
-
# @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
|
588
606
|
# @param value [Hash]
|
589
607
|
# @return [Chewy::Search::Request]
|
590
608
|
#
|
@@ -596,7 +614,7 @@ module Chewy
|
|
596
614
|
# PlacesIndex.indices_boost(index1: 1.2, index2: 1.3).indices_boost(index1: 1.5)
|
597
615
|
# # => <PlacesIndex::Query {..., :body=>{:indices_boost=>[{"index2"=>1.3}, {"index1"=>1.5}]}}>
|
598
616
|
# @see Chewy::Search::Parameters::IndicesBoost
|
599
|
-
# @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
|
600
618
|
# @param value [{String, Symbol => String, Integer, Float}]
|
601
619
|
# @return [Chewy::Search::Request]
|
602
620
|
#
|
@@ -608,7 +626,7 @@ module Chewy
|
|
608
626
|
# PlacesIndex.rescore(window_size: 100, query: {}).rescore(window_size: 200, query: {})
|
609
627
|
# # => <PlacesIndex::Query {..., :body=>{:rescore=>[{:window_size=>100, :query=>{}}, {:window_size=>200, :query=>{}}]}}>
|
610
628
|
# @see Chewy::Search::Parameters::Rescore
|
611
|
-
# @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
|
612
630
|
# @param value [Hash, Array<Hash>]
|
613
631
|
# @return [Chewy::Search::Request]
|
614
632
|
#
|
@@ -624,7 +642,7 @@ module Chewy
|
|
624
642
|
# # "fields"=>{:description=>{:type=>"plain"}},
|
625
643
|
# # "pre_tags"=>["<em>"], "post_tags"=>["</em>"]}}}>
|
626
644
|
# @see Chewy::Search::Parameters::Highlight
|
627
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
645
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
|
628
646
|
# @param value [Hash]
|
629
647
|
# @return [Chewy::Search::Request]
|
630
648
|
%i[script_fields indices_boost rescore highlight].each do |name|
|
@@ -647,7 +665,7 @@ module Chewy
|
|
647
665
|
# # "names"=>{:text=>"tring out Elasticsearch"},
|
648
666
|
# # "descriptions"=>{:text=>"some other text"}}}}>
|
649
667
|
# @see Chewy::Search::Parameters::Suggest
|
650
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/
|
668
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
|
651
669
|
# @param value [Hash]
|
652
670
|
# @return [Chewy::Search::Request]
|
653
671
|
#
|
@@ -733,7 +751,10 @@ module Chewy
|
|
733
751
|
# scope1.and(scope2)
|
734
752
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
735
753
|
# # :must=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
|
736
|
-
# # :filter=>{
|
754
|
+
# # :filter=>{
|
755
|
+
# # :bool=>{:must=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
|
756
|
+
# # }
|
757
|
+
# # }}}}>
|
737
758
|
# @param other [Chewy::Search::Request] scope to merge
|
738
759
|
# @return [Chewy::Search::Request] new scope
|
739
760
|
#
|
@@ -750,7 +771,10 @@ module Chewy
|
|
750
771
|
# scope1.or(scope2)
|
751
772
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
752
773
|
# # :should=>[{:match=>{:name=>"London"}}, {:match=>{:name=>"Washington"}}],
|
753
|
-
# # :filter=>{
|
774
|
+
# # :filter=>{
|
775
|
+
# # :bool=>{:should=>[{:term=>{:name=>"Moscow"}}, {:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}]}
|
776
|
+
# # }
|
777
|
+
# # }}}}>
|
754
778
|
# @param other [Chewy::Search::Request] scope to merge
|
755
779
|
# @return [Chewy::Search::Request] new scope
|
756
780
|
#
|
@@ -767,7 +791,13 @@ module Chewy
|
|
767
791
|
# scope1.not(scope2)
|
768
792
|
# # => <PlacesIndex::Query {..., :body=>{:query=>{:bool=>{
|
769
793
|
# # :must=>{:match=>{:name=>"London"}}, :must_not=>{:match=>{:name=>"Washington"}},
|
770
|
-
# # :filter=>{
|
794
|
+
# # :filter=>{
|
795
|
+
# # :bool=>{
|
796
|
+
# # :must=>{:term=>{:name=>"Moscow"}},
|
797
|
+
# # :must_not=>{:bool=>{:must_not=>{:term=>{:name=>"Berlin"}}}}
|
798
|
+
# # }
|
799
|
+
# # }
|
800
|
+
# # }}}}>
|
771
801
|
# @param other [Chewy::Search::Request] scope to merge
|
772
802
|
# @return [Chewy::Search::Request] new scope
|
773
803
|
%i[and or not].each do |name|
|
@@ -781,8 +811,8 @@ module Chewy
|
|
781
811
|
# Returns a new scope containing only specified storages.
|
782
812
|
#
|
783
813
|
# @example
|
784
|
-
# PlacesIndex.limit(10).offset(10).order(:name).
|
785
|
-
# # => <PlacesIndex::Query {..., :body=>{:
|
814
|
+
# PlacesIndex.limit(10).offset(10).order(:name).only(:offset, :order)
|
815
|
+
# # => <PlacesIndex::Query {..., :body=>{:from=>10, :sort=>["name"]}}>
|
786
816
|
# @param values [Array<String, Symbol>]
|
787
817
|
# @return [Chewy::Search::Request] new scope
|
788
818
|
def only(*values)
|
@@ -792,8 +822,8 @@ module Chewy
|
|
792
822
|
# Returns a new scope containing all the storages except specified.
|
793
823
|
#
|
794
824
|
# @example
|
795
|
-
# PlacesIndex.limit(10).offset(10).order(:name).
|
796
|
-
# # => <PlacesIndex::Query {..., :body=>{:
|
825
|
+
# PlacesIndex.limit(10).offset(10).order(:name).except(:offset, :order)
|
826
|
+
# # => <PlacesIndex::Query {..., :body=>{:size=>10}}>
|
797
827
|
# @param values [Array<String, Symbol>]
|
798
828
|
# @return [Chewy::Search::Request] new scope
|
799
829
|
def except(*values)
|
@@ -839,14 +869,14 @@ module Chewy
|
|
839
869
|
# @overload first
|
840
870
|
# If nothing is passed - it returns a single object.
|
841
871
|
#
|
842
|
-
# @return [Chewy::
|
872
|
+
# @return [Chewy::Index] result document
|
843
873
|
#
|
844
874
|
# @overload first(limit)
|
845
875
|
# If limit is provided - it returns the limit amount or less
|
846
876
|
# of wrapper objects.
|
847
877
|
#
|
848
878
|
# @param limit [Integer] amount of requested results
|
849
|
-
# @return [Array<Chewy::
|
879
|
+
# @return [Array<Chewy::Index>] result document collection
|
850
880
|
def first(limit = UNDEFINED)
|
851
881
|
request_limit = limit == UNDEFINED ? 1 : limit
|
852
882
|
|
@@ -865,7 +895,7 @@ module Chewy
|
|
865
895
|
# If single id is passed - it returns a single object.
|
866
896
|
#
|
867
897
|
# @param id [Integer, String] id of the desired document
|
868
|
-
# @return [Chewy::
|
898
|
+
# @return [Chewy::Index] result document
|
869
899
|
#
|
870
900
|
# @overload find(*ids)
|
871
901
|
# If several field are passed - it returns an array of wrappers.
|
@@ -873,7 +903,7 @@ module Chewy
|
|
873
903
|
# batch size - uses scroll API to retrieve everything.
|
874
904
|
#
|
875
905
|
# @param ids [Array<Integer, String>] ids of the desired documents
|
876
|
-
# @return [Array<Chewy::
|
906
|
+
# @return [Array<Chewy::Index>] result documents
|
877
907
|
def find(*ids)
|
878
908
|
return super if block_given?
|
879
909
|
|
@@ -895,7 +925,7 @@ module Chewy
|
|
895
925
|
|
896
926
|
# Returns and array of values for specified fields.
|
897
927
|
# Uses `source` to restrict the list of returned fields.
|
898
|
-
# Fields `_id`, `_type` and `_index` are also supported.
|
928
|
+
# Fields `_id`, `_type`, `_routing` and `_index` are also supported.
|
899
929
|
#
|
900
930
|
# @overload pluck(field)
|
901
931
|
# If single field is passed - it returns and array of values.
|
@@ -928,24 +958,37 @@ module Chewy
|
|
928
958
|
end
|
929
959
|
|
930
960
|
# Deletes all the documents from the specified scope it uses
|
931
|
-
# `delete_by_query`
|
932
|
-
# plugin, which requires additional installation effort.
|
961
|
+
# `delete_by_query`
|
933
962
|
#
|
934
963
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
|
935
|
-
# @see https://www.elastic.co/guide/en/elasticsearch/plugins/2.0/plugins-delete-by-query.html
|
936
964
|
# @note The result hash is different for different API used.
|
937
|
-
# @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
|
+
|
938
971
|
# @return [Hash] the result of query execution
|
939
|
-
def delete_all(refresh: true)
|
940
|
-
request_body = only(WHERE_STORAGES).render.merge(
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
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?
|
949
992
|
end
|
950
993
|
|
951
994
|
protected
|
@@ -957,6 +1000,10 @@ module Chewy
|
|
957
1000
|
|
958
1001
|
private
|
959
1002
|
|
1003
|
+
def build_response(raw_response)
|
1004
|
+
Response.new(raw_response, loader, collection_paginator)
|
1005
|
+
end
|
1006
|
+
|
960
1007
|
def compare_internals(other)
|
961
1008
|
parameters == other.parameters
|
962
1009
|
end
|
@@ -975,21 +1022,17 @@ module Chewy
|
|
975
1022
|
|
976
1023
|
def perform(additional = {})
|
977
1024
|
request_body = render.merge(additional)
|
978
|
-
ActiveSupport::Notifications.instrument 'search_query.chewy',
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
{}
|
984
|
-
end
|
985
|
-
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
|
+
{}
|
1029
|
+
end
|
986
1030
|
end
|
987
1031
|
|
988
1032
|
def notification_payload(additional)
|
989
1033
|
{
|
990
|
-
indexes: _indices,
|
991
|
-
index: _indices.one? ? _indices.first : _indices
|
992
|
-
type: _types.one? ? _types.first : _types
|
1034
|
+
indexes: _indices,
|
1035
|
+
index: _indices.one? ? _indices.first : _indices
|
993
1036
|
}.merge(additional)
|
994
1037
|
end
|
995
1038
|
|
@@ -997,10 +1040,6 @@ module Chewy
|
|
997
1040
|
parameters[:indices].indices
|
998
1041
|
end
|
999
1042
|
|
1000
|
-
def _types
|
1001
|
-
parameters[:indices].types
|
1002
|
-
end
|
1003
|
-
|
1004
1043
|
def raw_limit_value
|
1005
1044
|
parameters[:limit].value
|
1006
1045
|
end
|
@@ -1009,15 +1048,6 @@ module Chewy
|
|
1009
1048
|
parameters[:offset].value
|
1010
1049
|
end
|
1011
1050
|
|
1012
|
-
def delete_by_query_plugin(request)
|
1013
|
-
path = Elasticsearch::API::Utils.__pathify(
|
1014
|
-
Elasticsearch::API::Utils.__listify(request[:index]),
|
1015
|
-
Elasticsearch::API::Utils.__listify(request[:type]),
|
1016
|
-
'_query'
|
1017
|
-
)
|
1018
|
-
Chewy.client.perform_request(Elasticsearch::API::HTTP_DELETE, path, {}, request[:body]).body
|
1019
|
-
end
|
1020
|
-
|
1021
1051
|
def loader
|
1022
1052
|
@loader ||= Loader.new(
|
1023
1053
|
indexes: parameters[:indices].indices,
|
@@ -1033,10 +1063,6 @@ module Chewy
|
|
1033
1063
|
end
|
1034
1064
|
end
|
1035
1065
|
|
1036
|
-
def performed?
|
1037
|
-
!@response.nil?
|
1038
|
-
end
|
1039
|
-
|
1040
1066
|
def collection_paginator
|
1041
1067
|
method(:paginated_collection).to_proc if respond_to?(:paginated_collection, true)
|
1042
1068
|
end
|