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.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/README.md +28 -10
  4. data/Rakefile +56 -0
  5. data/docs/.nojekyll +0 -0
  6. data/docs/README.md +147 -0
  7. data/docs/_coverpage.md +14 -0
  8. data/docs/_sidebar.md +14 -0
  9. data/docs/examples/_sidebar.md +15 -0
  10. data/docs/examples/data_analysis.md +216 -0
  11. data/docs/examples/semantic_search_with_llm.md +83 -0
  12. data/docs/examples/simple-ingest-pipeline.md +326 -0
  13. data/docs/guides/_sidebar.md +14 -0
  14. data/docs/guides/aggregations.md +142 -0
  15. data/docs/guides/machine-learning.md +154 -0
  16. data/docs/guides/models.md +372 -0
  17. data/docs/guides/pipelines.md +151 -0
  18. data/docs/guides/querying.md +361 -0
  19. data/docs/guides/quick-start.md +72 -0
  20. data/docs/guides/scopes.md +125 -0
  21. data/docs/index.html +113 -0
  22. data/docs/stretchy.cover.png +0 -0
  23. data/docs/stretchy.logo.png +0 -0
  24. data/docs/styles.css +90 -0
  25. data/lib/stretchy/attributes/transformers/keyword_transformer.rb +41 -35
  26. data/lib/stretchy/attributes/type/array.rb +24 -1
  27. data/lib/stretchy/attributes/type/base.rb +6 -2
  28. data/lib/stretchy/attributes/type/binary.rb +24 -17
  29. data/lib/stretchy/attributes/type/boolean.rb +29 -22
  30. data/lib/stretchy/attributes/type/completion.rb +18 -10
  31. data/lib/stretchy/attributes/type/constant_keyword.rb +35 -26
  32. data/lib/stretchy/attributes/type/date_time.rb +28 -17
  33. data/lib/stretchy/attributes/type/dense_vector.rb +46 -49
  34. data/lib/stretchy/attributes/type/flattened.rb +28 -19
  35. data/lib/stretchy/attributes/type/geo_point.rb +21 -12
  36. data/lib/stretchy/attributes/type/geo_shape.rb +21 -12
  37. data/lib/stretchy/attributes/type/hash.rb +24 -10
  38. data/lib/stretchy/attributes/type/histogram.rb +25 -0
  39. data/lib/stretchy/attributes/type/ip.rb +26 -17
  40. data/lib/stretchy/attributes/type/join.rb +16 -7
  41. data/lib/stretchy/attributes/type/keyword.rb +21 -26
  42. data/lib/stretchy/attributes/type/knn_vector.rb +47 -0
  43. data/lib/stretchy/attributes/type/match_only_text.rb +22 -1
  44. data/lib/stretchy/attributes/type/nested.rb +16 -11
  45. data/lib/stretchy/attributes/type/numeric/base.rb +30 -22
  46. data/lib/stretchy/attributes/type/numeric/byte.rb +20 -0
  47. data/lib/stretchy/attributes/type/numeric/double.rb +20 -0
  48. data/lib/stretchy/attributes/type/numeric/float.rb +20 -0
  49. data/lib/stretchy/attributes/type/numeric/half_float.rb +20 -0
  50. data/lib/stretchy/attributes/type/numeric/integer.rb +21 -1
  51. data/lib/stretchy/attributes/type/numeric/long.rb +20 -0
  52. data/lib/stretchy/attributes/type/numeric/scaled_float.rb +16 -7
  53. data/lib/stretchy/attributes/type/numeric/short.rb +20 -0
  54. data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +21 -1
  55. data/lib/stretchy/attributes/type/percolator.rb +16 -4
  56. data/lib/stretchy/attributes/type/point.rb +19 -9
  57. data/lib/stretchy/attributes/type/range/base.rb +24 -1
  58. data/lib/stretchy/attributes/type/range/date_range.rb +21 -5
  59. data/lib/stretchy/attributes/type/range/double_range.rb +20 -4
  60. data/lib/stretchy/attributes/type/range/float_range.rb +21 -5
  61. data/lib/stretchy/attributes/type/range/integer_range.rb +20 -4
  62. data/lib/stretchy/attributes/type/range/ip_range.rb +20 -4
  63. data/lib/stretchy/attributes/type/range/long_range.rb +20 -4
  64. data/lib/stretchy/attributes/type/rank_feature.rb +16 -6
  65. data/lib/stretchy/attributes/type/rank_features.rb +16 -9
  66. data/lib/stretchy/attributes/type/search_as_you_type.rb +28 -18
  67. data/lib/stretchy/attributes/type/shape.rb +19 -9
  68. data/lib/stretchy/attributes/type/sparse_vector.rb +25 -21
  69. data/lib/stretchy/attributes/type/string.rb +42 -1
  70. data/lib/stretchy/attributes/type/text.rb +53 -28
  71. data/lib/stretchy/attributes/type/token_count.rb +21 -11
  72. data/lib/stretchy/attributes/type/version.rb +16 -6
  73. data/lib/stretchy/attributes/type/wildcard.rb +36 -25
  74. data/lib/stretchy/attributes.rb +29 -0
  75. data/lib/stretchy/delegation/gateway_delegation.rb +78 -0
  76. data/lib/stretchy/index_setting.rb +94 -0
  77. data/lib/stretchy/indexing/bulk.rb +75 -3
  78. data/lib/stretchy/model/callbacks.rb +1 -0
  79. data/lib/stretchy/model/common.rb +157 -0
  80. data/lib/stretchy/model/persistence.rb +144 -0
  81. data/lib/stretchy/model/refreshable.rb +26 -0
  82. data/lib/stretchy/pipeline.rb +2 -1
  83. data/lib/stretchy/pipelines/processor.rb +38 -36
  84. data/lib/stretchy/querying.rb +7 -8
  85. data/lib/stretchy/record.rb +5 -4
  86. data/lib/stretchy/relation.rb +229 -28
  87. data/lib/stretchy/relations/aggregation_methods/aggregation.rb +59 -0
  88. data/lib/stretchy/relations/aggregation_methods/avg.rb +45 -0
  89. data/lib/stretchy/relations/aggregation_methods/bucket_script.rb +47 -0
  90. data/lib/stretchy/relations/aggregation_methods/bucket_selector.rb +47 -0
  91. data/lib/stretchy/relations/aggregation_methods/bucket_sort.rb +47 -0
  92. data/lib/stretchy/relations/aggregation_methods/cardinality.rb +47 -0
  93. data/lib/stretchy/relations/aggregation_methods/children.rb +47 -0
  94. data/lib/stretchy/relations/aggregation_methods/composite.rb +41 -0
  95. data/lib/stretchy/relations/aggregation_methods/date_histogram.rb +53 -0
  96. data/lib/stretchy/relations/aggregation_methods/date_range.rb +53 -0
  97. data/lib/stretchy/relations/aggregation_methods/extended_stats.rb +48 -0
  98. data/lib/stretchy/relations/aggregation_methods/filter.rb +47 -0
  99. data/lib/stretchy/relations/aggregation_methods/filters.rb +47 -0
  100. data/lib/stretchy/relations/aggregation_methods/geo_bounds.rb +40 -0
  101. data/lib/stretchy/relations/aggregation_methods/geo_centroid.rb +40 -0
  102. data/lib/stretchy/relations/aggregation_methods/global.rb +39 -0
  103. data/lib/stretchy/relations/aggregation_methods/histogram.rb +43 -0
  104. data/lib/stretchy/relations/aggregation_methods/ip_range.rb +41 -0
  105. data/lib/stretchy/relations/aggregation_methods/max.rb +40 -0
  106. data/lib/stretchy/relations/aggregation_methods/min.rb +41 -0
  107. data/lib/stretchy/relations/aggregation_methods/missing.rb +40 -0
  108. data/lib/stretchy/relations/aggregation_methods/nested.rb +40 -0
  109. data/lib/stretchy/relations/aggregation_methods/percentile_ranks.rb +45 -0
  110. data/lib/stretchy/relations/aggregation_methods/percentiles.rb +45 -0
  111. data/lib/stretchy/relations/aggregation_methods/range.rb +42 -0
  112. data/lib/stretchy/relations/aggregation_methods/reverse_nested.rb +40 -0
  113. data/lib/stretchy/relations/aggregation_methods/sampler.rb +40 -0
  114. data/lib/stretchy/relations/aggregation_methods/scripted_metric.rb +43 -0
  115. data/lib/stretchy/relations/aggregation_methods/significant_terms.rb +45 -0
  116. data/lib/stretchy/relations/aggregation_methods/stats.rb +42 -0
  117. data/lib/stretchy/relations/aggregation_methods/sum.rb +42 -0
  118. data/lib/stretchy/relations/aggregation_methods/terms.rb +46 -0
  119. data/lib/stretchy/relations/aggregation_methods/top_hits.rb +42 -0
  120. data/lib/stretchy/relations/aggregation_methods/top_metrics.rb +44 -0
  121. data/lib/stretchy/relations/aggregation_methods/value_count.rb +41 -0
  122. data/lib/stretchy/relations/aggregation_methods/weighted_avg.rb +42 -0
  123. data/lib/stretchy/relations/aggregation_methods.rb +20 -749
  124. data/lib/stretchy/relations/finder_methods.rb +2 -18
  125. data/lib/stretchy/relations/null_relation.rb +55 -0
  126. data/lib/stretchy/relations/query_builder.rb +82 -36
  127. data/lib/stretchy/relations/query_methods/bind.rb +19 -0
  128. data/lib/stretchy/relations/query_methods/extending.rb +29 -0
  129. data/lib/stretchy/relations/query_methods/fields.rb +70 -0
  130. data/lib/stretchy/relations/query_methods/filter_query.rb +53 -0
  131. data/lib/stretchy/relations/query_methods/has_field.rb +40 -0
  132. data/lib/stretchy/relations/query_methods/highlight.rb +75 -0
  133. data/lib/stretchy/relations/query_methods/hybrid.rb +60 -0
  134. data/lib/stretchy/relations/query_methods/ids.rb +40 -0
  135. data/lib/stretchy/relations/query_methods/match.rb +52 -0
  136. data/lib/stretchy/relations/query_methods/must_not.rb +54 -0
  137. data/lib/stretchy/relations/query_methods/neural.rb +58 -0
  138. data/lib/stretchy/relations/query_methods/neural_sparse.rb +43 -0
  139. data/lib/stretchy/relations/query_methods/none.rb +21 -0
  140. data/lib/stretchy/relations/query_methods/or_filter.rb +21 -0
  141. data/lib/stretchy/relations/query_methods/order.rb +63 -0
  142. data/lib/stretchy/relations/query_methods/query_string.rb +44 -0
  143. data/lib/stretchy/relations/query_methods/regexp.rb +61 -0
  144. data/lib/stretchy/relations/query_methods/should.rb +51 -0
  145. data/lib/stretchy/relations/query_methods/size.rb +44 -0
  146. data/lib/stretchy/relations/query_methods/skip_callbacks.rb +47 -0
  147. data/lib/stretchy/relations/query_methods/source.rb +59 -0
  148. data/lib/stretchy/relations/query_methods/where.rb +113 -0
  149. data/lib/stretchy/relations/query_methods.rb +48 -569
  150. data/lib/stretchy/relations/scoping/default.rb +136 -0
  151. data/lib/stretchy/relations/scoping/named.rb +70 -0
  152. data/lib/stretchy/relations/scoping/scope_registry.rb +36 -0
  153. data/lib/stretchy/relations/scoping.rb +30 -0
  154. data/lib/stretchy/relations/search_option_methods.rb +2 -0
  155. data/lib/stretchy/version.rb +1 -1
  156. data/lib/stretchy.rb +17 -10
  157. metadata +111 -17
  158. data/lib/stretchy/common.rb +0 -38
  159. data/lib/stretchy/null_relation.rb +0 -53
  160. data/lib/stretchy/persistence.rb +0 -43
  161. data/lib/stretchy/refreshable.rb +0 -15
  162. data/lib/stretchy/scoping/default.rb +0 -134
  163. data/lib/stretchy/scoping/named.rb +0 -68
  164. data/lib/stretchy/scoping/scope_registry.rb +0 -34
  165. data/lib/stretchy/scoping.rb +0 -28
