stretchy-model 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/README.md +28 -10
- data/Rakefile +56 -0
- data/docs/.nojekyll +0 -0
- data/docs/README.md +147 -0
- data/docs/_coverpage.md +14 -0
- data/docs/_sidebar.md +15 -0
- data/docs/examples/_sidebar.md +15 -0
- data/docs/examples/data_analysis.md +216 -0
- data/docs/examples/neural_search_with_llm.md +381 -0
- data/docs/examples/simple-ingest-pipeline.md +326 -0
- data/docs/guides/_sidebar.md +15 -0
- data/docs/guides/aggregations.md +142 -0
- data/docs/guides/machine-learning.md +154 -0
- data/docs/guides/models.md +372 -0
- data/docs/guides/pipelines.md +151 -0
- data/docs/guides/querying.md +361 -0
- data/docs/guides/quick-start.md +72 -0
- data/docs/guides/scopes.md +125 -0
- data/docs/index.html +113 -0
- data/docs/stretchy.cover.png +0 -0
- data/docs/stretchy.logo.png +0 -0
- data/docs/styles.css +90 -0
- data/lib/elasticsearch/api/actions/connector/check_in.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/delete.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/get.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/last_sync.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/list.rb +60 -0
- data/lib/elasticsearch/api/actions/connector/post.rb +57 -0
- data/lib/elasticsearch/api/actions/connector/put.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_api_key_id.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_configuration.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_error.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_filtering.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_index_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_native.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_pipeline.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_scheduling.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_service_type.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_status.rb +66 -0
- data/lib/elasticsearch/api/namespace/connector.rb +36 -0
- data/lib/opensearch/api/actions/machine_learning/connector/delete.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/get.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/list.rb +38 -0
- data/lib/opensearch/api/actions/machine_learning/connector/post.rb +35 -0
- data/lib/opensearch/api/actions/machine_learning/connector/put.rb +44 -0
- data/lib/opensearch/api/actions/machine_learning/models/predict.rb +32 -0
- data/lib/opensearch/api/namespace/connector.rb +19 -0
- data/lib/stretchy/attributes/transformers/keyword_transformer.rb +41 -35
- data/lib/stretchy/attributes/type/array.rb +24 -1
- data/lib/stretchy/attributes/type/base.rb +6 -2
- data/lib/stretchy/attributes/type/binary.rb +24 -17
- data/lib/stretchy/attributes/type/boolean.rb +29 -22
- data/lib/stretchy/attributes/type/completion.rb +18 -10
- data/lib/stretchy/attributes/type/constant_keyword.rb +35 -26
- data/lib/stretchy/attributes/type/date_time.rb +28 -17
- data/lib/stretchy/attributes/type/dense_vector.rb +46 -49
- data/lib/stretchy/attributes/type/flattened.rb +28 -19
- data/lib/stretchy/attributes/type/geo_point.rb +21 -12
- data/lib/stretchy/attributes/type/geo_shape.rb +21 -12
- data/lib/stretchy/attributes/type/hash.rb +24 -10
- data/lib/stretchy/attributes/type/histogram.rb +25 -0
- data/lib/stretchy/attributes/type/ip.rb +26 -17
- data/lib/stretchy/attributes/type/join.rb +16 -7
- data/lib/stretchy/attributes/type/keyword.rb +21 -26
- data/lib/stretchy/attributes/type/knn_vector.rb +47 -0
- data/lib/stretchy/attributes/type/match_only_text.rb +22 -1
- data/lib/stretchy/attributes/type/nested.rb +16 -11
- data/lib/stretchy/attributes/type/numeric/base.rb +30 -22
- data/lib/stretchy/attributes/type/numeric/byte.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/double.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/half_float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/integer.rb +21 -1
- data/lib/stretchy/attributes/type/numeric/long.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/scaled_float.rb +16 -7
- data/lib/stretchy/attributes/type/numeric/short.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +21 -1
- data/lib/stretchy/attributes/type/percolator.rb +16 -4
- data/lib/stretchy/attributes/type/point.rb +19 -9
- data/lib/stretchy/attributes/type/range/base.rb +24 -1
- data/lib/stretchy/attributes/type/range/date_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/double_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/float_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/integer_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/ip_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/long_range.rb +20 -4
- data/lib/stretchy/attributes/type/rank_feature.rb +16 -6
- data/lib/stretchy/attributes/type/rank_features.rb +16 -9
- data/lib/stretchy/attributes/type/search_as_you_type.rb +28 -18
- data/lib/stretchy/attributes/type/shape.rb +19 -9
- data/lib/stretchy/attributes/type/sparse_vector.rb +25 -21
- data/lib/stretchy/attributes/type/string.rb +42 -1
- data/lib/stretchy/attributes/type/text.rb +53 -28
- data/lib/stretchy/attributes/type/token_count.rb +21 -11
- data/lib/stretchy/attributes/type/version.rb +16 -6
- data/lib/stretchy/attributes/type/wildcard.rb +36 -25
- data/lib/stretchy/attributes.rb +29 -0
- data/lib/stretchy/delegation/gateway_delegation.rb +78 -0
- data/lib/stretchy/index_setting.rb +94 -0
- data/lib/stretchy/indexing/bulk.rb +75 -3
- data/lib/stretchy/machine_learning/connector.rb +130 -0
- data/lib/stretchy/machine_learning/errors.rb +25 -0
- data/lib/stretchy/machine_learning/model.rb +162 -109
- data/lib/stretchy/machine_learning/registry.rb +19 -0
- data/lib/stretchy/model/callbacks.rb +1 -0
- data/lib/stretchy/model/common.rb +157 -0
- data/lib/stretchy/model/persistence.rb +144 -0
- data/lib/stretchy/model/refreshable.rb +26 -0
- data/lib/stretchy/open_search_compatibility.rb +2 -0
- data/lib/stretchy/pipeline.rb +2 -1
- data/lib/stretchy/pipelines/processor.rb +40 -36
- data/lib/stretchy/querying.rb +7 -8
- data/lib/stretchy/rails/railtie.rb +11 -0
- data/lib/stretchy/rails/tasks/connector/create.rake +32 -0
- data/lib/stretchy/rails/tasks/connector/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/connector/status.rake +31 -0
- data/lib/stretchy/rails/tasks/connector/update.rake +32 -0
- data/lib/stretchy/rails/tasks/index/create.rake +28 -0
- data/lib/stretchy/rails/tasks/index/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/index/status.rake +23 -0
- data/lib/stretchy/rails/tasks/ml/delete.rake +25 -0
- data/lib/stretchy/rails/tasks/ml/deploy.rake +78 -0
- data/lib/stretchy/rails/tasks/ml/status.rake +31 -0
- data/lib/stretchy/rails/tasks/pipeline/create.rake +27 -0
- data/lib/stretchy/rails/tasks/pipeline/delete.rake +26 -0
- data/lib/stretchy/rails/tasks/pipeline/status.rake +25 -0
- data/lib/stretchy/rails/tasks/status.rake +15 -0
- data/lib/stretchy/rails/tasks/stretchy.rake +42 -0
- data/lib/stretchy/record.rb +5 -4
- data/lib/stretchy/relation.rb +229 -28
- data/lib/stretchy/relations/aggregation_methods/aggregation.rb +59 -0
- data/lib/stretchy/relations/aggregation_methods/avg.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_script.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_selector.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_sort.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/cardinality.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/children.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/composite.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/date_histogram.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/date_range.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/extended_stats.rb +48 -0
- data/lib/stretchy/relations/aggregation_methods/filter.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/filters.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/geo_bounds.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/geo_centroid.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/global.rb +39 -0
- data/lib/stretchy/relations/aggregation_methods/histogram.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/ip_range.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/max.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/min.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/missing.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/percentile_ranks.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/percentiles.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/range.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/reverse_nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/sampler.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/scripted_metric.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/significant_terms.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/stats.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/sum.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/terms.rb +46 -0
- data/lib/stretchy/relations/aggregation_methods/top_hits.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/top_metrics.rb +44 -0
- data/lib/stretchy/relations/aggregation_methods/value_count.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/weighted_avg.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods.rb +20 -749
- data/lib/stretchy/relations/finder_methods.rb +2 -18
- data/lib/stretchy/relations/null_relation.rb +55 -0
- data/lib/stretchy/relations/query_builder.rb +82 -36
- data/lib/stretchy/relations/query_methods/bind.rb +19 -0
- data/lib/stretchy/relations/query_methods/extending.rb +29 -0
- data/lib/stretchy/relations/query_methods/fields.rb +70 -0
- data/lib/stretchy/relations/query_methods/filter_query.rb +53 -0
- data/lib/stretchy/relations/query_methods/has_field.rb +40 -0
- data/lib/stretchy/relations/query_methods/highlight.rb +75 -0
- data/lib/stretchy/relations/query_methods/hybrid.rb +60 -0
- data/lib/stretchy/relations/query_methods/ids.rb +40 -0
- data/lib/stretchy/relations/query_methods/match.rb +52 -0
- data/lib/stretchy/relations/query_methods/must_not.rb +54 -0
- data/lib/stretchy/relations/query_methods/neural.rb +58 -0
- data/lib/stretchy/relations/query_methods/neural_sparse.rb +43 -0
- data/lib/stretchy/relations/query_methods/none.rb +21 -0
- data/lib/stretchy/relations/query_methods/or_filter.rb +21 -0
- data/lib/stretchy/relations/query_methods/order.rb +63 -0
- data/lib/stretchy/relations/query_methods/query_string.rb +44 -0
- data/lib/stretchy/relations/query_methods/regexp.rb +61 -0
- data/lib/stretchy/relations/query_methods/should.rb +51 -0
- data/lib/stretchy/relations/query_methods/size.rb +44 -0
- data/lib/stretchy/relations/query_methods/skip_callbacks.rb +47 -0
- data/lib/stretchy/relations/query_methods/source.rb +59 -0
- data/lib/stretchy/relations/query_methods/where.rb +113 -0
- data/lib/stretchy/relations/query_methods.rb +48 -569
- data/lib/stretchy/relations/scoping/default.rb +136 -0
- data/lib/stretchy/relations/scoping/named.rb +70 -0
- data/lib/stretchy/relations/scoping/scope_registry.rb +36 -0
- data/lib/stretchy/relations/scoping.rb +30 -0
- data/lib/stretchy/relations/search_option_methods.rb +2 -0
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +24 -10
- metadata +170 -17
- data/lib/stretchy/common.rb +0 -38
- data/lib/stretchy/null_relation.rb +0 -53
- data/lib/stretchy/persistence.rb +0 -43
- data/lib/stretchy/refreshable.rb +0 -15
- data/lib/stretchy/scoping/default.rb +0 -134
- data/lib/stretchy/scoping/named.rb +0 -68
- data/lib/stretchy/scoping/scope_registry.rb +0 -34
- data/lib/stretchy/scoping.rb +0 -28
@@ -2,756 +2,27 @@ module Stretchy
|
|
2
2
|
module Relations
|
3
3
|
module AggregationMethods
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
:min,
|
26
|
-
:missing,
|
27
|
-
:nested,
|
28
|
-
:percentile_ranks,
|
29
|
-
:percentiles,
|
30
|
-
:range,
|
31
|
-
:reverse_nested,
|
32
|
-
:sampler,
|
33
|
-
:scripted_metric,
|
34
|
-
:significant_terms,
|
35
|
-
:stats,
|
36
|
-
:sum,
|
37
|
-
:terms,
|
38
|
-
:top_hits,
|
39
|
-
:top_metrics,
|
40
|
-
:value_count,
|
41
|
-
:weighted_avg
|
42
|
-
].freeze
|
43
|
-
|
44
|
-
# Adds an aggregation to the query.
|
45
|
-
#
|
46
|
-
# @param name [Symbol, String] the name of the aggregation
|
47
|
-
# @param options [Hash] a hash of options for the aggregation
|
48
|
-
# @param block [Proc] an optional block to further configure the aggregation
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# Model.aggregation(:avg_price, field: :price)
|
52
|
-
# Model.aggregation(:price_ranges) do
|
53
|
-
# range field: :price, ranges: [{to: 100}, {from: 100, to: 200}, {from: 200}]
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# Aggregation results are available in the `aggregations` method of the results under name provided in the aggregation.
|
57
|
-
#
|
58
|
-
# @example
|
59
|
-
# results = Model.where(color: :blue).aggregation(:avg_price, field: :price)
|
60
|
-
# results.aggregations.avg_price
|
61
|
-
#
|
62
|
-
# @return [Stretchy::Relation] a new relation
|
63
|
-
def aggregation(name, options = {}, &block)
|
64
|
-
spawn.aggregation!(name, options, &block)
|
65
|
-
end
|
66
|
-
|
67
|
-
def aggregation!(name, options = {}, &block) # :nodoc:
|
68
|
-
self.aggregation_values += [{name: name, args: assume_keyword_field(options)}]
|
69
|
-
self
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# Public: Perform an avg aggregation.
|
75
|
-
#
|
76
|
-
# name - The Symbol or String name of the aggregation.
|
77
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
78
|
-
# :field - The field to calculate the average on.
|
79
|
-
# aggs - The Hash of nested aggregations.
|
80
|
-
#
|
81
|
-
# Examples
|
82
|
-
#
|
83
|
-
# Model.aggregation(:average_price, field: :price)
|
84
|
-
#
|
85
|
-
# Returns a new Stretchy::Relation.
|
86
|
-
def avg(name, options = {}, *aggs)
|
87
|
-
options = {avg: options}.merge(*aggs)
|
88
|
-
aggregation(name, options)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Public: Perform a bucket_script aggregation.
|
92
|
-
#
|
93
|
-
# name - The Symbol or String name of the aggregation.
|
94
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
95
|
-
# :buckets_path - The paths to the buckets.
|
96
|
-
# :script - The script to execute.
|
97
|
-
# aggs - The Hash of nested aggregations.
|
98
|
-
#
|
99
|
-
# Examples
|
100
|
-
#
|
101
|
-
# Model.aggregation(:total_sales, script: "params.tShirtsSold * params.price", buckets_path: {tShirtsSold: "tShirtsSold", price: "price"})
|
102
|
-
#
|
103
|
-
# Returns a new Stretchy::Relation.
|
104
|
-
def bucket_script(name, options = {}, *aggs)
|
105
|
-
options = {bucket_script: options}.merge(*aggs)
|
106
|
-
aggregation(name, options)
|
107
|
-
end
|
108
|
-
|
109
|
-
# Public: Perform a bucket_selector aggregation.
|
110
|
-
#
|
111
|
-
# name - The Symbol or String name of the aggregation.
|
112
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
113
|
-
# :script - The script to determine whether the current bucket will be retained.
|
114
|
-
# aggs - The Hash of nested aggregations.
|
115
|
-
#
|
116
|
-
# Examples
|
117
|
-
#
|
118
|
-
# Model.aggregation(:sales_bucket_filter, script: "params.totalSales > 200", buckets_path: {totalSales: "totalSales"})
|
119
|
-
#
|
120
|
-
# Returns a new Stretchy::Relation.
|
121
|
-
def bucket_selector(name, options = {}, *aggs)
|
122
|
-
options = {bucket_selector: options}.merge(*aggs)
|
123
|
-
aggregation(name, options)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Public: Perform a bucket_sort aggregation.
|
127
|
-
#
|
128
|
-
# name - The Symbol or String name of the aggregation.
|
129
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
130
|
-
# :field - The field to sort on.
|
131
|
-
# aggs - The Hash of nested aggregations.
|
132
|
-
#
|
133
|
-
# Examples
|
134
|
-
#
|
135
|
-
# Model.bucket_sort(:my_agg, {field: 'my_field'})
|
136
|
-
# Model.bucket_sort(:my_agg, {field: 'my_field'}, aggs: {...})
|
137
|
-
#
|
138
|
-
# Returns a new Stretchy::Relation.
|
139
|
-
def bucket_sort(name, options = {}, *aggs)
|
140
|
-
options = {bucket_sort: options}.merge(*aggs)
|
141
|
-
aggregation(name, options)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Public: Perform a cardinality aggregation.
|
145
|
-
#
|
146
|
-
# name - The Symbol or String name of the aggregation.
|
147
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
148
|
-
# :field - The field to perform the aggregation on.
|
149
|
-
# aggs - The Hash of nested aggregations.
|
150
|
-
#
|
151
|
-
# Examples
|
152
|
-
#
|
153
|
-
# Model.cardinality(:unique_names, {field: 'names'})
|
154
|
-
# Model.cardinality(:unique_names, {field: 'names'}, aggs: {...})
|
155
|
-
#
|
156
|
-
# Returns a new Stretchy::Relation.
|
157
|
-
def cardinality(name, options = {}, *aggs)
|
158
|
-
options = {cardinality: options}.merge(*aggs)
|
159
|
-
aggregation(name, options)
|
160
|
-
end
|
161
|
-
|
162
|
-
# Public: Perform a children aggregation.
|
163
|
-
#
|
164
|
-
# name - The Symbol or String name of the aggregation.
|
165
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
166
|
-
# :type - The type of children to aggregate.
|
167
|
-
# aggs - The Hash of nested aggregations.
|
168
|
-
#
|
169
|
-
# Examples
|
170
|
-
#
|
171
|
-
# Model.children(:my_agg, {type: 'my_type'})
|
172
|
-
# Model.children(:my_agg, {type: 'my_type'}, aggs: {...})
|
173
|
-
#
|
174
|
-
# Returns a new Stretchy::Relation.
|
175
|
-
def children(name, options = {}, *aggs)
|
176
|
-
options = {children: options}.merge(*aggs)
|
177
|
-
aggregation(name, options)
|
178
|
-
end
|
179
|
-
|
180
|
-
# Public: Perform a composite aggregation.
|
181
|
-
#
|
182
|
-
# name - The Symbol or String name of the aggregation.
|
183
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
184
|
-
# :sources - The sources to use for the composite aggregation.
|
185
|
-
# :size - The size of the composite aggregation.
|
186
|
-
# aggs - The Hash of nested aggregations.
|
187
|
-
#
|
188
|
-
# Examples
|
189
|
-
#
|
190
|
-
# Model.composite(:my_agg, {sources: [...], size: 100})
|
191
|
-
# Model.composite(:my_agg, {sources: [...], size: 100}, aggs: {...})
|
192
|
-
#
|
193
|
-
# Returns a new Stretchy::Relation.
|
194
|
-
def composite(name, options = {}, *aggs)
|
195
|
-
options = {composite: options}.merge(*aggs)
|
196
|
-
aggregation(name, options)
|
197
|
-
end
|
198
|
-
|
199
|
-
# Public: Perform a date_histogram aggregation.
|
200
|
-
#
|
201
|
-
# name - The Symbol or String name of the aggregation.
|
202
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
203
|
-
# :field - The field to use for the date_histogram aggregation.
|
204
|
-
# :interval - The interval for the date_histogram aggregation.
|
205
|
-
# :calendar_interval - The calendar interval for the date_histogram aggregation.
|
206
|
-
# :format - The format for the date_histogram aggregation.
|
207
|
-
# :time_zone - The time zone for the date_histogram aggregation.
|
208
|
-
# :min_doc_count - The minimum document count for the date_histogram aggregation.
|
209
|
-
# :extended_bounds - The extended bounds for the date_histogram aggregation.
|
210
|
-
# aggs - The Hash of nested aggregations.
|
211
|
-
#
|
212
|
-
# Examples
|
213
|
-
#
|
214
|
-
# Model.date_histogram(:my_agg, {field: 'date', interval: 'month', format: 'MM-yyyy', time_zone: 'UTC'})
|
215
|
-
# Model.date_histogram(:my_agg, {field: 'date', calendar_interval: :month, format: 'MM-yyyy', time_zone: 'UTC'}, aggs: {...})
|
216
|
-
#
|
217
|
-
# Returns a new Stretchy::Relation.
|
218
|
-
def date_histogram(name, options = {}, *aggs)
|
219
|
-
options = {date_histogram: options}.merge(*aggs)
|
220
|
-
aggregation(name, options)
|
221
|
-
end
|
222
|
-
|
223
|
-
# Public: Perform a date_range aggregation.
|
224
|
-
#
|
225
|
-
# name - The Symbol or String name of the aggregation.
|
226
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
227
|
-
# :field - The field to use for the date_range aggregation.
|
228
|
-
# :format - The format for the date_range aggregation.
|
229
|
-
# :time_zone - The time zone for the date_range aggregation.
|
230
|
-
# :ranges - The ranges for the date_range aggregation.
|
231
|
-
# :keyed - The keyed option for the date_range aggregation.
|
232
|
-
# aggs - The Hash of nested aggregations.
|
233
|
-
#
|
234
|
-
# Examples
|
235
|
-
#
|
236
|
-
# Model.date_range(:my_agg, {field: 'date', format: 'MM-yyyy', time_zone: 'UTC', ranges: [{to: 'now', from: 'now-1M'}]})
|
237
|
-
# Model.date_range(:my_agg, {field: 'date', format: 'MM-yyyy', time_zone: 'UTC', ranges: [{to: 'now', from: 'now-1M'}]}, aggs: {...})
|
238
|
-
#
|
239
|
-
# Returns a new Stretchy::Relation.
|
240
|
-
def date_range(name, options = {}, *aggs)
|
241
|
-
options = {date_range: options}.merge(*aggs)
|
242
|
-
aggregation(name, options)
|
243
|
-
end
|
244
|
-
# Public: Perform an extended_stats aggregation.
|
245
|
-
#
|
246
|
-
# name - The Symbol or String name of the aggregation.
|
247
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
248
|
-
# :field - The field to use for the extended_stats aggregation.
|
249
|
-
# :sigma - The sigma for the extended_stats aggregation.
|
250
|
-
# aggs - The Array of additional nested aggregations (optional).
|
251
|
-
#
|
252
|
-
# Examples
|
253
|
-
#
|
254
|
-
# Model.extended_stats(:my_agg, {field: 'field_name', sigma: 1.0})
|
255
|
-
# Model.extended_stats(:my_agg, {field: 'field_name', sigma: 1.0}, aggs: {...})
|
256
|
-
#
|
257
|
-
# Returns a new Stretchy::Relation.
|
258
|
-
def extended_stats(name, options = {}, *aggs)
|
259
|
-
options = {extended_stats: options}.merge(*aggs)
|
260
|
-
aggregation(name, options)
|
261
|
-
end
|
262
|
-
|
263
|
-
# Public: Perform a filter_agg aggregation.
|
264
|
-
#
|
265
|
-
# name - The Symbol or String name of the aggregation.
|
266
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
267
|
-
# :filter - The filter to use for the filter_agg aggregation.
|
268
|
-
# aggs - The Array of additional nested aggregations (optional).
|
269
|
-
#
|
270
|
-
# Examples
|
271
|
-
#
|
272
|
-
# Model.filter_agg(:my_agg, {filter: {...}})
|
273
|
-
# Model.filter_agg(:my_agg, {filter: {...}}, aggs: {...})
|
274
|
-
#
|
275
|
-
# Returns a new Stretchy::Relation.
|
276
|
-
def filter(name, options = {}, *aggs)
|
277
|
-
options = {filter: options}.merge(*aggs)
|
278
|
-
aggregation(name, options)
|
279
|
-
end
|
280
|
-
|
281
|
-
# Public: Perform a filters aggregation.
|
282
|
-
#
|
283
|
-
# name - The Symbol or String name of the aggregation.
|
284
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
285
|
-
# :filters - The filters to use for the filters aggregation.
|
286
|
-
# aggs - The Array of additional nested aggregations (optional).
|
287
|
-
#
|
288
|
-
# Examples
|
289
|
-
#
|
290
|
-
# Model.filters(:my_agg, {filters: {...}})
|
291
|
-
# Model.filters(:my_agg, {filters: {...}}, aggs: {...})
|
292
|
-
#
|
293
|
-
# Returns a new Stretchy::Relation.
|
294
|
-
def filters(name, options = {}, *aggs)
|
295
|
-
options = {filters: options}.merge(*aggs)
|
296
|
-
aggregation(name, options)
|
297
|
-
end
|
298
|
-
|
299
|
-
# Public: Perform a geo_bounds aggregation.
|
300
|
-
#
|
301
|
-
# name - The Symbol or String name of the aggregation.
|
302
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
303
|
-
# :field - The field to use for the geo_bounds aggregation.
|
304
|
-
# aggs - The Array of additional nested aggregations (optional).
|
305
|
-
#
|
306
|
-
# Examples
|
307
|
-
#
|
308
|
-
# Model.geo_bounds(:my_agg, {field: 'location_field'})
|
309
|
-
# Model.geo_bounds(:my_agg, {field: 'location_field'}, aggs: {...})
|
310
|
-
#
|
311
|
-
# Returns a new Stretchy::Relation.
|
312
|
-
def geo_bounds(name, options = {}, *aggs)
|
313
|
-
options = {geo_bounds: options}.merge(*aggs)
|
314
|
-
aggregation(name, options)
|
315
|
-
end
|
316
|
-
|
317
|
-
# Public: Perform a geo_centroid aggregation.
|
318
|
-
#
|
319
|
-
# name - The Symbol or String name of the aggregation.
|
320
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
321
|
-
# :field - The field to use for the geo_centroid aggregation.
|
322
|
-
# aggs - The Array of additional nested aggregations (optional).
|
323
|
-
#
|
324
|
-
# Examples
|
325
|
-
#
|
326
|
-
# Model.geo_centroid(:my_agg, {field: 'location_field'})
|
327
|
-
# Model.geo_centroid(:my_agg, {field: 'location_field'}, aggs: {...})
|
328
|
-
#
|
329
|
-
# Returns a new Stretchy::Relation.
|
330
|
-
def geo_centroid(name, options = {}, *aggs)
|
331
|
-
options = {geo_centroid: options}.merge(*aggs)
|
332
|
-
aggregation(name, options)
|
333
|
-
end
|
334
|
-
|
335
|
-
# Public: Perform a global aggregation.
|
336
|
-
#
|
337
|
-
# name - The Symbol or String name of the aggregation.
|
338
|
-
# options - The Hash options used to refine the aggregation (default: {}).
|
339
|
-
# aggs - The Array of additional nested aggregations (optional).
|
340
|
-
#
|
341
|
-
# Examples
|
342
|
-
#
|
343
|
-
# Model.global(:my_agg)
|
344
|
-
# Model.global(:my_agg, {}, aggs: {...})
|
345
|
-
#
|
346
|
-
# Returns a new Stretchy::Relation.
|
347
|
-
def global(name, options = {}, *aggs)
|
348
|
-
options = {global: options}.merge(*aggs)
|
349
|
-
aggregation(name, options)
|
350
|
-
end
|
351
|
-
# Public: Perform a histogram aggregation.
|
352
|
-
#
|
353
|
-
# name - The Symbol or String name of the aggregation.
|
354
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
355
|
-
# :field - The field to use for the histogram aggregation.
|
356
|
-
# :interval - The interval for the histogram aggregation.
|
357
|
-
# :min_doc_count - The minimum document count for the histogram aggregation.
|
358
|
-
# :extended_bounds - The extended bounds for the histogram aggregation.
|
359
|
-
# aggs - The Array of additional nested aggregations (optional).
|
360
|
-
#
|
361
|
-
# Examples
|
362
|
-
#
|
363
|
-
# Model.histogram(:my_agg, {field: 'field_name', interval: 5})
|
364
|
-
# Model.histogram(:my_agg, {field: 'field_name', interval: 5}, aggs: {...})
|
365
|
-
#
|
366
|
-
# Returns a new Stretchy::Relation.
|
367
|
-
def histogram(name, options = {}, *aggs)
|
368
|
-
options = {histogram: options}.merge(*aggs)
|
369
|
-
aggregation(name, options)
|
370
|
-
end
|
371
|
-
|
372
|
-
# Public: Perform an ip_range aggregation.
|
373
|
-
#
|
374
|
-
# name - The Symbol or String name of the aggregation.
|
375
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
376
|
-
# :field - The field to use for the ip_range aggregation.
|
377
|
-
# :ranges - The ranges to use for the ip_range aggregation. ranges: [{to: '10.0.0.5'}, {from: '10.0.0.5'}]
|
378
|
-
# aggs - The Array of additional nested aggregations (optional).
|
379
|
-
#
|
380
|
-
# Examples
|
381
|
-
#
|
382
|
-
# Model.ip_range(:my_agg, {field: 'ip_field'})
|
383
|
-
# Model.ip_range(:my_agg, {field: 'ip_field'}, aggs: {...})
|
384
|
-
#
|
385
|
-
# Returns a new Stretchy::Relation.
|
386
|
-
def ip_range(name, options = {}, *aggs)
|
387
|
-
options = {ip_range: options}.merge(*aggs)
|
388
|
-
aggregation(name, options)
|
389
|
-
end
|
390
|
-
|
391
|
-
# Public: Perform a max aggregation.
|
392
|
-
#
|
393
|
-
# name - The Symbol or String name of the aggregation.
|
394
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
395
|
-
# :field - The field to use for the max aggregation.
|
396
|
-
# aggs - The Array of additional nested aggregations (optional).
|
397
|
-
#
|
398
|
-
# Examples
|
399
|
-
#
|
400
|
-
# Model.max(:my_agg, {field: 'field_name'})
|
401
|
-
# Model.max(:my_agg, {field: 'field_name'}, aggs: {...})
|
402
|
-
#
|
403
|
-
# Returns a new Stretchy::Relation.
|
404
|
-
def max(name, options = {}, *aggs)
|
405
|
-
options = {max: options}.merge(*aggs)
|
406
|
-
aggregation(name, options)
|
407
|
-
end
|
408
|
-
|
409
|
-
# Public: Perform a min aggregation.
|
410
|
-
#
|
411
|
-
# name - The Symbol or String name of the aggregation.
|
412
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
413
|
-
# :field - The field to use for the min aggregation.
|
414
|
-
# aggs - The Array of additional nested aggregations (optional).
|
415
|
-
#
|
416
|
-
# Examples
|
417
|
-
#
|
418
|
-
# Model.min(:my_agg, {field: 'field_name'})
|
419
|
-
# Model.min(:my_agg, {field: 'field_name'}, aggs: {...})
|
420
|
-
#
|
421
|
-
# Returns a new Stretchy::Relation.
|
422
|
-
def min(name, options = {}, *aggs)
|
423
|
-
options = {min: options}.merge(*aggs)
|
424
|
-
aggregation(name, options)
|
425
|
-
end
|
426
|
-
|
427
|
-
# Public: Perform a missing aggregation.
|
428
|
-
#
|
429
|
-
# name - The Symbol or String name of the aggregation.
|
430
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
431
|
-
# :field - The field to use for the missing aggregation.
|
432
|
-
# aggs - The Array of additional nested aggregations (optional).
|
433
|
-
#
|
434
|
-
# Examples
|
435
|
-
#
|
436
|
-
# Model.missing(:my_agg, {field: 'field_name'})
|
437
|
-
# Model.missing(:my_agg, {field: 'field_name'}, aggs: {...})
|
438
|
-
#
|
439
|
-
# Returns a new Stretchy::Relation.
|
440
|
-
def missing(name, options = {}, *aggs)
|
441
|
-
options = {missing: options}.merge(*aggs)
|
442
|
-
aggregation(name, options)
|
443
|
-
end
|
444
|
-
|
445
|
-
# Public: Perform a nested aggregation.
|
446
|
-
#
|
447
|
-
# name - The Symbol or String name of the aggregation.
|
448
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
449
|
-
# :path - The path to use for the nested aggregation.
|
450
|
-
# aggs - The Array of additional nested aggregations (optional).
|
451
|
-
#
|
452
|
-
# Examples
|
453
|
-
#
|
454
|
-
# Model.nested(:my_agg, {path: 'path_to_field'})
|
455
|
-
# Model.nested(:my_agg, {path: 'path_to_field'}, aggs: {...})
|
456
|
-
#
|
457
|
-
# Returns a new Stretchy::Relation.
|
458
|
-
def nested(name, options = {}, *aggs)
|
459
|
-
options = {nested: options}.merge(*aggs)
|
460
|
-
aggregation(name, options)
|
461
|
-
end
|
462
|
-
|
463
|
-
# Public: Perform a percentile_ranks aggregation.
|
464
|
-
#
|
465
|
-
# name - The Symbol or String name of the aggregation.
|
466
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
467
|
-
# :field - The field to use for the percentile_ranks aggregation.
|
468
|
-
# :values - The values to use for the percentile_ranks aggregation.
|
469
|
-
# :keyed - associates a unique string key with each bucket and returns the ranges as a hash rather than an array. default: true
|
470
|
-
# :script - The script to use for the percentile_ranks aggregation. (optional) script: {source: "doc['field_name'].value", lang: "painless"}
|
471
|
-
# :hdr - The hdr to use for the percentile_ranks aggregation. (optional) hdr: {number_of_significant_value_digits: 3}
|
472
|
-
# :missing - The missing to use for the percentile_ranks aggregation. (optional) missing: 10
|
473
|
-
# aggs - The Array of additional nested aggregations (optional).
|
474
|
-
#
|
475
|
-
# Examples
|
476
|
-
#
|
477
|
-
# Model.percentile_ranks(:my_agg, {field: 'field_name', values: [1, 2, 3]})
|
478
|
-
# Model.percentile_ranks(:my_agg, {field: 'field_name', values: [1, 2, 3]}, aggs: {...})
|
479
|
-
#
|
480
|
-
# Returns a new Stretchy::Relation.
|
481
|
-
def percentile_ranks(name, options = {}, *aggs)
|
482
|
-
options = {percentile_ranks: options}.merge(*aggs)
|
483
|
-
aggregation(name, options)
|
484
|
-
end
|
485
|
-
|
486
|
-
# Public: Perform a percentiles aggregation.
|
487
|
-
#
|
488
|
-
# name - The Symbol or String name of the aggregation.
|
489
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
490
|
-
# :field - The field to use for the percentiles aggregation.
|
491
|
-
# :percents - The percents to use for the percentiles aggregation. percents: [95, 99, 99.9]
|
492
|
-
# :keyed - associates a unique string key with each bucket and returns the ranges as a hash rather than an array. default: true
|
493
|
-
# :tdigest - The tdigest to use for the percentiles aggregation. (optional) tdigest: {compression: 100, execution_hint: "high_accuracy"}
|
494
|
-
# :compression - The compression factor to use for the t-digest algorithm. A higher compression factor will yield more accurate percentiles, but will require more memory. The default value is 100.
|
495
|
-
# :execution_hint - The execution_hint to use for the t-digest algorithm. (optional) execution_hint: "auto"
|
496
|
-
# aggs - The Array of additional nested aggregations (optional).
|
497
|
-
#
|
498
|
-
# Examples
|
499
|
-
#
|
500
|
-
# Model.percentiles(:my_agg, {field: 'field_name', percents: [1, 2, 3]})
|
501
|
-
# Model.percentiles(:my_agg, {field: 'field_name', percents: [1, 2, 3]}, aggs: {...})
|
502
|
-
#
|
503
|
-
# Returns a new Stretchy::Relation.
|
504
|
-
def percentiles(name, options = {}, *aggs)
|
505
|
-
options = {percentiles: options}.merge(*aggs)
|
506
|
-
aggregation(name, options)
|
507
|
-
end
|
508
|
-
|
509
|
-
# Public: Perform a range aggregation.
|
510
|
-
#
|
511
|
-
# name - The Symbol or String name of the aggregation.
|
512
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
513
|
-
# :field - The field to use for the range aggregation.
|
514
|
-
# :ranges - The ranges to use for the range aggregation.
|
515
|
-
# :keyed - associates a unique string key with each bucket and returns the ranges as a hash rather than an array. default: true
|
516
|
-
# aggs - The Array of additional nested aggregations (optional).
|
517
|
-
#
|
518
|
-
# Examples
|
519
|
-
#
|
520
|
-
# Model.range(:my_agg, {field: 'field_name', ranges: [{from: 1, to: 2}, {from: 2, to: 3}]})
|
521
|
-
# Model.range(:my_agg, {field: 'field_name', ranges: [{from: 1, to: 2}, {from: 2, to: 3}]}, aggs: {...})
|
522
|
-
#
|
523
|
-
# Returns a new Stretchy::Relation.
|
524
|
-
def range(name, options = {}, *aggs)
|
525
|
-
options = {range: options}.merge(*aggs)
|
526
|
-
aggregation(name, options)
|
527
|
-
end
|
528
|
-
|
529
|
-
# Public: Perform a reverse_nested aggregation.
|
530
|
-
#
|
531
|
-
# name - The Symbol or String name of the aggregation.
|
532
|
-
# options - The Hash options used to refine the aggregation (default: {}).
|
533
|
-
# aggs - The Array of additional nested aggregations (optional).
|
534
|
-
#
|
535
|
-
# Examples
|
536
|
-
#
|
537
|
-
# Model.reverse_nested(:my_agg)
|
538
|
-
# Model.reverse_nested(:my_agg, {}, aggs: {...})
|
539
|
-
#
|
540
|
-
# Returns a new Stretchy::Relation.
|
541
|
-
def reverse_nested(name, options = {}, *aggs)
|
542
|
-
options = {reverse_nested: options}.merge(*aggs)
|
543
|
-
aggregation(name, options)
|
544
|
-
end
|
545
|
-
|
546
|
-
# Public: Perform a sampler aggregation.
|
547
|
-
#
|
548
|
-
# name - The Symbol or String name of the aggregation.
|
549
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
550
|
-
# :shard_size - The shard size to use for the sampler aggregation.
|
551
|
-
# aggs - The Array of additional nested aggregations (optional).
|
552
|
-
#
|
553
|
-
# Examples
|
554
|
-
#
|
555
|
-
# Model.sampler(:my_agg, {shard_size: 100})
|
556
|
-
# Model.sampler(:my_agg, {shard_size: 100}, aggs: {...})
|
557
|
-
#
|
558
|
-
# Returns a new Stretchy::Relation.
|
559
|
-
def sampler(name, options = {}, *aggs)
|
560
|
-
options = {sampler: options}.merge(*aggs)
|
561
|
-
aggregation(name, options)
|
562
|
-
end
|
563
|
-
|
564
|
-
# Public: Perform a scripted_metric aggregation.
|
565
|
-
#
|
566
|
-
# name - The Symbol or String name of the aggregation.
|
567
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
568
|
-
# :init_script - The initialization script for the scripted_metric aggregation.
|
569
|
-
# :map_script - The map script for the scripted_metric aggregation.
|
570
|
-
# :combine_script - The combine script for the scripted_metric aggregation.
|
571
|
-
# :reduce_script - The reduce script for the scripted_metric aggregation.
|
572
|
-
# aggs - The Array of additional nested aggregations (optional).
|
573
|
-
#
|
574
|
-
# Examples
|
575
|
-
#
|
576
|
-
# Model.scripted_metric(:my_agg, {init_script: '...', map_script: '...', combine_script: '...', reduce_script: '...'})
|
577
|
-
# Model.scripted_metric(:my_agg, {init_script: '...', map_script: '...', combine_script: '...', reduce_script: '...'}, aggs: {...})
|
578
|
-
#
|
579
|
-
# Returns a new Stretchy::Relation.
|
580
|
-
def scripted_metric(name, options = {}, *aggs)
|
581
|
-
options = {scripted_metric: options}.merge(*aggs)
|
582
|
-
aggregation(name, options)
|
583
|
-
end
|
584
|
-
|
585
|
-
# Public: Perform a significant_terms aggregation.
|
586
|
-
#
|
587
|
-
# name - The Symbol or String name of the aggregation.
|
588
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
589
|
-
# :field - The field to use for the significant_terms aggregation.
|
590
|
-
# :background_filter - The background filter to use for the significant_terms aggregation.
|
591
|
-
# :mutual_information - The mutual information to use for the significant_terms aggregation.
|
592
|
-
# :chi_square - The chi square to use for the significant_terms aggregation.
|
593
|
-
# :gnd - The gnd to use for the significant_terms aggregation.
|
594
|
-
# :jlh - The jlh to use for the significant_terms aggregation.
|
595
|
-
# aggs - The Array of additional nested aggregations (optional).
|
596
|
-
#
|
597
|
-
# Examples
|
598
|
-
#
|
599
|
-
# Model.significant_terms(:my_agg, {field: 'field_name'})
|
600
|
-
# Model.significant_terms(:my_agg, {field: 'field_name'}, aggs: {...})
|
601
|
-
#
|
602
|
-
# Returns a new Stretchy::Relation.
|
603
|
-
def significant_terms(name, options = {}, *aggs)
|
604
|
-
options = {significant_terms: options}.merge(*aggs)
|
605
|
-
aggregation(name, options)
|
606
|
-
end
|
607
|
-
|
608
|
-
# Public: Perform a stats aggregation.
|
609
|
-
#
|
610
|
-
# name - The Symbol or String name of the aggregation.
|
611
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
612
|
-
# :field - The field to use for the stats aggregation.
|
613
|
-
# :missing - The missing to use for the stats aggregation.
|
614
|
-
# :script - The script to use for the stats aggregation.
|
615
|
-
# aggs - The Array of additional nested aggregations (optional).
|
616
|
-
#
|
617
|
-
# Examples
|
618
|
-
#
|
619
|
-
# Model.stats(:my_agg, {field: 'field_name'})
|
620
|
-
# Model.stats(:my_agg, {field: 'field_name'}, aggs: {...})
|
621
|
-
#
|
622
|
-
# Returns a new Stretchy::Relation.
|
623
|
-
def stats(name, options = {}, *aggs)
|
624
|
-
options = {stats: options}.merge(*aggs)
|
625
|
-
aggregation(name, options)
|
626
|
-
end
|
627
|
-
|
628
|
-
# Public: Perform a sum aggregation.
|
629
|
-
#
|
630
|
-
# name - The Symbol or String name of the aggregation.
|
631
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
632
|
-
# :field - The field to use for the sum aggregation.
|
633
|
-
# :missing - The missing to use for the sum aggregation.
|
634
|
-
# :script - The script to use for the sum aggregation.
|
635
|
-
# aggs - The Array of additional nested aggregations (optional).
|
636
|
-
#
|
637
|
-
# Examples
|
638
|
-
#
|
639
|
-
# Model.sum(:my_agg, {field: 'field_name'})
|
640
|
-
# Model.sum(:my_agg, {field: 'field_name'}, aggs: {...})
|
641
|
-
#
|
642
|
-
# Returns a new Stretchy::Relation.
|
643
|
-
def sum(name, options = {}, *aggs)
|
644
|
-
options = {sum: options}.merge(*aggs)
|
645
|
-
aggregation(name, options)
|
646
|
-
end
|
647
|
-
|
648
|
-
# Public: Perform a terms aggregation.
|
649
|
-
#
|
650
|
-
# name - The Symbol or String name of the aggregation.
|
651
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
652
|
-
# :field - The field to use for the terms aggregation.
|
653
|
-
# :size - The size for the terms aggregation. (optional)
|
654
|
-
# :min_doc_count - The minimum document count for the terms aggregation. (optional)
|
655
|
-
# :shard_min_doc_count - The shard minimum document count for the terms aggregation. (optional)
|
656
|
-
# :show_term_doc_count_error - The show_term_doc_count_error for the terms aggregation. (optional) default: false
|
657
|
-
# :shard_size - The shard size for the terms aggregation. (optional)
|
658
|
-
# :order - The order for the terms aggregation. (optional)
|
659
|
-
#
|
660
|
-
# aggs - The Array of additional nested aggregations (optional).
|
661
|
-
#
|
662
|
-
# Examples
|
663
|
-
#
|
664
|
-
# Model.terms(:my_agg, {field: 'field_name', size: 10, min_doc_count: 1, shard_size: 100})
|
665
|
-
# Model.terms(:my_agg, {field: 'field_name', size: 10, min_doc_count: 1, shard_size: 100}, aggs: {...})
|
666
|
-
#
|
667
|
-
# Returns a new Stretchy::Relation.
|
668
|
-
def terms(name, options = {}, *aggs)
|
669
|
-
options = {terms: options}.merge(*aggs)
|
670
|
-
aggregation(name, options)
|
671
|
-
end
|
672
|
-
|
673
|
-
|
674
|
-
# Public: Perform a top_hits aggregation.
|
675
|
-
#
|
676
|
-
# name - The Symbol or String name of the aggregation.
|
677
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
678
|
-
# :size - The size for the top_hits aggregation.
|
679
|
-
# :from - The from for the top_hits aggregation.
|
680
|
-
# :sort - The sort for the top_hits aggregation.
|
681
|
-
# aggs - The Array of additional nested aggregations (optional).
|
682
|
-
#
|
683
|
-
# Examples
|
684
|
-
#
|
685
|
-
# Model.top_hits(:my_agg, {size: 10, sort: {...}})
|
686
|
-
# Model.top_hits(:my_agg, {size: 10, sort: {...}}, aggs: {...})
|
687
|
-
#
|
688
|
-
# Returns a new Stretchy::Relation.
|
689
|
-
def top_hits(name, options = {}, *aggs)
|
690
|
-
options = {top_hits: options}.merge(*aggs)
|
691
|
-
aggregation(name, options)
|
692
|
-
end
|
693
|
-
|
694
|
-
# Public: Perform a top_metrics aggregation.
|
695
|
-
#
|
696
|
-
# name - The Symbol or String name of the aggregation.
|
697
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
698
|
-
# :metrics - The metrics to use for the top_metrics aggregation. metrics: [{field: 'field_name', type: 'max'}, {field: 'field_name', type: 'min']
|
699
|
-
# :field - The field to use for the top_metrics aggregation. (optional)
|
700
|
-
# :size - The size for the top_metrics aggregation. (optional)
|
701
|
-
# :sort - The sort for the top_metrics aggregation. (optional)
|
702
|
-
# :missing - The missing for the top_metrics aggregation. (optional)
|
703
|
-
# aggs - The Array of additional nested aggregations (optional).
|
704
|
-
#
|
705
|
-
# Examples
|
706
|
-
#
|
707
|
-
# Model.top_metrics(:my_agg, {metrics: ['metric1', 'metric2']})
|
708
|
-
# Model.top_metrics(:my_agg, {metrics: ['metric1', 'metric2']}, aggs: {...})
|
709
|
-
#
|
710
|
-
# Returns a new Stretchy::Relation.
|
711
|
-
def top_metrics(name, options = {}, *aggs)
|
712
|
-
options = {top_metrics: options}.merge(*aggs)
|
713
|
-
aggregation(name, options)
|
714
|
-
end
|
715
|
-
|
716
|
-
# Public: Perform a value_count aggregation.
|
717
|
-
#
|
718
|
-
# name - The Symbol or String name of the aggregation.
|
719
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
720
|
-
# :field - The field to use for the value_count aggregation.
|
721
|
-
# :script - The script to use for the value_count aggregation. (optional) script: {source: "doc['field_name'].value", lang: "painless"}
|
722
|
-
# aggs - The Array of additional nested aggregations (optional).
|
723
|
-
#
|
724
|
-
# Examples
|
725
|
-
#
|
726
|
-
# Model.value_count(:my_agg, {field: 'field_name'})
|
727
|
-
# Model.value_count(:my_agg, {field: 'field_name'}, aggs: {...})
|
728
|
-
#
|
729
|
-
# Returns a new Stretchy::Relation.
|
730
|
-
def value_count(name, options = {}, *aggs)
|
731
|
-
options = {value_count: options}.merge(*aggs)
|
732
|
-
aggregation(name, options)
|
733
|
-
end
|
734
|
-
|
735
|
-
# Public: Perform a weighted_avg aggregation.
|
736
|
-
#
|
737
|
-
# name - The Symbol or String name of the aggregation.
|
738
|
-
# options - The Hash options used to refine the aggregation (default: {}):
|
739
|
-
# :value - The value field to use for the weighted_avg aggregation. {value: { field: 'price', missing: 0}}
|
740
|
-
# :weight - The weight field to use for the weighted_avg aggregation. {weight: { field: 'weight', missing: 0}}
|
741
|
-
# :format - The format for the weighted_avg aggregation. (optional)
|
742
|
-
# aggs - The Array of additional nested aggregations (optional).
|
743
|
-
#
|
744
|
-
# Examples
|
745
|
-
#
|
746
|
-
# Model.weighted_avg(:my_agg, {value_field: 'value_field_name', weight_field: 'weight_field_name'})
|
747
|
-
# Model.weighted_avg(:my_agg, {value_field: 'value_field_name', weight_field: 'weight_field_name'}, aggs: {...})
|
748
|
-
#
|
749
|
-
# Returns a new Stretchy::Relation.
|
750
|
-
def weighted_avg(name, options = {}, *aggs)
|
751
|
-
options = {weighted_avg: options}.merge(*aggs)
|
752
|
-
aggregation(name, options)
|
5
|
+
@_registry = []
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# Define the register! method
|
9
|
+
def register!(*methods)
|
10
|
+
@_registry += methods
|
11
|
+
end
|
12
|
+
|
13
|
+
# Define a method to access the registry
|
14
|
+
def registry
|
15
|
+
@_registry.flatten.compact.uniq
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Load all the aggregation methods
|
20
|
+
Dir["#{File.dirname(__FILE__)}/aggregation_methods/*.rb"].each do |file|
|
21
|
+
basename = File.basename(file, '.rb')
|
22
|
+
module_name = basename.split('_').collect(&:capitalize).join
|
23
|
+
mod = const_get(module_name)
|
24
|
+
include mod
|
753
25
|
end
|
754
|
-
|
755
26
|
|
756
27
|
end
|
757
28
|
end
|