stretchy-model 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/README.md +28 -10
- data/Rakefile +56 -0
- data/docs/.nojekyll +0 -0
- data/docs/README.md +147 -0
- data/docs/_coverpage.md +14 -0
- data/docs/_sidebar.md +15 -0
- data/docs/examples/_sidebar.md +15 -0
- data/docs/examples/data_analysis.md +216 -0
- data/docs/examples/neural_search_with_llm.md +381 -0
- data/docs/examples/simple-ingest-pipeline.md +326 -0
- data/docs/guides/_sidebar.md +15 -0
- data/docs/guides/aggregations.md +142 -0
- data/docs/guides/machine-learning.md +154 -0
- data/docs/guides/models.md +372 -0
- data/docs/guides/pipelines.md +151 -0
- data/docs/guides/querying.md +361 -0
- data/docs/guides/quick-start.md +72 -0
- data/docs/guides/scopes.md +125 -0
- data/docs/index.html +113 -0
- data/docs/stretchy.cover.png +0 -0
- data/docs/stretchy.logo.png +0 -0
- data/docs/styles.css +90 -0
- data/lib/elasticsearch/api/actions/connector/check_in.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/delete.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/get.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/last_sync.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/list.rb +60 -0
- data/lib/elasticsearch/api/actions/connector/post.rb +57 -0
- data/lib/elasticsearch/api/actions/connector/put.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_api_key_id.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_configuration.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_error.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_filtering.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_index_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_native.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_pipeline.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_scheduling.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_service_type.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_status.rb +66 -0
- data/lib/elasticsearch/api/namespace/connector.rb +36 -0
- data/lib/opensearch/api/actions/machine_learning/connector/delete.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/get.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/list.rb +38 -0
- data/lib/opensearch/api/actions/machine_learning/connector/post.rb +35 -0
- data/lib/opensearch/api/actions/machine_learning/connector/put.rb +44 -0
- data/lib/opensearch/api/actions/machine_learning/models/predict.rb +32 -0
- data/lib/opensearch/api/namespace/connector.rb +19 -0
- data/lib/stretchy/attributes/transformers/keyword_transformer.rb +41 -35
- data/lib/stretchy/attributes/type/array.rb +24 -1
- data/lib/stretchy/attributes/type/base.rb +6 -2
- data/lib/stretchy/attributes/type/binary.rb +24 -17
- data/lib/stretchy/attributes/type/boolean.rb +29 -22
- data/lib/stretchy/attributes/type/completion.rb +18 -10
- data/lib/stretchy/attributes/type/constant_keyword.rb +35 -26
- data/lib/stretchy/attributes/type/date_time.rb +28 -17
- data/lib/stretchy/attributes/type/dense_vector.rb +46 -49
- data/lib/stretchy/attributes/type/flattened.rb +28 -19
- data/lib/stretchy/attributes/type/geo_point.rb +21 -12
- data/lib/stretchy/attributes/type/geo_shape.rb +21 -12
- data/lib/stretchy/attributes/type/hash.rb +24 -10
- data/lib/stretchy/attributes/type/histogram.rb +25 -0
- data/lib/stretchy/attributes/type/ip.rb +26 -17
- data/lib/stretchy/attributes/type/join.rb +16 -7
- data/lib/stretchy/attributes/type/keyword.rb +21 -26
- data/lib/stretchy/attributes/type/knn_vector.rb +47 -0
- data/lib/stretchy/attributes/type/match_only_text.rb +22 -1
- data/lib/stretchy/attributes/type/nested.rb +16 -11
- data/lib/stretchy/attributes/type/numeric/base.rb +30 -22
- data/lib/stretchy/attributes/type/numeric/byte.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/double.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/half_float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/integer.rb +21 -1
- data/lib/stretchy/attributes/type/numeric/long.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/scaled_float.rb +16 -7
- data/lib/stretchy/attributes/type/numeric/short.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +21 -1
- data/lib/stretchy/attributes/type/percolator.rb +16 -4
- data/lib/stretchy/attributes/type/point.rb +19 -9
- data/lib/stretchy/attributes/type/range/base.rb +24 -1
- data/lib/stretchy/attributes/type/range/date_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/double_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/float_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/integer_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/ip_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/long_range.rb +20 -4
- data/lib/stretchy/attributes/type/rank_feature.rb +16 -6
- data/lib/stretchy/attributes/type/rank_features.rb +16 -9
- data/lib/stretchy/attributes/type/search_as_you_type.rb +28 -18
- data/lib/stretchy/attributes/type/shape.rb +19 -9
- data/lib/stretchy/attributes/type/sparse_vector.rb +25 -21
- data/lib/stretchy/attributes/type/string.rb +42 -1
- data/lib/stretchy/attributes/type/text.rb +53 -28
- data/lib/stretchy/attributes/type/token_count.rb +21 -11
- data/lib/stretchy/attributes/type/version.rb +16 -6
- data/lib/stretchy/attributes/type/wildcard.rb +36 -25
- data/lib/stretchy/attributes.rb +29 -0
- data/lib/stretchy/delegation/gateway_delegation.rb +78 -0
- data/lib/stretchy/index_setting.rb +94 -0
- data/lib/stretchy/indexing/bulk.rb +75 -3
- data/lib/stretchy/machine_learning/connector.rb +130 -0
- data/lib/stretchy/machine_learning/errors.rb +25 -0
- data/lib/stretchy/machine_learning/model.rb +162 -109
- data/lib/stretchy/machine_learning/registry.rb +19 -0
- data/lib/stretchy/model/callbacks.rb +1 -0
- data/lib/stretchy/model/common.rb +157 -0
- data/lib/stretchy/model/persistence.rb +144 -0
- data/lib/stretchy/model/refreshable.rb +26 -0
- data/lib/stretchy/open_search_compatibility.rb +2 -0
- data/lib/stretchy/pipeline.rb +2 -1
- data/lib/stretchy/pipelines/processor.rb +40 -36
- data/lib/stretchy/querying.rb +7 -8
- data/lib/stretchy/rails/railtie.rb +11 -0
- data/lib/stretchy/rails/tasks/connector/create.rake +32 -0
- data/lib/stretchy/rails/tasks/connector/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/connector/status.rake +31 -0
- data/lib/stretchy/rails/tasks/connector/update.rake +32 -0
- data/lib/stretchy/rails/tasks/index/create.rake +28 -0
- data/lib/stretchy/rails/tasks/index/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/index/status.rake +23 -0
- data/lib/stretchy/rails/tasks/ml/delete.rake +25 -0
- data/lib/stretchy/rails/tasks/ml/deploy.rake +78 -0
- data/lib/stretchy/rails/tasks/ml/status.rake +31 -0
- data/lib/stretchy/rails/tasks/pipeline/create.rake +27 -0
- data/lib/stretchy/rails/tasks/pipeline/delete.rake +26 -0
- data/lib/stretchy/rails/tasks/pipeline/status.rake +25 -0
- data/lib/stretchy/rails/tasks/status.rake +15 -0
- data/lib/stretchy/rails/tasks/stretchy.rake +42 -0
- data/lib/stretchy/record.rb +5 -4
- data/lib/stretchy/relation.rb +229 -28
- data/lib/stretchy/relations/aggregation_methods/aggregation.rb +59 -0
- data/lib/stretchy/relations/aggregation_methods/avg.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_script.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_selector.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_sort.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/cardinality.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/children.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/composite.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/date_histogram.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/date_range.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/extended_stats.rb +48 -0
- data/lib/stretchy/relations/aggregation_methods/filter.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/filters.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/geo_bounds.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/geo_centroid.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/global.rb +39 -0
- data/lib/stretchy/relations/aggregation_methods/histogram.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/ip_range.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/max.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/min.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/missing.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/percentile_ranks.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/percentiles.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/range.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/reverse_nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/sampler.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/scripted_metric.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/significant_terms.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/stats.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/sum.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/terms.rb +46 -0
- data/lib/stretchy/relations/aggregation_methods/top_hits.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/top_metrics.rb +44 -0
- data/lib/stretchy/relations/aggregation_methods/value_count.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/weighted_avg.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods.rb +20 -749
- data/lib/stretchy/relations/finder_methods.rb +2 -18
- data/lib/stretchy/relations/null_relation.rb +55 -0
- data/lib/stretchy/relations/query_builder.rb +82 -36
- data/lib/stretchy/relations/query_methods/bind.rb +19 -0
- data/lib/stretchy/relations/query_methods/extending.rb +29 -0
- data/lib/stretchy/relations/query_methods/fields.rb +70 -0
- data/lib/stretchy/relations/query_methods/filter_query.rb +53 -0
- data/lib/stretchy/relations/query_methods/has_field.rb +40 -0
- data/lib/stretchy/relations/query_methods/highlight.rb +75 -0
- data/lib/stretchy/relations/query_methods/hybrid.rb +60 -0
- data/lib/stretchy/relations/query_methods/ids.rb +40 -0
- data/lib/stretchy/relations/query_methods/match.rb +52 -0
- data/lib/stretchy/relations/query_methods/must_not.rb +54 -0
- data/lib/stretchy/relations/query_methods/neural.rb +58 -0
- data/lib/stretchy/relations/query_methods/neural_sparse.rb +43 -0
- data/lib/stretchy/relations/query_methods/none.rb +21 -0
- data/lib/stretchy/relations/query_methods/or_filter.rb +21 -0
- data/lib/stretchy/relations/query_methods/order.rb +63 -0
- data/lib/stretchy/relations/query_methods/query_string.rb +44 -0
- data/lib/stretchy/relations/query_methods/regexp.rb +61 -0
- data/lib/stretchy/relations/query_methods/should.rb +51 -0
- data/lib/stretchy/relations/query_methods/size.rb +44 -0
- data/lib/stretchy/relations/query_methods/skip_callbacks.rb +47 -0
- data/lib/stretchy/relations/query_methods/source.rb +59 -0
- data/lib/stretchy/relations/query_methods/where.rb +113 -0
- data/lib/stretchy/relations/query_methods.rb +48 -569
- data/lib/stretchy/relations/scoping/default.rb +136 -0
- data/lib/stretchy/relations/scoping/named.rb +70 -0
- data/lib/stretchy/relations/scoping/scope_registry.rb +36 -0
- data/lib/stretchy/relations/scoping.rb +30 -0
- data/lib/stretchy/relations/search_option_methods.rb +2 -0
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +24 -10
- metadata +170 -17
- data/lib/stretchy/common.rb +0 -38
- data/lib/stretchy/null_relation.rb +0 -53
- data/lib/stretchy/persistence.rb +0 -43
- data/lib/stretchy/refreshable.rb +0 -15
- data/lib/stretchy/scoping/default.rb +0 -134
- data/lib/stretchy/scoping/named.rb +0 -68
- data/lib/stretchy/scoping/scope_registry.rb +0 -34
- data/lib/stretchy/scoping.rb +0 -28
@@ -0,0 +1,42 @@
|
|
1
|
+
module OpenSearch
|
2
|
+
module API
|
3
|
+
module Connector
|
4
|
+
module Actions
|
5
|
+
# Deletes a connector.
|
6
|
+
# This functionality is Experimental and may be changed or removed
|
7
|
+
# completely in a future release. Elastic will take a best effort approach
|
8
|
+
# to fix any issues, but experimental features are not subject to the
|
9
|
+
# support SLA of official GA features.
|
10
|
+
#
|
11
|
+
# @option arguments [String] :connector_id The unique identifier of the connector to be deleted.
|
12
|
+
# @option arguments [Hash] :headers Custom HTTP headers
|
13
|
+
#
|
14
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.13/delete-connector-api.html
|
15
|
+
#
|
16
|
+
def delete(arguments = {})
|
17
|
+
request_opts = { endpoint: arguments[:endpoint] || 'connector.delete' }
|
18
|
+
|
19
|
+
defined_params = [:connector_id].each_with_object({}) do |variable, set_variables|
|
20
|
+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
|
21
|
+
end
|
22
|
+
request_opts[:defined_params] = defined_params unless defined_params.empty?
|
23
|
+
|
24
|
+
raise ArgumentError, "Required argument 'connector_id' missing" unless arguments[:connector_id]
|
25
|
+
|
26
|
+
arguments = arguments.clone
|
27
|
+
headers = arguments.delete(:headers) || {}
|
28
|
+
|
29
|
+
body = nil
|
30
|
+
|
31
|
+
_connector_id = arguments.delete(:connector_id)
|
32
|
+
|
33
|
+
method = OpenSearch::API::HTTP_DELETE
|
34
|
+
path = "_plugins/_ml/connectors/#{Utils.__listify(_connector_id)}"
|
35
|
+
params = {}
|
36
|
+
|
37
|
+
perform_request(method, path, params, body, headers).body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module OpenSearch
|
2
|
+
module API
|
3
|
+
module Connector
|
4
|
+
module Actions
|
5
|
+
# Returns the details about a connector.
|
6
|
+
# This functionality is Experimental and may be changed or removed
|
7
|
+
# completely in a future release. Elastic will take a best effort approach
|
8
|
+
# to fix any issues, but experimental features are not subject to the
|
9
|
+
# support SLA of official GA features.
|
10
|
+
#
|
11
|
+
# @option arguments [String] :connector_id The unique identifier of the connector to be returned.
|
12
|
+
# @option arguments [Hash] :headers Custom HTTP headers
|
13
|
+
#
|
14
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.13/get-connector-api.html
|
15
|
+
#
|
16
|
+
def get(arguments = {})
|
17
|
+
request_opts = { endpoint: arguments[:endpoint] || 'connector.get' }
|
18
|
+
|
19
|
+
defined_params = [:connector_id].each_with_object({}) do |variable, set_variables|
|
20
|
+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
|
21
|
+
end
|
22
|
+
request_opts[:defined_params] = defined_params unless defined_params.empty?
|
23
|
+
|
24
|
+
raise ArgumentError, "Required argument 'connector_id' missing" unless arguments[:connector_id]
|
25
|
+
|
26
|
+
arguments = arguments.clone
|
27
|
+
headers = arguments.delete(:headers) || {}
|
28
|
+
|
29
|
+
body = nil
|
30
|
+
|
31
|
+
_connector_id = arguments.delete(:connector_id)
|
32
|
+
|
33
|
+
method = OpenSearch::API::HTTP_GET
|
34
|
+
path = "_plugins/_ml/connectors/#{Utils.__listify(_connector_id)}"
|
35
|
+
params = {}
|
36
|
+
|
37
|
+
perform_request(method, path, params, body, headers).body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module OpenSearch
|
2
|
+
module API
|
3
|
+
module Connector
|
4
|
+
module Actions
|
5
|
+
# Lists all connectors.
|
6
|
+
# This functionality is Experimental and may be changed or removed
|
7
|
+
# completely in a future release. Elastic will take a best effort approach
|
8
|
+
# to fix any issues, but experimental features are not subject to the
|
9
|
+
# support SLA of official GA features.
|
10
|
+
#
|
11
|
+
# @option arguments [Integer] :from Starting offset (default: 0)
|
12
|
+
# @option arguments [Integer] :size Specifies a max number of results to get (default: 100)
|
13
|
+
# @option arguments [List] :index_name A comma-separated list of connector index names to fetch connector documents for
|
14
|
+
# @option arguments [List] :connector_name A comma-separated list of connector names to fetch connector documents for
|
15
|
+
# @option arguments [List] :service_type A comma-separated list of connector service types to fetch connector documents for
|
16
|
+
# @option arguments [String] :query A search string for querying connectors, filtering results by matching against connector names, descriptions, and index names
|
17
|
+
# @option arguments [Hash] :headers Custom HTTP headers
|
18
|
+
#
|
19
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.13/list-connector-api.html
|
20
|
+
#
|
21
|
+
def list(arguments = {})
|
22
|
+
request_opts = { endpoint: arguments[:endpoint] || 'connector.list' }
|
23
|
+
|
24
|
+
arguments = arguments.clone
|
25
|
+
headers = arguments.delete(:headers) || {}
|
26
|
+
|
27
|
+
body = nil
|
28
|
+
|
29
|
+
method = OpenSearch::API::HTTP_GET
|
30
|
+
path = '_plugins/_ml/connectors'
|
31
|
+
params = Utils.process_params(arguments)
|
32
|
+
|
33
|
+
perform_request(method, path, params, body, headers).body
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module OpenSearch
|
2
|
+
module API
|
3
|
+
module Connector
|
4
|
+
module Actions
|
5
|
+
# Creates a connector.
|
6
|
+
# This functionality is Experimental and may be changed or removed
|
7
|
+
# completely in a future release. Elastic will take a best effort approach
|
8
|
+
# to fix any issues, but experimental features are not subject to the
|
9
|
+
# support SLA of official GA features.
|
10
|
+
#
|
11
|
+
# @option arguments [Hash] :headers Custom HTTP headers
|
12
|
+
# @option arguments [Hash] :body The connector configuration. (*Required*)
|
13
|
+
#
|
14
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.13/create-connector-api.html
|
15
|
+
#
|
16
|
+
def post(arguments = {})
|
17
|
+
request_opts = { endpoint: arguments[:endpoint] || 'connector.post' }
|
18
|
+
|
19
|
+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
|
20
|
+
|
21
|
+
arguments = arguments.clone
|
22
|
+
headers = arguments.delete(:headers) || {}
|
23
|
+
|
24
|
+
body = arguments.delete(:body)
|
25
|
+
|
26
|
+
method = OpenSearch::API::HTTP_POST
|
27
|
+
path = '_plugins/_ml/connectors/_create'
|
28
|
+
params = {}
|
29
|
+
|
30
|
+
perform_request(method, path, params, body, headers).body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module OpenSearch
|
2
|
+
module API
|
3
|
+
module Connector
|
4
|
+
module Actions
|
5
|
+
# Creates or updates a connector.
|
6
|
+
# This functionality is Experimental and may be changed or removed
|
7
|
+
# completely in a future release. Elastic will take a best effort approach
|
8
|
+
# to fix any issues, but experimental features are not subject to the
|
9
|
+
# support SLA of official GA features.
|
10
|
+
#
|
11
|
+
# @option arguments [String] :connector_id The unique identifier of the connector to be created or updated.
|
12
|
+
# @option arguments [Hash] :headers Custom HTTP headers
|
13
|
+
# @option arguments [Hash] :body The connector configuration. (*Required*)
|
14
|
+
#
|
15
|
+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.13/create-connector-api.html
|
16
|
+
#
|
17
|
+
def put(arguments = {})
|
18
|
+
request_opts = { endpoint: arguments[:endpoint] || 'connector.put' }
|
19
|
+
|
20
|
+
defined_params = [:connector_id].each_with_object({}) do |variable, set_variables|
|
21
|
+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
|
22
|
+
end
|
23
|
+
request_opts[:defined_params] = defined_params unless defined_params.empty?
|
24
|
+
|
25
|
+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
|
26
|
+
raise ArgumentError, "Required argument 'connector_id' missing" unless arguments[:connector_id]
|
27
|
+
|
28
|
+
arguments = arguments.clone
|
29
|
+
headers = arguments.delete(:headers) || {}
|
30
|
+
|
31
|
+
body = arguments.delete(:body)
|
32
|
+
|
33
|
+
_connector_id = arguments.delete(:connector_id)
|
34
|
+
|
35
|
+
method = OpenSearch::API::HTTP_PUT
|
36
|
+
path = "_plugins/_ml/connectors/#{Utils.__listify(_connector_id)}"
|
37
|
+
params = {}
|
38
|
+
|
39
|
+
perform_request(method, path, params, body, headers).body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module OpenSearch
|
2
|
+
module API
|
3
|
+
module MachineLearning
|
4
|
+
module Models
|
5
|
+
module Actions
|
6
|
+
# Register a model.
|
7
|
+
#
|
8
|
+
# @option arguments [String] :model_id The model id
|
9
|
+
# @option arguments [Hash] :body The deploy options
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# POST /_plugins/_ml/models/<model_id>/_predict
|
13
|
+
def predict(arguments = {})
|
14
|
+
raise ArgumentError, "Required argument 'model_id' missing" unless arguments[:model_id]
|
15
|
+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
|
16
|
+
_id = arguments.delete(:model_id)
|
17
|
+
arguments = arguments.clone
|
18
|
+
headers = arguments.delete(:headers) || {}
|
19
|
+
|
20
|
+
method = OpenSearch::API::HTTP_POST
|
21
|
+
path = "_plugins/_ml/models/#{Utils.__listify(_id)}/_predict"
|
22
|
+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
|
23
|
+
|
24
|
+
body = arguments[:body]
|
25
|
+
perform_request(method, path, params, body, headers).body
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module OpenSearch
|
2
|
+
module API
|
3
|
+
module Connector
|
4
|
+
module Actions; end
|
5
|
+
|
6
|
+
# Client for the "connector" namespace (includes the {Connector::Actions} methods)
|
7
|
+
#
|
8
|
+
class ConnectorClient
|
9
|
+
include Common::Client, Common::Client::Base, Connector::Actions
|
10
|
+
end
|
11
|
+
|
12
|
+
# Proxy method for {ConnectorClient}, available in the receiving object
|
13
|
+
#
|
14
|
+
def connector
|
15
|
+
@connector ||= ConnectorClient.new(self)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,6 +1,20 @@
|
|
1
1
|
module Stretchy
|
2
2
|
module Attributes
|
3
3
|
module Transformers
|
4
|
+
# Applies transformations to keyword fields in queries
|
5
|
+
#
|
6
|
+
# ### Examples
|
7
|
+
#
|
8
|
+
# ```ruby
|
9
|
+
# class Goat < StretchyModel
|
10
|
+
# attribute :name, :keyword
|
11
|
+
# attribute :age, :integer
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Goat.where(name: 'billy').to_elastic
|
15
|
+
# # => {query: {term: {'name.keyword': 'billy'}}}
|
16
|
+
#
|
17
|
+
# ```
|
4
18
|
class KeywordTransformer
|
5
19
|
|
6
20
|
KEYWORD_AGGREGATION_KEYS = [:terms, :rare_terms, :significant_terms, :cardinality, :string_stats]
|
@@ -24,61 +38,53 @@ module Stretchy
|
|
24
38
|
end
|
25
39
|
end
|
26
40
|
|
27
|
-
def
|
28
|
-
|
29
|
-
return false unless
|
30
|
-
|
41
|
+
def keyword_available?(arg)
|
42
|
+
attrib = @attribute_types[arg.to_s.split(".").first]
|
43
|
+
return false unless attrib
|
44
|
+
attrib.respond_to?(:keyword_field?) && attrib.keyword_field?
|
45
|
+
end
|
46
|
+
|
47
|
+
def keyword_field_for(arg)
|
48
|
+
attrib = @attribute_types[arg.to_s.split(".").first]
|
49
|
+
keyword_field = attrib.respond_to?(:fields) ? attrib.fields.find { |k,d| d[:type].to_sym == :keyword }&.first : nil
|
50
|
+
keyword_field || Stretchy.configuration.default_keyword_field
|
31
51
|
end
|
32
52
|
|
33
53
|
def protected?(arg)
|
34
54
|
return false if arg.nil?
|
35
|
-
Stretchy::Relations::AggregationMethods
|
55
|
+
Stretchy::Relations::AggregationMethods.registry.include?(arg.to_sym)
|
36
56
|
end
|
37
57
|
|
58
|
+
# Add `.keyword` to attributes that have a keyword subfield but aren't `:keywords`
|
59
|
+
# this is for text fields that have a keyword subfield
|
60
|
+
# `:text` and `:string` fields add a `:keyword` subfield to the attribute mapping automatically
|
38
61
|
def transform(item, *ignore)
|
39
|
-
item
|
40
|
-
|
41
|
-
|
62
|
+
return item unless Stretchy.configuration.auto_target_keywords
|
63
|
+
if item.is_a?(String)
|
64
|
+
return (!protected?(item) && keyword_available?(item)) ? "#{item}.#{keyword_field_for(item)}" : item
|
65
|
+
end
|
66
|
+
item.each_with_object({}) do |(key, value), new_item|
|
67
|
+
if ignore && ignore.include?(key)
|
68
|
+
new_item[key] = value
|
42
69
|
next
|
43
70
|
end
|
44
|
-
new_key = (!protected?(k) && keyword?(k)) ? "#{k}.keyword" : k
|
45
71
|
|
46
|
-
|
72
|
+
new_key = (!protected?(key) && keyword_available?(key)) ? "#{key}.#{keyword_field_for(key)}" : key
|
73
|
+
|
74
|
+
new_value = value
|
47
75
|
|
48
76
|
if new_value.is_a?(Hash)
|
49
|
-
new_value = transform(new_value)
|
77
|
+
new_value = transform(new_value, *ignore)
|
50
78
|
elsif new_value.is_a?(Array)
|
51
|
-
new_value = new_value.map { |i| i.is_a?(Hash) ? transform(i) : i }
|
79
|
+
new_value = new_value.map { |i| i.is_a?(Hash) ? transform(i, *ignore) : i }
|
52
80
|
elsif new_value.is_a?(String) || new_value.is_a?(Symbol)
|
53
|
-
new_value = "#{new_value}
|
81
|
+
new_value = "#{new_value}.#{keyword_field_for(new_value)}" if keyword_available?(new_value) && new_value.to_s !~ Regexp.new("\.#{keyword_field_for(new_value)}$")
|
54
82
|
end
|
55
83
|
|
56
84
|
new_item[new_key] = new_value
|
57
85
|
end
|
58
86
|
end
|
59
87
|
|
60
|
-
# If terms are used, we assume that the field is a keyword field
|
61
|
-
# and append .keyword to the field name
|
62
|
-
# {terms: {field: 'gender'}}
|
63
|
-
# or nested aggs
|
64
|
-
# {terms: {field: 'gender'}, aggs: {name: {terms: {field: 'position.name'}}}}
|
65
|
-
# should be converted to
|
66
|
-
# {terms: {field: 'gender.keyword'}, aggs: {name: {terms: {field: 'position.name.keyword'}}}}
|
67
|
-
# {date_histogram: {field: 'created_at', interval: 'day'}}
|
68
|
-
# TODO: There may be cases where we don't want to add .keyword to the field and there should be a way to override this
|
69
|
-
def assume_keyword_field(args={}, parent_match=false)
|
70
|
-
if args.is_a?(Hash)
|
71
|
-
args.each do |k, v|
|
72
|
-
if v.is_a?(Hash)
|
73
|
-
assume_keyword_field(v, KEYWORD_AGGREGATION_FIELDS.include?(k))
|
74
|
-
else
|
75
|
-
next unless v.is_a?(String) || v.is_a?(Symbol)
|
76
|
-
args[k] = ([:field, :fields].include?(k.to_sym) && v !~ /\.keyword$/ && parent_match) ? "#{v}.keyword" : v.to_s
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
88
|
end
|
83
89
|
end
|
84
90
|
end
|
@@ -1,5 +1,28 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
|
2
|
+
# The Array attribute type
|
3
|
+
#
|
4
|
+
# This class is used to define an array attribute for a model. It provides support for the Elasticsearch array data type, which is a type of data type that can hold multiple values.
|
5
|
+
#
|
6
|
+
# ### Parameters
|
7
|
+
#
|
8
|
+
# - `type:` `:array`.
|
9
|
+
# - `options:` The Hash of options for the attribute.
|
10
|
+
# - `:data_type:` The Symbol representing the data type for the array. Defaults to `:text`.
|
11
|
+
# - `:fields:` The Boolean indicating if fields should be included in the mapping. Defaults to `true`.
|
12
|
+
#
|
13
|
+
# ---
|
14
|
+
#
|
15
|
+
# ### Examples
|
16
|
+
#
|
17
|
+
# #### Define an array attribute
|
18
|
+
#
|
19
|
+
# ```ruby
|
20
|
+
# class MyModel < StretchyModel
|
21
|
+
# attribute :tags, :array, data_type: :text
|
22
|
+
# end
|
23
|
+
# ```
|
24
|
+
#
|
25
|
+
class Array < Stretchy::Attributes::Type::Base
|
3
26
|
OPTIONS = [:data_type, :fields]
|
4
27
|
def type
|
5
28
|
:array
|
@@ -5,7 +5,6 @@ module Stretchy
|
|
5
5
|
|
6
6
|
OPTIONS = []
|
7
7
|
|
8
|
-
|
9
8
|
def initialize(**args)
|
10
9
|
|
11
10
|
define_option_methods!
|
@@ -13,11 +12,16 @@ module Stretchy
|
|
13
12
|
args.each do |k, v|
|
14
13
|
if self.class::OPTIONS.include?(k)
|
15
14
|
instance_variable_set("@#{k}", v)
|
16
|
-
args.delete(k)
|
17
15
|
end
|
16
|
+
args.delete(k)
|
18
17
|
end
|
19
18
|
super
|
20
19
|
end
|
20
|
+
|
21
|
+
def keyword_field?
|
22
|
+
return false unless respond_to? :fields
|
23
|
+
fields.present? && fields.include?(:keyword)
|
24
|
+
end
|
21
25
|
|
22
26
|
def mappings(name)
|
23
27
|
options = {type: type_for_database}
|
@@ -1,23 +1,30 @@
|
|
1
|
-
# Public: Defines a binary attribute for the model.
|
2
|
-
#
|
3
|
-
# name - The Symbol name of the attribute.
|
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.
|
6
|
-
# This allows it to be used later for sorting, aggregations, or scripting. Defaults to false.
|
7
|
-
# :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
8
|
-
#
|
9
|
-
# Examples
|
10
|
-
#
|
11
|
-
# class MyModel
|
12
|
-
# include StretchyModel
|
13
|
-
# attribute :name, :binary, doc_values: true, store: true
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# Returns nothing.
|
17
1
|
module Stretchy
|
18
2
|
module Attributes
|
19
3
|
module Type
|
20
|
-
|
4
|
+
# The Binary attribute type
|
5
|
+
#
|
6
|
+
# This class is used to define a binary attribute for a model. It provides support for the Elasticsearch binary data type, which is a type of data type that can hold binary data.
|
7
|
+
#
|
8
|
+
# ### Parameters
|
9
|
+
#
|
10
|
+
# - `type:` `:binary`.
|
11
|
+
# - `options:` The Hash of options for the attribute.
|
12
|
+
# - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. This allows it to be used later for sorting, aggregations, or scripting. Defaults to false.
|
13
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
14
|
+
#
|
15
|
+
# ---
|
16
|
+
#
|
17
|
+
# ### Examples
|
18
|
+
#
|
19
|
+
# #### Define a binary attribute
|
20
|
+
#
|
21
|
+
# ```ruby
|
22
|
+
# class MyModel < StretchyModel
|
23
|
+
# attribute :data, :binary, doc_values: true, store: true
|
24
|
+
# end
|
25
|
+
# ```
|
26
|
+
#
|
27
|
+
class Binary < Stretchy::Attributes::Type::Base
|
21
28
|
OPTIONS = [:doc_values, :store]
|
22
29
|
attr_reader *OPTIONS
|
23
30
|
|
@@ -1,28 +1,35 @@
|
|
1
|
-
# Public: Defines a boolean attribute for the model.
|
2
|
-
#
|
3
|
-
# name - The Symbol name of the attribute.
|
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.
|
6
|
-
# This allows it to be used later for sorting, aggregations, or scripting. Defaults to true.
|
7
|
-
# :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
8
|
-
# :ignore_malformed - The Boolean indicating if exceptions thrown when trying to index the wrong data type into a field should be ignored. Defaults to false.
|
9
|
-
# :null_value - The Boolean value to be substituted for any explicit null values. Defaults to null.
|
10
|
-
# :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'.
|
11
|
-
# :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
|
12
|
-
# :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
13
|
-
# :meta - The Hash metadata about the field.
|
14
|
-
#
|
15
|
-
# Examples
|
16
|
-
#
|
17
|
-
# class MyModel
|
18
|
-
# include StretchyModel
|
19
|
-
# attribute :name, :boolean, doc_values: true, store: true
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# Returns nothing.
|
23
1
|
module Stretchy
|
24
2
|
module Attributes
|
25
3
|
module Type
|
4
|
+
# The Boolean attribute type
|
5
|
+
#
|
6
|
+
# This class is used to define a boolean attribute for a model. It provides support for the Elasticsearch boolean data type, which is a type of data type that can hold true or false values.
|
7
|
+
#
|
8
|
+
# ### Parameters
|
9
|
+
#
|
10
|
+
# - `type:` `:boolean`.
|
11
|
+
# - `options:` The Hash of options for the attribute.
|
12
|
+
# - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. This allows it to be used later for sorting, aggregations, or scripting. Defaults to true.
|
13
|
+
# - `:index:` The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
14
|
+
# - `:ignore_malformed:` The Boolean indicating if exceptions thrown when trying to index the wrong data type into a field should be ignored. Defaults to false.
|
15
|
+
# - `:null_value:` The Boolean value to be substituted for any explicit null values. Defaults to null.
|
16
|
+
# - `: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'.
|
17
|
+
# - `:script:` The String script that will index values generated by this script, rather than reading the values directly from the source.
|
18
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
19
|
+
# - `:meta:` The Hash metadata about the field.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
#
|
23
|
+
# ### Examples
|
24
|
+
#
|
25
|
+
# #### Define a boolean attribute
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# class MyModel < StretchyModel
|
29
|
+
# attribute :is_active, :boolean, doc_values: true, store: true
|
30
|
+
# end
|
31
|
+
# ```
|
32
|
+
#
|
26
33
|
class Boolean < Stretchy::Attributes::Type::Base
|
27
34
|
|
28
35
|
OPTIONS = [:doc_values, :index, :ignore_malformed, :null_value, :on_script_error, :script, :store, :meta]
|
@@ -1,20 +1,28 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
2
|
+
# Completion attribute type for Elasticsearch completion suggester.
|
3
3
|
#
|
4
|
-
#
|
5
|
-
# :analyzer - The String index analyzer to use. Defaults to 'simple'.
|
6
|
-
# :search_analyzer - The String search analyzer to use. Defaults to the value of :analyzer.
|
7
|
-
# :preserve_separators - The Boolean indicating if separators should be preserved. Defaults to true.
|
8
|
-
# :preserve_position_increments - The Boolean indicating if position increments should be enabled. Defaults to true.
|
9
|
-
# :max_input_length - The Integer limit for the length of a single input. Defaults to 50.
|
4
|
+
# This class is used to define a completion attribute for a model. It provides support for the Elasticsearch completion suggester, which is a type of suggester that provides auto-complete functionality.
|
10
5
|
#
|
11
|
-
#
|
6
|
+
# ### Parameters
|
12
7
|
#
|
13
|
-
#
|
8
|
+
# - `analyzer:` The String index analyzer to use. Defaults to 'simple'.
|
9
|
+
# - `search_analyzer:` The String search analyzer to use. Defaults to the value of `analyzer`.
|
10
|
+
# - `preserve_separators:` The Boolean indicating if separators should be preserved. Defaults to true.
|
11
|
+
# - `preserve_position_increments:` The Boolean indicating if position increments should be enabled. Defaults to true.
|
12
|
+
# - `max_input_length:` The Integer limit for the length of a single input. Defaults to 50.
|
13
|
+
#
|
14
|
+
# ---
|
15
|
+
#
|
16
|
+
# ### Examples
|
17
|
+
#
|
18
|
+
# #### Define a completion attribute
|
19
|
+
#
|
20
|
+
# ```ruby
|
21
|
+
# class MyModel < StretchyModel
|
14
22
|
# attribute :name, :completion, analyzer: 'simple', max_input_length: 100
|
15
23
|
# end
|
24
|
+
# ```
|
16
25
|
#
|
17
|
-
# Returns nothing.
|
18
26
|
class Completion < Stretchy::Attributes::Type::Base
|
19
27
|
OPTIONS = [:analyzer, :search_analyzer, :preserve_separators, :preserve_position_increments, :max_input_length]
|
20
28
|
attr_reader *OPTIONS
|
@@ -1,33 +1,42 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
2
|
+
# The ConstantKeyword attribute type
|
3
|
+
#
|
4
|
+
# This class is used to define a constant_keyword attribute for a model. This field type is a specialization of the keyword field, but it only accepts a single value.
|
5
|
+
#
|
6
|
+
# ### Parameters
|
7
|
+
#
|
8
|
+
# - `type:` `:constant_keyword`.
|
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
|
+
# - `:eager_global_ordinals:` The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
|
12
|
+
# - `:fields:` The Hash of multi-fields for the same string value to be indexed in multiple ways.
|
13
|
+
# - `:ignore_above:` The Integer limit for the length of the string. Strings longer than this limit will not be indexed. Defaults to 2147483647.
|
14
|
+
# - `:index:` The Boolean indicating if the field should be quickly 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
|
+
# - `:meta:` The Hash metadata about the field.
|
17
|
+
# - `:norms:` The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to false.
|
18
|
+
# - `:null_value:` The String value to be substituted for any explicit null values. Defaults to null.
|
19
|
+
# - `: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'.
|
20
|
+
# - `:script:` The String script that will index values generated by this script, rather than reading the values directly from the source.
|
21
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
22
|
+
# - `:similarity:` The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
|
23
|
+
# - `:normalizer:` The String pre-processor for the keyword prior to indexing. Defaults to null.
|
24
|
+
# - `:split_queries_on_whitespace:` The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
|
25
|
+
# - `:time_series_dimension:` The Boolean indicating if the field is a time series dimension. Defaults to false.
|
26
|
+
# - `:value:` The String value to associate with all documents in the index.
|
27
|
+
#
|
28
|
+
# ---
|
29
|
+
#
|
30
|
+
# ### Examples
|
31
|
+
#
|
32
|
+
# #### Define a constant_keyword attribute
|
33
|
+
#
|
34
|
+
# ```ruby
|
35
|
+
# class MyModel < StretchyModel
|
27
36
|
# attribute :status, :constant_keyword, value: 'active'
|
28
37
|
# end
|
38
|
+
# ```
|
29
39
|
#
|
30
|
-
# Returns nothing.
|
31
40
|
class ConstantKeyword < Stretchy::Attributes::Type::Keyword
|
32
41
|
OPTIONS = OPTIONS + [:value]
|
33
42
|
attr_reader *OPTIONS
|