@@ -1,26 +1,35 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines a flattened attribute for the model.
3
- #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- # :depth_limit - The Integer maximum allowed depth of the flattened object field. Defaults to 20.
6
- # :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
7
- # :eager_global_ordinals - The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
8
- # :ignore_above - The Integer limit for the length of leaf values. Values longer than this limit will not be indexed. By default, there is no limit.
9
- # :index - The Boolean indicating if the field should be searchable. Defaults to true.
10
- # :index_options - The String indicating what information should be stored in the index for scoring purposes. Defaults to 'docs'.
11
- # :null_value - The String value to be substituted for any explicit null values. Defaults to null.
12
- # :similarity - The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
13
- # :split_queries_on_whitespace - The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
14
- # :time_series_dimensions - The Array of Strings indicating the fields inside the flattened object that are dimensions of the time series.
15
- #
16
- # Examples
17
- #
18
- # class MyModel
19
- # include StretchyModel
2
+ # The Flattened attribute type
3
+ #
4
+ # This class is used to define a flattened attribute for a model. It provides support for the Elasticsearch flattened data type, which is a type of data type that can hold an entire JSON object as a single field.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `type:` `:flattened`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:depth_limit:` The Integer maximum allowed depth of the flattened object field. Defaults to 20.
11
+ # - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
12
+ # - `:eager_global_ordinals:` The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
13
+ # - `:ignore_above:` The Integer limit for the length of leaf values. Values longer than this limit will not be indexed. By default, there is no limit.
14
+ # - `:index:` The Boolean indicating if the field should be searchable. Defaults to true.
15
+ # - `:index_options:` The String indicating what information should be stored in the index for scoring purposes. Defaults to 'docs'.
16
+ # - `:null_value:` The String value to be substituted for any explicit null values. Defaults to null.
17
+ # - `:similarity:` The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
18
+ # - `:split_queries_on_whitespace:` The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
19
+ # - `:time_series_dimensions:` The Array of Strings indicating the fields inside the flattened object that are dimensions of the time series.
20
+ #
21
+ # ---
22
+ #
23
+ # ### Examples
24
+ #
25
+ # #### Define a flattened attribute
26
+ #
27
+ # ```ruby
28
+ # class MyModel < StretchyModel
20
29
  # attribute :metadata, :flattened, depth_limit: 10, index_options: 'freqs'
