stretchy-model 0.6.0 → 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/containers/Dockerfile.opensearch +4 -3
- data/docker-compose.yml +32 -19
- 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/elasticsearch/api/actions/machine_learning/models/delete_model.rb +33 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/deploy.rb +31 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/get_model.rb +43 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/get_status.rb +31 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb +45 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/register.rb +45 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb +32 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/update_model.rb +39 -0
- data/lib/elasticsearch/api/namespace/machine_learning/model.rb +27 -0
- data/lib/opensearch/api/actions/machine_learning/models/delete_model.rb +33 -0
- data/lib/opensearch/api/actions/machine_learning/models/deploy.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/get_model.rb +44 -0
- data/lib/opensearch/api/actions/machine_learning/models/get_status.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/params_registry.rb +45 -0
- data/lib/opensearch/api/actions/machine_learning/models/register.rb +45 -0
- data/lib/opensearch/api/actions/machine_learning/models/undeploy.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/update_model.rb +39 -0
- data/lib/opensearch/api/namespace/machine_learning/model.rb +27 -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 +81 -20
- 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 +27 -10
- 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 +30 -0
- data/lib/stretchy/delegation/gateway_delegation.rb +86 -2
- data/lib/stretchy/index_setting.rb +94 -0
- data/lib/stretchy/indexing/bulk.rb +75 -3
- data/lib/stretchy/machine_learning/model.rb +192 -0
- data/lib/stretchy/model/callbacks.rb +1 -0
- data/lib/stretchy/model/common.rb +157 -0
- data/lib/stretchy/model/persistence.rb +144 -0
- data/lib/stretchy/model/refreshable.rb +26 -0
- data/lib/stretchy/open_search_compatibility.rb +4 -0
- data/lib/stretchy/pipeline.rb +124 -0
- data/lib/stretchy/pipelines/processor.rb +57 -0
- data/lib/stretchy/querying.rb +7 -7
- data/lib/stretchy/rails/instrumentation/publishers.rb +31 -0
- data/lib/{rails → stretchy/rails}/instrumentation/railtie.rb +11 -6
- data/lib/stretchy/record.rb +5 -4
- data/lib/stretchy/relation.rb +230 -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 +139 -23
- 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 +51 -540
- 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/shared_scopes.rb +6 -1
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +23 -11
- metadata +147 -18
- data/lib/rails/instrumentation/publishers.rb +0 -29
- data/lib/stretchy/common.rb +0 -33
- 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,144 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Model
|
3
|
+
module Persistence
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
# Create a new instance and save it to the database.
|
8
|
+
#
|
9
|
+
# This class method is used to create a new instance of the model and save it to the database. It accepts a list of keyword attributes to set on the new instance.
|
10
|
+
#
|
11
|
+
# ### Parameters
|
12
|
+
#
|
13
|
+
# - `*args:` A list of keyword arguments representing the attributes to set on the new instance.
|
14
|
+
#
|
15
|
+
# ### Returns
|
16
|
+
# Returns the newly created instance of the model.
|
17
|
+
#
|
18
|
+
# ---
|
19
|
+
#
|
20
|
+
# ### Examples
|
21
|
+
#
|
22
|
+
# #### Create a new instance
|
23
|
+
#
|
24
|
+
# ```ruby
|
25
|
+
# Model.create(name: 'John Doe', age: 30)
|
26
|
+
# ```
|
27
|
+
#
|
28
|
+
def create(*args)
|
29
|
+
self.new(*args).save
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Save the current instance to the database.
|
34
|
+
#
|
35
|
+
# This instance method is used to save the current instance of the model to the database. If the instance is a new record, it runs the `:create` callbacks and saves the instance to the database. It then sets the `id` of the instance to the `_id` returned by the save operation.
|
36
|
+
#
|
37
|
+
# ### Returns
|
38
|
+
# Returns the `id` of the saved instance.
|
39
|
+
#
|
40
|
+
# ---
|
41
|
+
#
|
42
|
+
# ### Examples
|
43
|
+
#
|
44
|
+
# #### Save an instance
|
45
|
+
#
|
46
|
+
# ```ruby
|
47
|
+
# model = Model.new(name: 'John Doe', age: 30)
|
48
|
+
# model.save
|
49
|
+
# ```
|
50
|
+
#
|
51
|
+
def save
|
52
|
+
run_callbacks :save do
|
53
|
+
if new_record?
|
54
|
+
run_callbacks :create do
|
55
|
+
response = self.class.gateway.save(self.attributes)
|
56
|
+
self.id = response['_id']
|
57
|
+
end
|
58
|
+
else
|
59
|
+
self.class.gateway.save(self.attributes)
|
60
|
+
end
|
61
|
+
self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Destroy the current instance.
|
66
|
+
#
|
67
|
+
# This instance method is used to delete the current instance of the model from the database.
|
68
|
+
# It differs from delete in that it runs the `:destroy` callbacks before deleting the instance.
|
69
|
+
#
|
70
|
+
#
|
71
|
+
# ### Returns
|
72
|
+
# Returns `true` if the instance was successfully deleted, `false` otherwise.
|
73
|
+
#
|
74
|
+
# ---
|
75
|
+
#
|
76
|
+
# ### Examples
|
77
|
+
#
|
78
|
+
# #### Delete an instance
|
79
|
+
#
|
80
|
+
# ```ruby
|
81
|
+
# model = Model.find(id: '1')
|
82
|
+
# model.destroy
|
83
|
+
# ```
|
84
|
+
#
|
85
|
+
def destroy
|
86
|
+
run_callbacks :destroy do
|
87
|
+
delete
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Delete the current instance from the database.
|
92
|
+
#
|
93
|
+
# This instance method is used to delete the current instance of the model from the database. It uses the `id` of the instance to perform the delete operation.
|
94
|
+
#
|
95
|
+
# ### Returns
|
96
|
+
# Returns `true` if the instance was successfully deleted, `false` otherwise.
|
97
|
+
#
|
98
|
+
# ---
|
99
|
+
#
|
100
|
+
# ### Examples
|
101
|
+
#
|
102
|
+
# #### Delete an instance
|
103
|
+
#
|
104
|
+
# ```ruby
|
105
|
+
# model = Model.find(id: '1')
|
106
|
+
# model.delete
|
107
|
+
# ```
|
108
|
+
#
|
109
|
+
def delete
|
110
|
+
self.class.gateway.delete(self.id)["result"] == 'deleted'
|
111
|
+
end
|
112
|
+
|
113
|
+
# Update the current instance with the given attributes and save it to the database.
|
114
|
+
#
|
115
|
+
# This instance method is used to update the current instance of the model with the given attributes and save it to the database. It accepts a list of keyword arguments representing the attributes to update.
|
116
|
+
#
|
117
|
+
# ### Parameters
|
118
|
+
#
|
119
|
+
# - `*args:` A list of keyword arguments representing the attributes to update.
|
120
|
+
#
|
121
|
+
# ### Returns
|
122
|
+
# Returns `true` if the instance was successfully updated, `false` otherwise.
|
123
|
+
#
|
124
|
+
# ---
|
125
|
+
#
|
126
|
+
# ### Examples
|
127
|
+
#
|
128
|
+
# #### Update an instance
|
129
|
+
#
|
130
|
+
# ```ruby
|
131
|
+
# model = Model.find(id: '1')
|
132
|
+
# model.update(name: 'Jane Doe', age: 32)
|
133
|
+
# ```
|
134
|
+
#
|
135
|
+
def update(*args)
|
136
|
+
run_callbacks :update do
|
137
|
+
self.assign_attributes(*args)
|
138
|
+
self.save
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Model
|
3
|
+
# Adds callbacks to the model to refresh the index after save or destroy.
|
4
|
+
#
|
5
|
+
# ```ruby
|
6
|
+
# included do
|
7
|
+
# after_save :refresh_index
|
8
|
+
# after_destroy :refresh_index
|
9
|
+
# end
|
10
|
+
# ```
|
11
|
+
module Refreshable
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
|
15
|
+
included do
|
16
|
+
after_save :refresh_index
|
17
|
+
after_destroy :refresh_index
|
18
|
+
end
|
19
|
+
|
20
|
+
def refresh_index
|
21
|
+
self.class.refresh_index!
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'opensearch/api/namespace/machine_learning/model'
|
2
|
+
|
1
3
|
module Stretchy
|
2
4
|
module OpenSearchCompatibility
|
3
5
|
extend ActiveSupport::Concern
|
@@ -79,6 +81,8 @@ module Stretchy
|
|
79
81
|
|
80
82
|
::Elasticsearch::Persistence::Repository.send(:include, patch)
|
81
83
|
::Elasticsearch::Persistence::Repository.send(:include, store)
|
84
|
+
OpenSearch::API.send(:include, OpenSearch::API::MachineLearning::Models)
|
85
|
+
|
82
86
|
end
|
83
87
|
|
84
88
|
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Stretchy
|
2
|
+
class Pipeline
|
3
|
+
cattr_reader :client do
|
4
|
+
Stretchy.configuration.client.ingest
|
5
|
+
end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :description, :pipeline_name, :processors
|
9
|
+
|
10
|
+
def pipeline_name(name = nil)
|
11
|
+
return @pipeline_name if name.nil? && @pipeline_name
|
12
|
+
@pipeline_name = name || self.name.split('::').last.underscore
|
13
|
+
end
|
14
|
+
|
15
|
+
def description(desc = nil)
|
16
|
+
@description = desc if desc
|
17
|
+
@description
|
18
|
+
end
|
19
|
+
|
20
|
+
def processor(type, opts = {})
|
21
|
+
@processors ||= []
|
22
|
+
@processors << Stretchy::Pipelines::Processor.new(type, opts)
|
23
|
+
end
|
24
|
+
|
25
|
+
def all
|
26
|
+
begin
|
27
|
+
client.get_pipeline
|
28
|
+
rescue not_found => e
|
29
|
+
return {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def find(id=nil)
|
34
|
+
id = self.pipeline_name if id.nil?
|
35
|
+
client.get_pipeline(id: id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def simulate(docs, verbose: true)
|
39
|
+
client.simulate(id: self.pipeline_name, body: {docs: docs}, verbose: verbose)
|
40
|
+
end
|
41
|
+
|
42
|
+
# PUT _ingest/pipeline/<pipeline-name>
|
43
|
+
def create!
|
44
|
+
client.put_pipeline(id: self.pipeline_name, body: self.to_hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
# DELETE _ingest/pipeline/<pipeline-name>
|
48
|
+
def delete!
|
49
|
+
client.delete_pipeline(id: self.pipeline_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def exists?
|
53
|
+
begin
|
54
|
+
self.find(self.pipeline_name).present?
|
55
|
+
rescue not_found => e
|
56
|
+
return false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def to_hash
|
62
|
+
{
|
63
|
+
description: self.description,
|
64
|
+
processors: self.processors.map(&:to_hash)
|
65
|
+
}.as_json
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
def not_found
|
70
|
+
@not_found ||= Object.const_get("#{client.class.name.split('::').first}::Transport::Transport::Errors::NotFound")
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
attr_accessor :description, :pipeline_name, :processors
|
76
|
+
|
77
|
+
def initialize
|
78
|
+
@description = self.class.description
|
79
|
+
@pipeline_name = self.class.pipeline_name
|
80
|
+
@processors = self.class.processors
|
81
|
+
end
|
82
|
+
|
83
|
+
# GET _ingest/pipeline/<pipeline-name>
|
84
|
+
def find
|
85
|
+
self.class.find(self.pipeline_name)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Simulates the pipeline.
|
89
|
+
#
|
90
|
+
# Request body fields
|
91
|
+
#
|
92
|
+
# The following table lists the request body fields used to run a pipeline.
|
93
|
+
#
|
94
|
+
# Field Required Type Description
|
95
|
+
# docs Required Array The documents to be used to test the pipeline.
|
96
|
+
# pipeline Optional Object The pipeline to be simulated. If the pipeline identifier is not included, then the response simulates the latest pipeline created.
|
97
|
+
# The docs field can include subfields listed in the following table.
|
98
|
+
#
|
99
|
+
# Field Required Type Description
|
100
|
+
# source Required Object The document’s JSON body.
|
101
|
+
# id Optional String A unique document identifier. The identifier cannot be used elsewhere in the index.
|
102
|
+
# index Optional String The index where the document’s transformed data appears.
|
103
|
+
def simulate(docs, verbose: true)
|
104
|
+
self.class.simulate(docs, verbose: verbose)
|
105
|
+
end
|
106
|
+
|
107
|
+
def exists?
|
108
|
+
self.class.exists?
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_hash
|
112
|
+
{
|
113
|
+
description: self.description,
|
114
|
+
processors: self.processors.map(&:to_hash)
|
115
|
+
}.as_json
|
116
|
+
end
|
117
|
+
|
118
|
+
def client
|
119
|
+
@client ||= Stretchy.configuration.client.ingest
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Stretchy::Pipelines
|
2
|
+
# Creates a new processor for a pipeline
|
3
|
+
#
|
4
|
+
# Below is a list of processors that can be used in a pipeline. Each processor has a specific function that can be applied to a document.
|
5
|
+
#
|
6
|
+
# For more information on processors, see the [Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest-processors.html).
|
7
|
+
# or [OpenSearch](https://opensearch.org/docs/latest/ingest-pipelines/processors/index-processors/) documentation.
|
8
|
+
#
|
9
|
+
# | type | Description |
|
10
|
+
# | --- | --- |
|
11
|
+
# | append | Adds one or more values to a field in a document. |
|
12
|
+
# | bytes | Converts a human-readable byte value to its value in bytes. |
|
13
|
+
# | convert | Changes the data type of a field in a document. |
|
14
|
+
# | copy | Copies an entire object in an existing field to another field. |
|
15
|
+
# | csv | Extracts CSVs and stores them as individual fields in a document. |
|
16
|
+
# | date | Parses dates from fields and then uses the date or timestamp as the timestamp for a document. |
|
17
|
+
# | date_index_name | Indexes documents into time-based indexes based on a date or timestamp field in a document. |
|
18
|
+
# | dissect | Extracts structured fields from a text field using a defined pattern. |
|
19
|
+
# | dot_expander | Expands a field with dots into an object field. |
|
20
|
+
# | drop | Drops a document without indexing it or raising any errors. |
|
21
|
+
# | fail | Raises an exception and stops the execution of a pipeline. |
|
22
|
+
# | foreach | Allows for another processor to be applied to each element of an array or an object field in a document. |
|
23
|
+
# | geoip | Adds information about the geographical location of an IP address. |
|
24
|
+
# | geojson-feature | Indexes GeoJSON data into a geospatial field. |
|
25
|
+
# | grok | Parses and structures unstructured data using pattern matching. |
|
26
|
+
# | gsub | Replaces or deletes substrings within a string field of a document. |
|
27
|
+
# | html_strip | Removes HTML tags from a text field and returns the plain text content. |
|
28
|
+
# | ip2geo | Adds information about the geographical location of an IPv4 or IPv6 address. |
|
29
|
+
# | join | Concatenates each element of an array into a single string using a separator character between each element. |
|
30
|
+
# | json | Converts a JSON string into a structured JSON object. |
|
31
|
+
# | kv | Automatically parses key-value pairs in a field. |
|
32
|
+
# | lowercase | Converts text in a specific field to lowercase letters. |
|
33
|
+
# | pipeline | Runs an inner pipeline. |
|
34
|
+
# | remove | Removes fields from a document. |
|
35
|
+
# | script | Runs an inline or stored script on incoming documents. |
|
36
|
+
# | set | Sets the value of a field to a specified value. |
|
37
|
+
# | sort | Sorts the elements of an array in ascending or descending order. |
|
38
|
+
# | sparse_encoding | Generates a sparse vector/token and weights from text fields for neural sparse search using sparse retrieval. |
|
39
|
+
# | split | Splits a field into an array using a separator character. |
|
40
|
+
# | text_embedding | Generates vector embeddings from text fields for semantic search. |
|
41
|
+
# | text_image_embedding | Generates combined vector embeddings from text and image fields for multimodal neural search. |
|
42
|
+
|
43
|
+
class Processor
|
44
|
+
|
45
|
+
attr_reader :type, :opts, :description
|
46
|
+
|
47
|
+
def initialize(type, opts = {})
|
48
|
+
@type = type
|
49
|
+
@description = opts[:description]
|
50
|
+
@opts = opts
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_hash
|
54
|
+
{ type => @opts }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/stretchy/querying.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Stretchy
|
2
2
|
module Querying
|
3
|
-
delegate :
|
4
|
-
delegate :
|
5
|
-
|
6
|
-
delegate *Stretchy::Relations::
|
3
|
+
delegate :exists?, :any?, :many?, :includes, to: :all
|
4
|
+
delegate :rewhere, :eager_load, :create_with, :unscoped, to: :all
|
5
|
+
|
6
|
+
delegate *Stretchy::Relations::FinderMethods::METHODS, to: :all
|
7
|
+
delegate *Stretchy::Relations::SearchOptionMethods::METHODS, to: :all
|
8
|
+
delegate *Stretchy::Relations::QueryMethods.registry, to: :all
|
9
|
+
delegate *Stretchy::Relations::AggregationMethods.registry, to: :all
|
7
10
|
|
8
|
-
delegate :skip_callbacks, :routing, :search_options, to: :all
|
9
|
-
delegate :must, :must_not, :should, :where_not, :where, :filter_query, :query_string, :regexp, to: :all
|
10
11
|
|
11
12
|
def fetch_results(es)
|
12
13
|
if es.count?
|
@@ -16,6 +17,5 @@ module Stretchy
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Rails
|
3
|
+
module Instrumentation
|
4
|
+
module Publishers
|
5
|
+
|
6
|
+
module Record
|
7
|
+
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
unless method_defined?(:search_without_instrumentation!)
|
12
|
+
alias_method :search_without_instrumentation!, :search
|
13
|
+
alias_method :search, :search_with_instrumentation!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def search_with_instrumentation!(query_or_definition, options={})
|
18
|
+
ActiveSupport::Notifications.instrument "search.stretchy",
|
19
|
+
name: "Search",
|
20
|
+
klass: self.base_class.to_s,
|
21
|
+
search: {index: self.index_name, body: query_or_definition }.merge(options) do
|
22
|
+
search_without_instrumentation!(query_or_definition, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,17 +3,21 @@ module Stretchy
|
|
3
3
|
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
5
|
|
6
|
-
|
7
|
-
Stretchy.instrument!
|
6
|
+
require_relative 'publishers'
|
8
7
|
|
9
8
|
ActiveSupport::Notifications.subscribe 'search.stretchy' do |name, start, finish, id, payload|
|
10
9
|
message = [
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
Rainbow(" #{payload[:klass]}").bright,
|
11
|
+
"(#{(finish.to_time - start.to_time).round(2)}ms)",
|
12
|
+
Stretchy::Utils.to_curl(payload[:klass].constantize, payload[:search])
|
14
13
|
].join(" ")
|
15
14
|
::Rails.logger.debug(Rainbow(message).color(:yellow))
|
16
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
initializer 'stretchy.instrumentation' do
|
19
|
+
Stretchy.instrument!
|
20
|
+
end
|
17
21
|
|
18
22
|
# initializer 'stretchy.set_defaults' do
|
19
23
|
# config.elasticsearch_cache_store = :redis_store
|
@@ -21,5 +25,6 @@ module Stretchy
|
|
21
25
|
# end
|
22
26
|
|
23
27
|
end
|
28
|
+
|
24
29
|
end
|
25
30
|
end
|
data/lib/stretchy/record.rb
CHANGED
@@ -16,12 +16,12 @@ module Stretchy
|
|
16
16
|
include ActiveModel::Serializers::JSON
|
17
17
|
|
18
18
|
include Stretchy::Model::Callbacks
|
19
|
+
include Stretchy::Model::Common
|
20
|
+
include Stretchy::Model::Persistence
|
21
|
+
include Stretchy::Model::Refreshable
|
19
22
|
include Stretchy::Indexing::Bulk
|
20
|
-
include Stretchy::Persistence
|
21
23
|
include Stretchy::Associations
|
22
|
-
include Stretchy::
|
23
|
-
include Stretchy::Common
|
24
|
-
include Stretchy::Scoping
|
24
|
+
include Stretchy::Relations::Scoping
|
25
25
|
include Stretchy::Utils
|
26
26
|
include Stretchy::SharedScopes
|
27
27
|
include Stretchy::Attributes
|
@@ -46,6 +46,7 @@ module Stretchy
|
|
46
46
|
def initialize(attributes = {})
|
47
47
|
@highlights = attributes.delete(:_highlights)
|
48
48
|
super(attributes)
|
49
|
+
run_callbacks :initialize
|
49
50
|
end
|
50
51
|
|
51
52
|
end
|