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,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Nested
|
5
|
+
# Perform a nested aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a nested aggregation, which allows you to aggregate nested documents as if they were indexed as separate documents. 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
|
+
# - `:path:` The String representing the path to use for the nested aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified nested aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Nested aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.nested(:my_agg, {path: 'path_to_field'})
|
27
|
+
# Model.nested(:my_agg, {path: 'path_to_field'}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def nested(name, options = {}, *aggs)
|
31
|
+
options = {nested: options}.merge(*aggs)
|
32
|
+
aggregation(name, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
AggregationMethods.register!(:nested)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module PercentileRanks
|
5
|
+
# Perform a percentile_ranks aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a percentile_ranks aggregation, which allows you to calculate the percentile rank for each value in a set of values. 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 percentile_ranks aggregation.
|
14
|
+
# - `:values:` The Array of values to use for the percentile_ranks aggregation.
|
15
|
+
# - `:keyed:` The Boolean that associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Default is true.
|
16
|
+
# - `:script:` The Hash representing the script to use for the percentile_ranks aggregation. Example: script: {source: "doc['field_name'].value", lang: "painless"}
|
17
|
+
# - `:hdr:` The Hash representing the hdr to use for the percentile_ranks aggregation. Example: hdr: {number_of_significant_value_digits: 3}
|
18
|
+
# - `:missing:` The value to use for the percentile_ranks aggregation when a field is missing in a document. Example: missing: 10
|
19
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
20
|
+
#
|
21
|
+
# ### Returns
|
22
|
+
# Returns a new Stretchy::Relation with the specified percentile_ranks aggregation.
|
23
|
+
#
|
24
|
+
# ---
|
25
|
+
#
|
26
|
+
# ### Examples
|
27
|
+
#
|
28
|
+
# #### Percentile_ranks aggregation
|
29
|
+
#
|
30
|
+
# ```ruby
|
31
|
+
# Model.percentile_ranks(:my_agg, {field: 'field_name', values: [1, 2, 3]})
|
32
|
+
# Model.percentile_ranks(:my_agg, {field: 'field_name', values: [1, 2, 3]}, aggs: {...})
|
33
|
+
# ```
|
34
|
+
#
|
35
|
+
def percentile_ranks(name, options = {}, *aggs)
|
36
|
+
options = {percentile_ranks: options}.merge(*aggs)
|
37
|
+
aggregation(name, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
AggregationMethods.register!(:percentile_ranks)
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Percentiles
|
5
|
+
# Perform a percentiles aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a percentiles aggregation, which allows you to calculate the percentiles of a set of values. 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 percentiles aggregation.
|
14
|
+
# - `:percents:` The Array of Floats representing the percentiles to calculate for the percentiles aggregation. Example: percents: [95, 99, 99.9]
|
15
|
+
# - `:keyed:` The Boolean that associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Default is true.
|
16
|
+
# - `:tdigest:` The Hash representing the tdigest to use for the percentiles aggregation. Example: tdigest: {compression: 100, execution_hint: "high_accuracy"}
|
17
|
+
# - `:compression:` The Float representing 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.
|
18
|
+
# - `:execution_hint:` The String representing the execution_hint to use for the t-digest algorithm. Example: execution_hint: "auto"
|
19
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
20
|
+
#
|
21
|
+
# ### Returns
|
22
|
+
# Returns a new Stretchy::Relation with the specified percentiles aggregation.
|
23
|
+
#
|
24
|
+
# ---
|
25
|
+
#
|
26
|
+
# ### Examples
|
27
|
+
#
|
28
|
+
# #### Percentiles aggregation
|
29
|
+
#
|
30
|
+
# ```ruby
|
31
|
+
# Model.percentiles(:my_agg, {field: 'field_name', percents: [1, 2, 3]})
|
32
|
+
# Model.percentiles(:my_agg, {field: 'field_name', percents: [1, 2, 3]}, aggs: {...})
|
33
|
+
# ```
|
34
|
+
#
|
35
|
+
def percentiles(name, options = {}, *aggs)
|
36
|
+
options = {percentiles: options}.merge(*aggs)
|
37
|
+
aggregation(name, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
AggregationMethods.register!(:percentiles)
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Range
|
5
|
+
# Perform a range aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a range aggregation, which allows you to aggregate data into specified 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 range aggregation.
|
14
|
+
# - `:ranges:` The Array of Hashes representing the ranges to use for the range aggregation. Example: ranges: [{from: 1, to: 2}, {from: 2, to: 3}]
|
15
|
+
# - `:keyed:` The Boolean that associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Default is true.
|
16
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
17
|
+
#
|
18
|
+
# ### Returns
|
19
|
+
# Returns a new Stretchy::Relation with the specified range aggregation.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
#
|
23
|
+
# ### Examples
|
24
|
+
#
|
25
|
+
# #### Range aggregation
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# Model.range(:my_agg, {field: 'field_name', ranges: [{from: 1, to: 2}, {from: 2, to: 3}]})
|
29
|
+
# Model.range(:my_agg, {field: 'field_name', ranges: [{from: 1, to: 2}, {from: 2, to: 3}]}, aggs: {...})
|
30
|
+
# ```
|
31
|
+
#
|
32
|
+
def range(name, options = {}, *aggs)
|
33
|
+
options = {range: options}.merge(*aggs)
|
34
|
+
aggregation(name, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
AggregationMethods.register!(:range)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module ReverseNested
|
5
|
+
# Perform a reverse_nested aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a reverse_nested aggregation, which allows you to access data in the parent document from within a nested document. 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
|
+
# - `:path:` The String representing the path to use for the reverse_nested aggregation (optional).
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified reverse_nested aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Reverse_nested aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.reverse_nested(:my_agg)
|
27
|
+
# Model.reverse_nested(:my_agg, {}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def reverse_nested(name, options = {}, *aggs)
|
31
|
+
options = {reverse_nested: options}.merge(*aggs)
|
32
|
+
aggregation(name, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
AggregationMethods.register!(:reverse_nested)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Sampler
|
5
|
+
# Perform a sampler aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a sampler aggregation, which allows you to create a representative sample of a larger 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
|
+
# - `:shard_size:` The Integer representing the shard size to use for the sampler aggregation.
|
14
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
15
|
+
#
|
16
|
+
# ### Returns
|
17
|
+
# Returns a new Stretchy::Relation with the specified sampler aggregation.
|
18
|
+
#
|
19
|
+
# ---
|
20
|
+
#
|
21
|
+
# ### Examples
|
22
|
+
#
|
23
|
+
# #### Sampler aggregation
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# Model.sampler(:my_agg, {shard_size: 100})
|
27
|
+
# Model.sampler(:my_agg, {shard_size: 100}, aggs: {...})
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def sampler(name, options = {}, *aggs)
|
31
|
+
options = {sampler: options}.merge(*aggs)
|
32
|
+
aggregation(name, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
AggregationMethods.register!(:sampler)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module ScriptedMetric
|
5
|
+
# Perform a scripted_metric aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a scripted_metric aggregation, which allows you to define your own aggregations using scripts. 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
|
+
# - `:init_script:` The String representing the initialization script for the scripted_metric aggregation.
|
14
|
+
# - `:map_script:` The String representing the map script for the scripted_metric aggregation.
|
15
|
+
# - `:combine_script:` The String representing the combine script for the scripted_metric aggregation.
|
16
|
+
# - `:reduce_script:` The String representing the reduce script for the scripted_metric aggregation.
|
17
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
18
|
+
#
|
19
|
+
# ### Returns
|
20
|
+
# Returns a new Stretchy::Relation with the specified scripted_metric aggregation.
|
21
|
+
#
|
22
|
+
# ---
|
23
|
+
#
|
24
|
+
# ### Examples
|
25
|
+
#
|
26
|
+
# #### Scripted_metric aggregation
|
27
|
+
#
|
28
|
+
# ```ruby
|
29
|
+
# Model.scripted_metric(:my_agg, {init_script: '...', map_script: '...', combine_script: '...', reduce_script: '...'})
|
30
|
+
# Model.scripted_metric(:my_agg, {init_script: '...', map_script: '...', combine_script: '...', reduce_script: '...'}, aggs: {...})
|
31
|
+
# ```
|
32
|
+
#
|
33
|
+
def scripted_metric(name, options = {}, *aggs)
|
34
|
+
options = {scripted_metric: options}.merge(*aggs)
|
35
|
+
aggregation(name, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
AggregationMethods.register!(:scripted_metric)
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module SignificantTerms
|
5
|
+
# Perform a significant_terms aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a significant_terms aggregation, which allows you to find the terms that are unusually common in your data set compared to a background 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 significant_terms aggregation.
|
14
|
+
# - `:background_filter:` The Hash representing the background filter to use for the significant_terms aggregation.
|
15
|
+
# - `:mutual_information:` The Hash representing the mutual information to use for the significant_terms aggregation.
|
16
|
+
# - `:chi_square:` The Hash representing the chi square to use for the significant_terms aggregation.
|
17
|
+
# - `:gnd:` The Hash representing the gnd to use for the significant_terms aggregation.
|
18
|
+
# - `:jlh:` The Hash representing the jlh to use for the significant_terms aggregation.
|
19
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
20
|
+
#
|
21
|
+
# ### Returns
|
22
|
+
# Returns a new Stretchy::Relation with the specified significant_terms aggregation.
|
23
|
+
#
|
24
|
+
# ---
|
25
|
+
#
|
26
|
+
# ### Examples
|
27
|
+
#
|
28
|
+
# #### Significant_terms aggregation
|
29
|
+
#
|
30
|
+
# ```ruby
|
31
|
+
# Model.significant_terms(:my_agg, {field: 'field_name'})
|
32
|
+
# Model.significant_terms(:my_agg, {field: 'field_name'}, aggs: {...})
|
33
|
+
# ```
|
34
|
+
#
|
35
|
+
def significant_terms(name, options = {}, *aggs)
|
36
|
+
options = {significant_terms: options}.merge(*aggs)
|
37
|
+
aggregation(name, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
AggregationMethods.register!(:significant_terms)
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Stats
|
5
|
+
# Perform a stats aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a stats aggregation, which allows you to compute aggregate statistics over your data set, such as count, min, max, sum, and average. 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 stats aggregation.
|
14
|
+
# - `:missing:` The value to use for the stats aggregation when a field is missing in a document. Example: missing: 10
|
15
|
+
# - `:script:` The Hash representing the script to use for the stats aggregation. Example: script: {source: "doc['field_name'].value", lang: "painless"}
|
16
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
17
|
+
#
|
18
|
+
# ### Returns
|
19
|
+
# Returns a new Stretchy::Relation with the specified stats aggregation.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
#
|
23
|
+
# ### Examples
|
24
|
+
#
|
25
|
+
# #### Stats aggregation
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# Model.stats(:my_agg, {field: 'field_name'})
|
29
|
+
# Model.stats(:my_agg, {field: 'field_name'}, aggs: {...})
|
30
|
+
# ```
|
31
|
+
#
|
32
|
+
def stats(name, options = {}, *aggs)
|
33
|
+
options = {stats: options}.merge(*aggs)
|
34
|
+
aggregation(name, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
AggregationMethods.register!(:stats)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Sum
|
5
|
+
# Perform a sum aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a sum aggregation, which allows you to compute the sum of a numeric 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 sum aggregation.
|
14
|
+
# - `:missing:` The value to use for the sum aggregation when a field is missing in a document. Example: missing: 10
|
15
|
+
# - `:script:` The Hash representing the script to use for the sum aggregation. Example: script: {source: "doc['field_name'].value", lang: "painless"}
|
16
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
17
|
+
#
|
18
|
+
# ### Returns
|
19
|
+
# Returns a new Stretchy::Relation with the specified sum aggregation.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
#
|
23
|
+
# ### Examples
|
24
|
+
#
|
25
|
+
# #### Sum aggregation
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# Model.sum(:my_agg, {field: 'field_name'})
|
29
|
+
# Model.sum(:my_agg, {field: 'field_name'}, aggs: {...})
|
30
|
+
# ```
|
31
|
+
#
|
32
|
+
def sum(name, options = {}, *aggs)
|
33
|
+
options = {sum: options}.merge(*aggs)
|
34
|
+
aggregation(name, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
AggregationMethods.register!(:sum)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module Terms
|
5
|
+
# Perform a terms aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a terms aggregation, which allows you to compute the frequency of different terms within a 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 terms aggregation.
|
14
|
+
# - `:size:` The Integer representing the size for the terms aggregation (optional).
|
15
|
+
# - `:min_doc_count:` The Integer representing the minimum document count for the terms aggregation (optional).
|
16
|
+
# - `:shard_min_doc_count:` The Integer representing the shard minimum document count for the terms aggregation (optional).
|
17
|
+
# - `:show_term_doc_count_error:` The Boolean representing the show_term_doc_count_error for the terms aggregation (optional). Default is false.
|
18
|
+
# - `:shard_size:` The Integer representing the shard size for the terms aggregation (optional).
|
19
|
+
# - `:order:` The Hash representing the order for the terms aggregation (optional).
|
20
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
21
|
+
#
|
22
|
+
# ### Returns
|
23
|
+
# Returns a new Stretchy::Relation with the specified terms aggregation.
|
24
|
+
#
|
25
|
+
# ---
|
26
|
+
#
|
27
|
+
# ### Examples
|
28
|
+
#
|
29
|
+
# #### Terms aggregation
|
30
|
+
#
|
31
|
+
# ```ruby
|
32
|
+
# Model.terms(:my_agg, {field: 'field_name', size: 10, min_doc_count: 1, shard_size: 100})
|
33
|
+
# Model.terms(:my_agg, {field: 'field_name', size: 10, min_doc_count: 1, shard_size: 100}, aggs: {...})
|
34
|
+
# ```
|
35
|
+
#
|
36
|
+
def terms(name, options = {}, *aggs)
|
37
|
+
options = {terms: options}.merge(*aggs)
|
38
|
+
aggregation(name, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
AggregationMethods.register!(:terms)
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module TopHits
|
5
|
+
# Perform a top_hits aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a top_hits aggregation, which allows you to return the top matching hits for each bucket of a parent aggregation. 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
|
+
# - `:size:` The Integer representing the size for the top_hits aggregation.
|
14
|
+
# - `:from:` The Integer representing the from for the top_hits aggregation.
|
15
|
+
# - `:sort:` The Hash or Array representing the sort for the top_hits aggregation.
|
16
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
17
|
+
#
|
18
|
+
# ### Returns
|
19
|
+
# Returns a new Stretchy::Relation with the specified top_hits aggregation.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
#
|
23
|
+
# ### Examples
|
24
|
+
#
|
25
|
+
# #### Top_hits aggregation
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# Model.top_hits(:my_agg, {size: 10, sort: {...}})
|
29
|
+
# Model.top_hits(:my_agg, {size: 10, sort: {...}}, aggs: {...})
|
30
|
+
# ```
|
31
|
+
#
|
32
|
+
def top_hits(name, options = {}, *aggs)
|
33
|
+
options = {top_hits: options}.merge(*aggs)
|
34
|
+
aggregation(name, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
AggregationMethods.register!(:top_hits)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module TopMetrics
|
5
|
+
# Perform a top_metrics aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a top_metrics aggregation, which allows you to return the top metrics for each bucket of a parent aggregation. 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
|
+
# - `:metrics:` The Array of Hashes representing the metrics to use for the top_metrics aggregation. Example: metrics: [{field: 'field_name', type: 'max'}, {field: 'field_name', type: 'min'}]
|
14
|
+
# - `:field:` The String representing the field to use for the top_metrics aggregation (optional).
|
15
|
+
# - `:size:` The Integer representing the size for the top_metrics aggregation (optional).
|
16
|
+
# - `:sort:` The Hash or Array representing the sort for the top_metrics aggregation (optional).
|
17
|
+
# - `:missing:` The value to use for the top_metrics aggregation when a field is missing in a document (optional).
|
18
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
19
|
+
#
|
20
|
+
# ### Returns
|
21
|
+
# Returns a new Stretchy::Relation with the specified top_metrics aggregation.
|
22
|
+
#
|
23
|
+
# ---
|
24
|
+
#
|
25
|
+
# ### Examples
|
26
|
+
#
|
27
|
+
# #### Top_metrics aggregation
|
28
|
+
#
|
29
|
+
# ```ruby
|
30
|
+
# Model.top_metrics(:my_agg, {metrics: [{field: 'field_name', type: 'max'}, {field: 'field_name', type: 'min'}]})
|
31
|
+
# Model.top_metrics(:my_agg, {metrics: [{field: 'field_name', type: 'max'}, {field: 'field_name', type: 'min'}]}, aggs: {...})
|
32
|
+
# ```
|
33
|
+
#
|
34
|
+
def top_metrics(name, options = {}, *aggs)
|
35
|
+
options = {top_metrics: options}.merge(*aggs)
|
36
|
+
aggregation(name, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
AggregationMethods.register!(:top_metrics)
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module ValueCount
|
5
|
+
# Perform a value_count aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a value_count aggregation, which allows you to compute the count of values for a specific 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 value_count aggregation.
|
14
|
+
# - `:script:` The Hash representing the script to use for the value_count aggregation. Example: script: {source: "doc['field_name'].value", lang: "painless"}
|
15
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
16
|
+
#
|
17
|
+
# ### Returns
|
18
|
+
# Returns a new Stretchy::Relation with the specified value_count aggregation.
|
19
|
+
#
|
20
|
+
# ---
|
21
|
+
#
|
22
|
+
# ### Examples
|
23
|
+
#
|
24
|
+
# #### Value_count aggregation
|
25
|
+
#
|
26
|
+
# ```ruby
|
27
|
+
# Model.value_count(:my_agg, {field: 'field_name'})
|
28
|
+
# Model.value_count(:my_agg, {field: 'field_name'}, aggs: {...})
|
29
|
+
# ```
|
30
|
+
#
|
31
|
+
def value_count(name, options = {}, *aggs)
|
32
|
+
options = {value_count: options}.merge(*aggs)
|
33
|
+
aggregation(name, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
AggregationMethods.register!(:value_count)
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module AggregationMethods
|
4
|
+
module WeightedAvg
|
5
|
+
# Perform a weighted_avg aggregation.
|
6
|
+
#
|
7
|
+
# This method is used to perform a weighted_avg aggregation, which allows you to compute a weighted average of a specified 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
|
+
# - `:value:` The Hash representing the value field to use for the weighted_avg aggregation. Example: value: { field: 'price', missing: 0}
|
14
|
+
# - `:weight:` The Hash representing the weight field to use for the weighted_avg aggregation. Example: weight: { field: 'weight', missing: 0}
|
15
|
+
# - `:format:` The String representing the format for the weighted_avg aggregation (optional).
|
16
|
+
# - `aggs:` The Array of Hashes representing nested aggregations (optional).
|
17
|
+
#
|
18
|
+
# ### Returns
|
19
|
+
# Returns a new Stretchy::Relation with the specified weighted_avg aggregation.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
#
|
23
|
+
# ### Examples
|
24
|
+
#
|
25
|
+
# #### Weighted_avg aggregation
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# Model.weighted_avg(:my_agg, {value: {field: 'value_field_name'}, weight: {field: 'weight_field_name'}})
|
29
|
+
# Model.weighted_avg(:my_agg, {value: {field: 'value_field_name'}, weight: {field: 'weight_field_name'}}, aggs: {...})
|
30
|
+
# ```
|
31
|
+
#
|
32
|
+
def weighted_avg(name, options = {}, *aggs)
|
33
|
+
options = {weighted_avg: options}.merge(*aggs)
|
34
|
+
aggregation(name, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
AggregationMethods.register!(:weighted_avg)
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|