21
30
  # end
31
+ # ```
22
32
  #
23
- # Returns nothing.
24
33
  class Flattened < Stretchy::Attributes::Type::Base
25
34
  OPTIONS = [:depth_limit, :doc_values, :eager_global_ordinals, :ignore_above, :index, :index_options, :null_value, :similarity, :split_queries_on_whitespace, :time_series_dimensions]
26
35
 
@@ -1,22 +1,31 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines a geo_point attribute for the model.
2
+ # The GeoPoint attribute type
3
3
  #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- # :ignore_malformed - The Boolean indicating if malformed geopoints should be ignored. Defaults to false.
6
- # :ignore_z_value - The Boolean indicating if three dimension points should be accepted but only latitude and longitude values should be indexed. Defaults to true.
7
- # :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
8
- # :null_value - The GeoPoint value to be substituted for any explicit null values. Defaults to null.
9
- # :on_script_error - The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'fail' or 'continue'.
10
- # :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
4
+ # This class is used to define a geo_point attribute for a model. It provides support for the Elasticsearch geo_point data type, which is a type of data type that can hold geographical points (latitude and longitude).
11
5
  #
12
- # Examples
6
+ # ### Parameters
13
7
  #
14
- # class MyModel
15
- # include StretchyModel
8
+ # - `type:` `:geo_point`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:ignore_malformed:` The Boolean indicating if malformed geopoints should be ignored. Defaults to false.
11
+ # - `:ignore_z_value:` The Boolean indicating if three dimension points should be accepted but only latitude and longitude values should be indexed. Defaults to true.
12
+ # - `:index:` The Boolean indicating if the field should be quickly searchable. Defaults to true.
13
+ # - `:null_value:` The GeoPoint value to be substituted for any explicit null values. Defaults to null.
14
+ # - `:on_script_error:` The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'fail' or 'continue'.
15
+ # - `:script:` The String script that will index values generated by this script, rather than reading the values directly from the source.
16
+ #
17
+ # ---
18
+ #
19
+ # ### Examples
20
+ #
21
+ # #### Define a geo_point attribute
22
+ #
23
+ # ```ruby
24
+ # class MyModel < StretchyModel
16
25
  # attribute :location, :geo_point, ignore_malformed: true
