stretchy-model 0.6.5 → 0.6.6
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 +14 -0
- data/docs/examples/_sidebar.md +15 -0
- data/docs/examples/data_analysis.md +216 -0
- data/docs/examples/semantic_search_with_llm.md +83 -0
- data/docs/examples/simple-ingest-pipeline.md +326 -0
- data/docs/guides/_sidebar.md +14 -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/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/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/pipeline.rb +2 -1
- data/lib/stretchy/pipelines/processor.rb +38 -36
- data/lib/stretchy/querying.rb +7 -8
- 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 +17 -10
- metadata +111 -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
@@ -0,0 +1,47 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Children
|
5
|
+
# Perform a children aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to aggregate on child documents of the parent documents that match the query. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:type:` The String representing the type of children to aggregate.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified children aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Children aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.children(:my_agg, {type: 'my_type'})
|
27
|
+
# Model.children(:my_agg, {type: 'my_type'}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
# Aggregation results are available in the `aggregations` method of the results under the name provided in the aggregation.
|
31
|
+
#
|
32
|
+
# ```ruby
|
33
|
+
# results = Model.where(color: :blue).children(:my_agg, {type: 'my_type'})
|
34
|
+
# results.aggregations.my_agg
|
35
|
+
# ```
|
36
|
+
#
|
37
|
+
def children(name, options = {}, *aggs)
|
38
|
+
options = {children: options}.merge(*aggs)
|
39
|
+
aggregation(name, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
AggregationMethods.register!(:children)
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Composite
|
5
|
+
# Perform a composite aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a composite aggregation, which allows you to collect terms or histogram aggregations on high cardinality fields. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:sources:` The Array representing the sources to use for the composite aggregation.
|
14
|
+
# - `:size:` The Integer representing the size of the composite aggregation.
|
15
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
16
|
+
#
|
17
|
+
# ### Returns
|
18
|
+
# Returns a new Stretchy::Relation with the specified composite aggregation.
|
19
|
+
#
|
20
|
+
# ---
|
21
|
+
#
|
22
|
+
# ### Examples
|
23
|
+
#
|
24
|
+
# #### Composite aggregation
|
25
|
+
#
|
26
|
+
# ```ruby
|
27
|
+
# Model.composite(:my_agg, {sources: [...], size: 100})
|
28
|
+
# Model.composite(:my_agg, {sources: [...], size: 100}, aggs: {...})
|
29
|
+
# ```
|
30
|
+
#
|
31
|
+
def composite(name, options = {}, *aggs)
|
32
|
+
options = {composite: options}.merge(*aggs)
|
33
|
+
aggregation(name, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
AggregationMethods.register!(:composite)
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module DateHistogram
|
5
|
+
# Perform a date_histogram aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a date_histogram aggregation, which allows you to aggregate time-based data by a certain interval. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the date_histogram aggregation.
|
14
|
+
# - `:interval:` The String representing the interval for the date_histogram aggregation.
|
15
|
+
# - `:calendar_interval:` The Symbol representing the calendar interval for the date_histogram aggregation.
|
16
|
+
# - `:format:` The String representing the format for the date_histogram aggregation.
|
17
|
+
# - `:time_zone:` The String representing the time zone for the date_histogram aggregation.
|
18
|
+
# - `:min_doc_count:` The Integer representing the minimum document count for the date_histogram aggregation.
|
19
|
+
# - `:extended_bounds:` The Hash representing the extended bounds for the date_histogram aggregation.
|
20
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
21
|
+
#
|
22
|
+
# ### Returns
|
23
|
+
# Returns a new Stretchy::Relation with the specified date_histogram aggregation.
|
24
|
+
#
|
25
|
+
# ---
|
26
|
+
#
|
27
|
+
# ### Examples
|
28
|
+
#
|
29
|
+
# #### Date_histogram aggregation
|
30
|
+
#
|
31
|
+
# ```ruby
|
32
|
+
# Model.date_histogram(:my_agg, {field: 'date', interval: 'month', format: 'MM-yyyy', time_zone: 'UTC'})
|
33
|
+
# Model.date_histogram(:my_agg, {field: 'date', calendar_interval: :month, format: 'MM-yyyy', time_zone: 'UTC'}, aggs: {...})
|
34
|
+
# ```
|
35
|
+
#
|
36
|
+
# Aggregation results are available in the `aggregations` method of the results under the name provided in the aggregation.
|
37
|
+
#
|
38
|
+
# ```ruby
|
39
|
+
# results = Model.where(color: :blue).date_histogram(:my_agg, {field: 'date', interval: 'month', format: 'MM-yyyy', time_zone: 'UTC'})
|
40
|
+
# results.aggregations.my_agg
|
41
|
+
# ```
|
42
|
+
#
|
43
|
+
def date_histogram(name, options = {}, *aggs)
|
44
|
+
options = {date_histogram: options}.merge(*aggs)
|
45
|
+
aggregation(name, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
AggregationMethods.register!(:date_histogram)
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module DateRange
|
5
|
+
# Perform a date_histogram aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a date_histogram aggregation, which allows you to aggregate time-based data by a certain interval. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the date_histogram aggregation.
|
14
|
+
# - `:interval:` The String representing the interval for the date_histogram aggregation.
|
15
|
+
# - `:calendar_interval:` The Symbol representing the calendar interval for the date_histogram aggregation.
|
16
|
+
# - `:format:` The String representing the format for the date_histogram aggregation.
|
17
|
+
# - `:time_zone:` The String representing the time zone for the date_histogram aggregation.
|
18
|
+
# - `:min_doc_count:` The Integer representing the minimum document count for the date_histogram aggregation.
|
19
|
+
# - `:extended_bounds:` The Hash representing the extended bounds for the date_histogram aggregation.
|
20
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
21
|
+
#
|
22
|
+
# ### Returns
|
23
|
+
# Returns a new Stretchy::Relation with the specified date_histogram aggregation.
|
24
|
+
#
|
25
|
+
# ---
|
26
|
+
#
|
27
|
+
# ### Examples
|
28
|
+
#
|
29
|
+
# #### Date_histogram aggregation
|
30
|
+
#
|
31
|
+
# ```ruby
|
32
|
+
# Model.date_histogram(:my_agg, {field: 'date', interval: 'month', format: 'MM-yyyy', time_zone: 'UTC'})
|
33
|
+
# Model.date_histogram(:my_agg, {field: 'date', calendar_interval: :month, format: 'MM-yyyy', time_zone: 'UTC'}, aggs: {...})
|
34
|
+
# ```
|
35
|
+
#
|
36
|
+
# Aggregation results are available in the `aggregations` method of the results under the name provided in the aggregation.
|
37
|
+
#
|
38
|
+
# ```ruby
|
39
|
+
# results = Model.where(color: :blue).date_histogram(:my_agg, {field: 'date', interval: 'month', format: 'MM-yyyy', time_zone: 'UTC'})
|
40
|
+
# results.aggregations.my_agg
|
41
|
+
# ```
|
42
|
+
#
|
43
|
+
def date_range(name, options = {}, *aggs)
|
44
|
+
options = {date_range: options}.merge(*aggs)
|
45
|
+
aggregation(name, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
AggregationMethods.register!(:date_range)
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module ExtendedStats
|
5
|
+
# Perform an extended_stats aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform an extended_stats aggregation, which allows you to compute several statistical measures from your data. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the extended_stats aggregation.
|
14
|
+
# - `:sigma:` The Float representing the sigma for the extended_stats aggregation.
|
15
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
16
|
+
#
|
17
|
+
# ### Returns
|
18
|
+
# Returns a new Stretchy::Relation with the specified extended_stats aggregation.
|
19
|
+
#
|
20
|
+
# ---
|
21
|
+
#
|
22
|
+
# ### Examples
|
23
|
+
#
|
24
|
+
# #### Extended_stats aggregation
|
25
|
+
#
|
26
|
+
# ```ruby
|
27
|
+
# Model.extended_stats(:my_agg, {field: 'field_name', sigma: 1.0})
|
28
|
+
# Model.extended_stats(:my_agg, {field: 'field_name', sigma: 1.0}, aggs: {...})
|
29
|
+
# ```
|
30
|
+
#
|
31
|
+
# Aggregation results are available in the `aggregations` method of the results under the name provided in the aggregation.
|
32
|
+
#
|
33
|
+
# ```ruby
|
34
|
+
# results = Model.where(color: :blue).extended_stats(:my_agg, {field: 'field_name', sigma: 1.0})
|
35
|
+
# results.aggregations.my_agg
|
36
|
+
# ```
|
37
|
+
#
|
38
|
+
def extended_stats(name, options = {}, *aggs)
|
39
|
+
options = {extended_stats: options}.merge(*aggs)
|
40
|
+
aggregation(name, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
AggregationMethods.register!(:extended_stats)
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Filter
|
5
|
+
# Perform a filter aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a filter_agg aggregation, which allows you to filter the data that an aggregation operates on. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:filter:` The Hash representing the filter to use for the filter_agg aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified filter_agg aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Filter_agg aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.filter(:my_agg, {filter: {...}})
|
27
|
+
# Model.filter(:my_agg, {filter: {...}}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
# Aggregation results are available in the `aggregations` method of the results under the name provided in the aggregation.
|
31
|
+
#
|
32
|
+
# ```ruby
|
33
|
+
# results = Model.where(color: :blue).filter(:my_agg, {filter: {...}})
|
34
|
+
# results.aggregations.my_agg
|
35
|
+
# ```
|
36
|
+
#
|
37
|
+
def filter(name, options = {}, *aggs)
|
38
|
+
options = {filter: options}.merge(*aggs)
|
39
|
+
aggregation(name, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
AggregationMethods.register!(:filter)
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Filters
|
5
|
+
# Perform a filters aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a filters aggregation, which allows you to apply several filters and return the document count for each filter. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:filters:` The Hash representing the filters to use for the filters aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified filters aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Filters aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.filters(:my_agg, {filters: {...}})
|
27
|
+
# Model.filters(:my_agg, {filters: {...}}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
# Aggregation results are available in the `aggregations` method of the results under the name provided in the aggregation.
|
31
|
+
#
|
32
|
+
# ```ruby
|
33
|
+
# results = Model.where(color: :blue).filters(:my_agg, {filters: {...}})
|
34
|
+
# results.aggregations.my_agg
|
35
|
+
# ```
|
36
|
+
#
|
37
|
+
def filters(name, options = {}, *aggs)
|
38
|
+
options = {filters: options}.merge(*aggs)
|
39
|
+
aggregation(name, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
AggregationMethods.register!(:filters)
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module GeoBounds
|
5
|
+
# Perform a geo_bounds aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a geo_bounds aggregation, which allows you to find the bounding box containing all geo_point values for a particular field. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the geo_bounds aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified geo_bounds aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Geo_bounds aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.geo_bounds(:my_agg, {field: 'location_field'})
|
27
|
+
# Model.geo_bounds(:my_agg, {field: 'location_field'}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def geo_bounds(name, options = {}, *aggs)
|
31
|
+
options = {geo_bounds: options}.merge(*aggs)
|
32
|
+
aggregation(name, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
AggregationMethods.register!(:geo_bounds)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module GeoCentroid
|
5
|
+
# Perform a geo_centroid aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a geo_centroid aggregation, which allows you to find the central point (centroid) of all geo_point values for a particular field. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the geo_centroid aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified geo_centroid aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Geo_centroid aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.geo_centroid(:my_agg, {field: 'location_field'})
|
27
|
+
# Model.geo_centroid(:my_agg, {field: 'location_field'}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def geo_centroid(name, options = {}, *aggs)
|
31
|
+
options = {geo_centroid: options}.merge(*aggs)
|
32
|
+
aggregation(name, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
AggregationMethods.register!(:geo_centroid)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Global
|
5
|
+
# Perform a global aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a global aggregation, which allows you to count all documents matching a query, regardless of the search scope. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
14
|
+
#
|
15
|
+
# ### Returns
|
16
|
+
# Returns a new Stretchy::Relation with the specified global aggregation.
|
17
|
+
#
|
18
|
+
# ---
|
19
|
+
#
|
20
|
+
# ### Examples
|
21
|
+
#
|
22
|
+
# #### Global aggregation
|
23
|
+
#
|
24
|
+
# ```ruby
|
25
|
+
# Model.global(:my_agg)
|
26
|
+
# Model.global(:my_agg, {}, aggs: {...})
|
27
|
+
# ```
|
28
|
+
#
|
29
|
+
def global(name, options = {}, *aggs)
|
30
|
+
options = {global: options}.merge(*aggs)
|
31
|
+
aggregation(name, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
AggregationMethods.register!(:global)
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Histogram
|
5
|
+
# Perform a histogram aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a histogram aggregation, which allows you to aggregate data into buckets of a certain interval. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the histogram aggregation.
|
14
|
+
# - `:interval:` The Integer representing the interval for the histogram aggregation.
|
15
|
+
# - `:min_doc_count:` The Integer representing the minimum document count for the histogram aggregation.
|
16
|
+
# - `:extended_bounds:` The Hash representing the extended bounds for the histogram aggregation.
|
17
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
18
|
+
#
|
19
|
+
# ### Returns
|
20
|
+
# Returns a new Stretchy::Relation with the specified histogram aggregation.
|
21
|
+
#
|
22
|
+
# ---
|
23
|
+
#
|
24
|
+
# ### Examples
|
25
|
+
#
|
26
|
+
# #### Histogram aggregation
|
27
|
+
#
|
28
|
+
# ```ruby
|
29
|
+
# Model.histogram(:my_agg, {field: 'field_name', interval: 5})
|
30
|
+
# Model.histogram(:my_agg, {field: 'field_name', interval: 5}, aggs: {...})
|
31
|
+
# ```
|
32
|
+
#
|
33
|
+
def histogram(name, options = {}, *aggs)
|
34
|
+
options = {histogram: options}.merge(*aggs)
|
35
|
+
aggregation(name, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
AggregationMethods.register!(:histogram)
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module IpRange
|
5
|
+
# Perform an ip_range aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform an ip_range aggregation, which allows you to aggregate IP values into specified IP ranges. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the ip_range aggregation.
|
14
|
+
# - `:ranges:` The Array of Hashes representing the ranges to use for the ip_range aggregation. Example: ranges: [{to: '10.0.0.5'}, {from: '10.0.0.5'}]
|
15
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
16
|
+
#
|
17
|
+
# ### Returns
|
18
|
+
# Returns a new Stretchy::Relation with the specified ip_range aggregation.
|
19
|
+
#
|
20
|
+
# ---
|
21
|
+
#
|
22
|
+
# ### Examples
|
23
|
+
#
|
24
|
+
# #### Ip_range aggregation
|
25
|
+
#
|
26
|
+
# ```ruby
|
27
|
+
# Model.ip_range(:my_agg, {field: 'ip_field'})
|
28
|
+
# Model.ip_range(:my_agg, {field: 'ip_field'}, aggs: {...})
|
29
|
+
# ```
|
30
|
+
#
|
31
|
+
def ip_range(name, options = {}, *aggs)
|
32
|
+
options = {ip_range: options}.merge(*aggs)
|
33
|
+
aggregation(name, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
AggregationMethods.register!(:ip_range)
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Max
|
5
|
+
# Perform a max aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a max aggregation, which allows you to find the maximum value of a field in the data set. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the max aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified max aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Max aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.max(:my_agg, {field: 'field_name'})
|
27
|
+
# Model.max(:my_agg, {field: 'field_name'}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def max(name, options = {}, *aggs)
|
31
|
+
options = {max: options}.merge(*aggs)
|
32
|
+
aggregation(name, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
AggregationMethods.register!(:max)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Min
|
5
|
+
|
6
|
+
# Perform a min aggregation.
|
7
|
+
#
|
8
|
+
# This method is used to perform a min aggregation, which allows you to find the minimum value of a field in the data set. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
9
|
+
#
|
10
|
+
# ### Parameters
|
11
|
+
#
|
12
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
13
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
14
|
+
# - `:field:` The String representing the field to use for the min aggregation.
|
15
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
16
|
+
#
|
17
|
+
# ### Returns
|
18
|
+
# Returns a new Stretchy::Relation with the specified min aggregation.
|
19
|
+
#
|
20
|
+
# ---
|
21
|
+
#
|
22
|
+
# ### Examples
|
23
|
+
#
|
24
|
+
# #### Min aggregation
|
25
|
+
#
|
26
|
+
# ```ruby
|
27
|
+
# Model.min(:my_agg, {field: 'field_name'})
|
28
|
+
# Model.min(:my_agg, {field: 'field_name'}, aggs: {...})
|
29
|
+
# ```
|
30
|
+
#
|
31
|
+
def min(name, options = {}, *aggs)
|
32
|
+
options = {min: options}.merge(*aggs)
|
33
|
+
aggregation(name, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
AggregationMethods.register!(:min)
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Missing
|
5
|
+
# Perform a missing aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a missing aggregation, which allows you to find all documents where a field is missing or null. It accepts a name for the aggregation, a hash of options for the aggregation, and an optional array of nested aggregations.
|
8
|
+
#
|
9
|
+
# ### Parameters
|
10
|
+
#
|
11
|
+
# - `name:` The Symbol or String representing the name of the aggregation.
|
12
|
+
# - `options:` The Hash representing the options for the aggregation (default: {}).
|
13
|
+
# - `:field:` The String representing the field to use for the missing aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified missing aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Missing aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.missing(:my_agg, {field: 'field_name'})
|
27
|
+
# Model.missing(:my_agg, {field: 'field_name'}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def missing(name, options = {}, *aggs)
|
31
|
+
options = {missing: options}.merge(*aggs)
|
32
|
+
aggregation(name, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
AggregationMethods.register!(:missing)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|