17
26
  # end
27
+ # ```
18
28
  #
19
- # Returns nothing.
20
29
  class GeoPoint < Stretchy::Attributes::Type::Base
21
30
  OPTIONS = [:ignore_malformed, :ignore_z_value, :index, :null_value, :on_script_error, :script]
22
31
 
@@ -1,22 +1,31 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines a geo_shape attribute for the model.
2
+ # The GeoShape attribute type
3
3
  #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- # :orientation - The String default orientation for the field’s WKT polygons. Can be 'right', 'counterclockwise', 'ccw', 'left', 'clockwise', or 'cw'. Defaults to 'right'.
6
- # :ignore_malformed - The Boolean indicating if malformed GeoJSON or WKT shapes should be ignored. Defaults to false.
7
- # :ignore_z_value - The Boolean indicating if three dimension points should be accepted but only latitude and longitude values should be indexed. Defaults to true.
8
- # :coerce - The Boolean indicating if unclosed linear rings in polygons should be automatically closed. Defaults to false.
9
- # :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
10
- # :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
4
+ # This class is used to define a geo_shape attribute for a model. It provides support for the Elasticsearch geo_shape data type, which is a type of data type that can hold geographical shapes.
11
5
  #
12
- # Examples
6
+ # ### Parameters
13
7
  #
14
- # class MyModel
15
- # include StretchyModel
8
+ # - `type:` `:geo_shape`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:orientation:` The String default orientation for the field’s WKT polygons. Can be 'right', 'counterclockwise', 'ccw', 'left', 'clockwise', or 'cw'. Defaults to 'right'.
11
+ # - `:ignore_malformed:` The Boolean indicating if malformed GeoJSON or WKT shapes should be ignored. Defaults to false.
12
+ # - `:ignore_z_value:` The Boolean indicating if three dimension points should be accepted but only latitude and longitude values should be indexed. Defaults to true.
13
+ # - `:coerce:` The Boolean indicating if unclosed linear rings in polygons should be automatically closed. Defaults to false.
14
+ # - `:index:` The Boolean indicating if the field should be quickly searchable. Defaults to true.
15
+ # - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
16
+ #
17
+ # ---
18
+ #
19
+ # ### Examples
20
+ #
21
+ # #### Define a geo_shape attribute
22
+ #
23
+ # ```ruby
24
+ # class MyModel < StretchyModel
16
25
  # attribute :boundary, :geo_shape, orientation: 'left', coerce: true
17
26
  # end
27
+ # ```
18
28
  #
19
- # Returns nothing.
20
29
  class GeoShape < Stretchy::Attributes::Type::Base
21
30
  OPTIONS = [:orientation, :ignore_malformed, :ignore_z_value, :coerce, :index, :doc_values]
22
31
 
@@ -1,19 +1,29 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines a hash attribute for the model.
2
+ # The Hash attribute type
3
3
  #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- # :dynamic - The String indicating if new properties should be added dynamically to an existing object. Can be 'true', 'runtime', 'false', or 'strict'. Defaults to 'true'.
6
- # :enabled - The Boolean indicating if the JSON value for the object field should be parsed and indexed. Defaults to true.
7
- # :subobjects - The Boolean indicating if the object can hold subobjects. Defaults to true.
8
- # :properties - The Hash of fields within the object, which can be of any data type, including object.
4
+ # This class is used to define a hash attribute for a model. It provides support for the Elasticsearch object data type, which is a type of data type that can hold JSON objects.
9
5
  #
10
- # Examples
6
+ # ### Parameters
11
7
  #
12
- # class MyModel < Stretchy::Record
8
+ # - `type:` `:hash`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:dynamic:` The String indicating if new properties should be added dynamically to an existing object. Can be 'true', 'runtime', 'false', or 'strict'. Defaults to 'true'.
11
+ # - `:enabled:` The Boolean indicating if the JSON value for the object field should be parsed and indexed. Defaults to true.
12
+ # - `:subobjects:` The Boolean indicating if the object can hold subobjects. Defaults to true.
13
+ # - `:properties:` The Hash of fields within the object, which can be of any data type, including object.
14
+ #
15
+ # ---
16
+ #
17
+ # ### Examples
18
+ #
19
+ # #### Define a hash attribute
20
+ #
21
+ # ```ruby
22
+ # class MyModel < StretchyModel
13
23
  # attribute :metadata, :hash, dynamic: 'strict', subobjects: false
14
24
  # end
25
+ # ```
15
26
  #
16
- # Returns nothing.
17
27
  class Hash < Stretchy::Attributes::Type::Base
18
28
  OPTIONS = [:dynamic, :enabled, :subobjects, :properties]
19
29
 
@@ -26,11 +36,15 @@ module Stretchy::Attributes::Type
26
36
  end
27
37
 
28
38
  def mappings(name)
29
- options = {}
39
+ options = {type: type_for_database}
30
40
  OPTIONS.each { |option| options[option] = send(option) unless send(option).nil? }
31
41
  { name => options }.as_json
32
42
  end
33
43
 
44
+ def keyword_field?
45
+ true
46
+ end
47
+
34
48
  private
35
49
 
36
50
  def cast_value(value)
@@ -1,5 +1,30 @@
1
1
  module Stretchy::Attributes::Type
2
+ # The Histogram attribute type
3
+ #
4
+ # This class is used to define a histogram attribute for a model. It provides support for the Elasticsearch histogram data type, which is a type of data type that can hold arrays of values and counts.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `type:` `:histogram`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:ignore_malformed:` The Boolean indicating if malformed numbers should be ignored. Defaults to false.
11
+ # - `:coerce:` The Boolean indicating if the field should automatically convert strings to numbers and truncate fractions for integers. Defaults to true.
12
+ #
13
+ # ---
14
+ #
15
+ # ### Examples
16
+ #
17
+ # #### Define a histogram attribute
18
+ #
19
+ # ```ruby
20
+ # class MyModel < StretchyModel
21
+ # attribute :grades_distribution, :histogram, ignore_malformed: true
22
+ # end
23
+ # ```
24
+ #
2
25
  class Histogram < Stretchy::Attributes::Type::Base
26
+ OPTIONS = [:ignore_malformed, :coerce]
27
+
3
28
  def type
4
29
  :histogram
5
30
  end
@@ -1,24 +1,33 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines an IP attribute for the model.
3
- #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- # :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
6
- # :ignore_malformed - The Boolean indicating if malformed IP addresses should be ignored. Defaults to false.
7
- # :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
8
- # :null_value - The String IPv4 or IPv6 value to be substituted for any explicit null values. Defaults to null.
9
- # :on_script_error - The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'reject' or 'ignore'.
10
- # :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
11
- # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
12
- # :time_series_dimension - The Boolean indicating if the field is a time series dimension. Defaults to false.
13
- #
14
- # Examples
15
- #
16
- # class MyModel
17
- # include StretchyModel
2
+ # The IP attribute type
3
+ #
4
+ # This class is used to define an IP attribute for a model. It provides support for the Elasticsearch IP data type, which is a type of data type that can hold IPv4 and IPv6 addresses.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `type:` `:ip`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
11
+ # - `:ignore_malformed:` The Boolean indicating if malformed IP addresses should be ignored. Defaults to false.
12
+ # - `:index:` The Boolean indicating if the field should be quickly searchable. Defaults to true.
13
+ # - `:null_value:` The String IPv4 or IPv6 value to be substituted for any explicit null values. Defaults to null.
14
+ # - `:on_script_error:` The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'reject' or 'ignore'.
15
+ # - `:script:` The String script that will index values generated by this script, rather than reading the values directly from the source.
16
+ # - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
17
+ # - `:time_series_dimension:` The Boolean indicating if the field is a time series dimension. Defaults to false.
18
+ #
19
+ # ---
20
+ #
21
+ # ### Examples
22
+ #
23
+ # #### Define an IP attribute
24
+ #
25
+ # ```ruby
26
+ # class MyModel < StretchyModel
18
27
  # attribute :ip_address, :ip, ignore_malformed: true, time_series_dimension: true
19
28
  # end
29
+ # ```
20
30
  #
21
- # Returns nothing.
22
31
  class IP < Stretchy::Attributes::Type::Base
23
32
  OPTIONS = [:doc_values, :ignore_malformed, :index, :null_value, :on_script_error, :script, :store, :time_series_dimension]
24
33
 
@@ -1,17 +1,26 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines a join attribute for the model.
2
+ # The Join attribute type
3
3
  #
4
- # opts - The Hash options used to define the parent/child relation within documents of the same index (default: {}):
5
- # :relations - The Hash defining a set of possible relations within the documents, each relation being a parent name and a child name.
4
+ # This class is used to define a join attribute for a model. It provides support for the Elasticsearch join data type, which is a type of data type that can hold parent/child relationships within documents of the same index.
6
5
  #
7
- # Examples
6
+ # ### Parameters
8
7
  #
9
- # class MyModel
10
- # include StretchyModel
8
+ # - `type:` `:join`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:relations:` The Hash defining a set of possible relations within the documents, each relation being a parent name and a child name.
11
+ #
12
+ # ---
13
+ #
14
+ # ### Examples
15
+ #
16
+ # #### Define a join attribute
17
+ #
18
+ # ```ruby
19
+ # class MyModel < StretchyModel
11
20
  # attribute :relation, :join, relations: { question: :answer }
12
21
  # end
22
+ # ```
13
23
  #
14
- # Returns nothing.
15
24
  class Join < Stretchy::Attributes::Type::Base
16
25
  OPTIONS = [:relations]
17
26
 
@@ -1,37 +1,32 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines a keyword attribute for the model.
3
- #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- #
6
- # :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
7
- # :eager_global_ordinals - The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
8
- # :fields - The Hash of multi-fields for the same string value to be indexed in multiple ways.
9
- # :ignore_above - The Integer limit for the length of the string. Strings longer than this limit will not be indexed. Defaults to 2147483647.
10
- # :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
11
- # :index_options - The String indicating what information should be stored in the index for scoring purposes. Defaults to 'docs'.
12
- # :meta - The Hash metadata about the field.
13
- # :norms - The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to false.
14
- # :null_value - The String value to be substituted for any explicit null values. Defaults to null.
15
- # :on_script_error - The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'fail' or 'continue'.
16
- # :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
17
- # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
18
- # :similarity - The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
19
- # :normalizer - The String pre-processor for the keyword prior to indexing. Defaults to null.
20
- # :split_queries_on_whitespace - The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
21
- # :time_series_dimension - The Boolean indicating if the field is a time series dimension. Defaults to false.
22
- #
23
- # Examples
24
- # class MyModel
25
- # include StretchyModel
26
- # attribute :tag, :keyword, ignore_above: 256, time_series_dimension: true
2
+ # The Join attribute type
3
+ #
4
+ # This class is used to define a join attribute for a model. It provides support for the Elasticsearch join data type, which is a type of data type that can hold parent/child relationships within documents of the same index.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `type:` `:join`.
9
+ # - `options:` The Hash of options for the attribute.
10
+ # - `:relations:` The Hash defining a set of possible relations within the documents, each relation being a parent name and a child name.
11
+ #
12
+ # ---
13
+ #
14
+ # ### Examples
15
+ #
16
+ # #### Define a join attribute
17
+ #
18
+ # ```ruby
19
+ # class MyModel < StretchyModel
20
+ # attribute :relation, :join, relations: { question: :answer }
27
21
  # end
22
+ # ```
28
23
  #
29
- # Returns nothing.
30
24
  class Keyword < Stretchy::Attributes::Type::Base
31
25
  OPTIONS = [:doc_values, :eager_global_ordinals, :fields, :ignore_above, :index, :index_options, :meta, :norms, :null_value, :on_script_error, :script, :store, :similarity, :normalizer, :split_queries_on_whitespace, :time_series_dimension]
32
26
 
33
27
  def type
34
28
  :keyword
35
29
  end
30
+
36
31
  end
37
32
  end
@@ -0,0 +1,47 @@
1
+ module Stretchy::Attributes::Type
2
+ # The KnnVector attribute type.
3
+ #
4
+ # This class is used to define a `knn_vector` attribute for a model.
5
+ # It provides support for the Elasticsearch `knn_vector` data type,
6
+ # which is a type of data type that can hold vectors of float values.
7
+ #
8
+ # ### Parameters
9
+ #
10
+ # The `knn_vector` data type supports the following options:
11
+ # - `dimension`: The number of dimensions in the vector.
12
+ # - `method`: The method used for nearest neighbor search. This is a hash that can include the following keys:
13
+ # - `name`: The name of the method.
14
+ # - `space_type`: The type of space used for the method.
15
+ # - `engine`: The engine used for the method.
16
+ # - `parameters`: Any additional parameters for the method.
17
+ #
18
+ # ---
19
+ #
20
+ # ### Examples
21
+ #
22
+ #
23
+ # #### Define a `knn_vector` attribute
24
+ #
25
+ # ```ruby
26
+ # class MyModel < StretchyModel
27
+ # attribute :my_vector, :knn_vector
28
+ # end
29
+ # ```
30
+ #
31
+ # #### Define a `knn_vector` attribute with options
32
+ #
33
+ # ```ruby
34
+ # class MyModel < StretchyModel
35
+ # attribute :my_vector, :knn_vector, dimension: 3, method: { name: "hnsw", space_type: "cosinesimil", engine: "nmslib", parameters: { ef_construction: 200 } }
36
+ # end
37
+ # ```
38
+ #
39
+ class KnnVector < Stretchy::Attributes::Type::Base
40
+ OPTIONS = [:dimension, :method]
41
+
42
+ def type
43
+ :knn_vector
44
+ end
45
+
46
+ end
47
+ end
@@ -1,5 +1,26 @@
1
- # a space-optimized variant of text that disables scoring and performs slower on queries that need positions. It is best suited for indexing log messages.
2
1
  module Stretchy::Attributes::Type
2
+ # The MatchOnlyText attribute type
3
+ #
4
+ # This class is used to define a match_only_text attribute for a model. It provides support for the Elasticsearch match_only_text data type, which is a space-optimized variant of text that disables scoring and performs slower on queries that need positions. It is best suited for indexing log messages.
5
+ # `:match_only_text` is a space-optimized variant of text that disables scoring and performs slower on queries that need positions. It is best suited for indexing log messages.
6
+ #
7
+ # ### Parameters
8
+ #
9
+ # - `type:` `:match_only_text`.
10
+ # - `options:` The Hash of options for the attribute. This type does not have any specific options.
11
+ #
12
+ # ---
13
+ #
14
+ # ### Examples
15
+ #
16
+ # #### Define a match_only_text attribute
17
+ #
18
+ # ```ruby
19
+ # class MyModel < StretchyModel
20
+ # attribute :log_message, :match_only_text
21
+ # end
22
+ # ```
23
+ #
3
24
  class MatchOnlyText < Stretchy::Attributes::Type::Text
4
25
  def type
5
26
  :match_only_text
@@ -1,20 +1,25 @@
1
1
  module Stretchy::Attributes::Type
2
- # Public: Defines a nested attribute for the model.
2
+ # The MatchOnlyText attribute type
3
3
  #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- # :dynamic - The String indicating if new properties should be added dynamically to an existing nested object. Can be 'true', 'false', or 'strict'. Defaults to 'true'.
6
- # :properties - The Hash of fields within the nested object, which can be of any data type, including nested.
7
- # :include_in_parent - The Boolean indicating if all fields in the nested object are also added to the parent document as standard fields. Defaults to false.
8
- # :include_in_root - The Boolean indicating if all fields in the nested object are also added to the root document as standard fields. Defaults to false.
4
+ # This class is used to define a match_only_text attribute for a model. It provides support for the Elasticsearch match_only_text data type, which is a space-optimized variant of text that disables scoring and performs slower on queries that need positions. It is best suited for indexing log messages.
9
5
  #
10
- # Examples
6
+ # ### Parameters
11
7
  #
12
- # class MyModel
13
- # include StretchyModel
14
- # attribute :metadata, :nested, dynamic: 'strict', include_in_parent: true
8
+ # - `type:` `:match_only_text`.
9
+ # - `options:` The Hash of options for the attribute. This type does not have any specific options.
10
+ #
11
+ # ---
12
+ #
13
+ # ### Examples
14
+ #
15
+ # #### Define a match_only_text attribute
16
+ #
17
+ # ```ruby
18
+ # class MyModel < StretchyModel
19
+ # attribute :log_message, :match_only_text
15
20
  # end
21
+ # ```
16
22
  #
17
- # Returns nothing.
18
23
  class Nested < Stretchy::Attributes::Type::Base
19
24
  OPTIONS = [:dynamic, :properties, :include_in_parent, :include_in_root]
20
25
 
@@ -1,29 +1,37 @@
1
1
  module Stretchy::Attributes::Type::Numeric
2
- # Public: Defines a numeric attribute for the model. This is a base class for numeric types.
3
- #
4
- # opts - The Hash options used to refine the attribute (default: {}):
5
- # :coerce - The Boolean indicating if strings should be converted to numbers and fractions truncated for integers. Defaults to true.
6
- # :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
7
- # :ignore_malformed - The Boolean indicating if malformed numbers should be ignored. Defaults to false.
8
- # :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
9
- # :meta - The Hash metadata about the field.
10
- # :null_value - The Numeric value to be substituted for any explicit null values. Defaults to null.
11
- # :on_script_error - The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'fail' or 'continue'.
12
- # :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
13
- # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
14
- # :time_series_dimension - The Boolean indicating if the field is a time series dimension. Defaults to false.
15
- # :time_series_metric - The String indicating if the field is a time series metric. Can be 'counter', 'gauge', or 'null'.
16
- #
17
- # Examples
18
- #
19
- # class MyModel
20
- # include StretchyModel
2
+ # The Base class for numeric attribute types
3
+ #
4
+ # This class is used to define a base for numeric attribute types for a model. It provides support for the Elasticsearch numeric data types, which are types of data that can hold numeric values.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `options:` The Hash of options for the attribute.
9
+ # - `:coerce:` The Boolean indicating if strings should be converted to numbers and fractions truncated for integers. Defaults to true.
10
+ # - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
11
+ # - `:ignore_malformed:` The Boolean indicating if malformed numbers should be ignored. Defaults to false.
12
+ # - `:index:` The Boolean indicating if the field should be quickly searchable. Defaults to true.
13
+ # - `:meta:` The Hash metadata about the field.
14
+ # - `:null_value:` The Numeric value to be substituted for any explicit null values. Defaults to null.
15
+ # - `:on_script_error:` The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'fail' or 'continue'.
16
+ # - `:script:` The String script that will index values generated by this script, rather than reading the values directly from the source.
17
+ # - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
18
+ # - `:time_series_dimension:` The Boolean indicating if the field is a time series dimension. Defaults to false.
19
+ # - `:time_series_metric:` The String indicating if the field is a time series metric. Can be 'counter', 'gauge', or 'null'.
20
+ #
21
+ # ---
22
+ #
23
+ # ### Examples
24
+ #
25
+ # #### Define a numeric attribute
26
+ #
27
+ # ```ruby
28
+ # class MyModel < Stretchy::Record
21
29
  # attribute :age, :integer, coerce: false, time_series_dimension: true
22
30
  # end
31
+ # ```
23
32
  #
24
- # Returns nothing.
25
- class Base < Stretchy::Attributes::Type::Base
26
- OPTIONS = [:coerce, :doc_values, :ignore_malformed, :index, :meta, :null_value, :on_script_error, :script, :store, :time_series_dimension, :time_series_metric]
33
+ class Base < Stretchy::Attributes::Type::Base #:nodoc:
34
+ OPTIONS = [:coerce, :doc_values, :ignore_malformed, :index, :meta, :null_value, :on_script_error, :script, :store, :time_series_dimension, :time_series_metric] + self.superclass::OPTIONS
27
35
 
28
36
  def type
29
37
  raise NotImplementedError, "You must use one of the numeric types: integer, long, short, byte, double, float, half_float, scaled_float."
@@ -1,4 +1,24 @@
1
1
  module Stretchy::Attributes::Type::Numeric
2
+ # The Byte attribute type
3
+ #
4
+ # This class is used to define a byte attribute for a model. It provides support for the Elasticsearch numeric data type, which is a type of data type that can hold byte values.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `type:` `:byte`.
9
+ #
10
+ # ---
11
+ #
12
+ # ### Examples
13
+ #
14
+ # #### Define a byte attribute
15
+ #
16
+ # ```ruby
17
+ # class MyModel < StretchyModel
18
+ # attribute :data, :byte
19
+ # end
20
+ # ```
21
+ #
2
22
  class Byte < Base
3
23
  def type
4
24
  :byte
@@ -1,4 +1,24 @@
1
1
  module Stretchy::Attributes::Type::Numeric
2
+ # The Double attribute type
3
+ #
4
+ # This class is used to define a double attribute for a model. It provides support for the Elasticsearch numeric data type, which is a type of data type that can hold double-precision 64-bit IEEE 754 floating point values.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `type:` `:double`.
9
+ #
10
+ # ---
11
+ #
12
+ # ### Examples
13
+ #
14
+ # #### Define a double attribute
15
+ #
16
+ # ```ruby
17
+ # class MyModel < StretchyModel
18
+ # attribute :rating, :double
19
+ # end
20
+ # ```
21
+ #
2
22
  class Double < Base
3
23
  def type
4
24
  :double
@@ -1,4 +1,24 @@
1
1
  module Stretchy::Attributes::Type::Numeric
2
+ # The Float attribute type
3
+ #
4
+ # This class is used to define a float attribute for a model. It provides support for the Elasticsearch numeric data type, which is a type of data type that can hold single-precision 32-bit IEEE 754 floating point values.
5
+ #
6
+ # ### Parameters
7
+ #
8
+ # - `type:` `:float`.
9
+ #
10
+ # ---
11
+ #
12
+ # ### Examples
13
+ #
14
+ # #### Define a float attribute
15
+ #
16
+ # ```ruby
17
+ # class MyModel < StretchyModel
18
+ # attribute :rating, :float
19
+ # end
20
+ # ```
21
+ #
2
22
  class Float < Base
3
23
  def type
4
24
  :float