Skip to content

Commit 8bd57df

Browse files
committed
[X-Pack] Adds AsyncSearch API endpoint
1 parent 4bda2c4 commit 8bd57df

File tree

6 files changed

+294
-0
lines changed

6 files changed

+294
-0
lines changed

elasticsearch-xpack/lib/elasticsearch/xpack.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def license
8383
def transform
8484
@transform ||= xpack.transform
8585
end
86+
87+
def async_search
88+
@async_search ||= xpack.async_search
89+
end
8690
end
8791
end
8892
end if defined?(Elasticsearch::Transport::Client)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module AsyncSearch
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :id The async search ID
14+
15+
#
16+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html
17+
#
18+
def delete(arguments = {})
19+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
20+
21+
arguments = arguments.clone
22+
23+
_id = arguments.delete(:id)
24+
25+
method = Elasticsearch::API::HTTP_DELETE
26+
path = "_async_search/#{Elasticsearch::API::Utils.__listify(_id)}"
27+
params = {}
28+
29+
body = nil
30+
perform_request(method, path, params, body).body
31+
end
32+
end
33+
end
34+
end
35+
end
36+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module AsyncSearch
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [String] :id The async search ID
14+
# @option arguments [Time] :wait_for_completion_timeout Specify the time that the request should block waiting for the final response
15+
# @option arguments [Time] :keep_alive Specify the time interval in which the results (partial or final) for this search will be available
16+
# @option arguments [Boolean] :typed_keys Specify whether aggregation and suggester names should be prefixed by their respective types in the response
17+
18+
#
19+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html
20+
#
21+
def get(arguments = {})
22+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
23+
24+
arguments = arguments.clone
25+
26+
_id = arguments.delete(:id)
27+
28+
method = Elasticsearch::API::HTTP_GET
29+
path = "_async_search/#{Elasticsearch::API::Utils.__listify(_id)}"
30+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
31+
32+
body = nil
33+
perform_request(method, path, params, body).body
34+
end
35+
36+
# Register this action with its valid params when the module is loaded.
37+
#
38+
# @since 6.2.0
39+
ParamsRegistry.register(:get, [
40+
:wait_for_completion_timeout,
41+
:keep_alive,
42+
:typed_keys
43+
].freeze)
44+
end
45+
end
46+
end
47+
end
48+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module AsyncSearch
9+
module Actions
10+
module ParamsRegistry
11+
extend self
12+
13+
# A Mapping of all the actions to their list of valid params.
14+
#
15+
# @since 7.4.0
16+
PARAMS = {}
17+
18+
# Register an action with its list of valid params.
19+
#
20+
# @example Register the action.
21+
# ParamsRegistry.register(:benchmark, [ :verbose ])
22+
#
23+
# @param [ Symbol ] action The action to register.
24+
# @param [ Array[Symbol] ] valid_params The list of valid params.
25+
#
26+
# @since 7.4.0
27+
def register(action, valid_params)
28+
PARAMS[action.to_sym] = valid_params
29+
end
30+
31+
# Get the list of valid params for a given action.
32+
#
33+
# @example Get the list of valid params.
34+
# ParamsRegistry.get(:benchmark)
35+
#
36+
# @param [ Symbol ] action The action.
37+
#
38+
# @return [ Array<Symbol> ] The list of valid params for the action.
39+
#
40+
# @since 7.4.0
41+
def get(action)
42+
PARAMS.fetch(action, [])
43+
end
44+
end
45+
end
46+
end
47+
end
48+
end
49+
end
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module AsyncSearch
9+
module Actions
10+
# TODO: Description
11+
12+
#
13+
# @option arguments [List] :index A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices
14+
# @option arguments [Time] :wait_for_completion_timeout Specify the time that the request should block waiting for the final response
15+
# @option arguments [Boolean] :keep_on_completion Control whether the response should be stored in the cluster if it completed within the provided [wait_for_completion] time (default: false)
16+
# @option arguments [Time] :keep_alive Update the time interval in which the results (partial or final) for this search will be available
17+
# @option arguments [Number] :batched_reduce_size The number of shard results that should be reduced at once on the coordinating node. This value should be used as the granularity at which progress results will be made available.
18+
# @option arguments [Boolean] :request_cache Specify if request cache should be used for this request or not, defaults to true
19+
# @option arguments [String] :analyzer The analyzer to use for the query string
20+
# @option arguments [Boolean] :analyze_wildcard Specify whether wildcard and prefix queries should be analyzed (default: false)
21+
# @option arguments [String] :default_operator The default operator for query string query (AND or OR)
22+
# (options: AND,OR)
23+
24+
# @option arguments [String] :df The field to use as default where no field prefix is given in the query string
25+
# @option arguments [Boolean] :explain Specify whether to return detailed information about score computation as part of a hit
26+
# @option arguments [List] :stored_fields A comma-separated list of stored fields to return as part of a hit
27+
# @option arguments [List] :docvalue_fields A comma-separated list of fields to return as the docvalue representation of a field for each hit
28+
# @option arguments [Number] :from Starting offset (default: 0)
29+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
30+
# @option arguments [Boolean] :ignore_throttled Whether specified concrete, expanded or aliased indices should be ignored when throttled
31+
# @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
32+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both.
33+
# (options: open,closed,none,all)
34+
35+
# @option arguments [Boolean] :lenient Specify whether format-based query failures (such as providing text to a numeric field) should be ignored
36+
# @option arguments [String] :preference Specify the node or shard the operation should be performed on (default: random)
37+
# @option arguments [String] :q Query in the Lucene query string syntax
38+
# @option arguments [List] :routing A comma-separated list of specific routing values
39+
# @option arguments [String] :search_type Search operation type
40+
# (options: query_then_fetch,dfs_query_then_fetch)
41+
42+
# @option arguments [Number] :size Number of hits to return (default: 10)
43+
# @option arguments [List] :sort A comma-separated list of <field>:<direction> pairs
44+
# @option arguments [List] :_source True or false to return the _source field or not, or a list of fields to return
45+
# @option arguments [List] :_source_excludes A list of fields to exclude from the returned _source field
46+
# @option arguments [List] :_source_includes A list of fields to extract and return from the _source field
47+
# @option arguments [Number] :terminate_after The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.
48+
# @option arguments [List] :stats Specific 'tag' of the request for logging and statistical purposes
49+
# @option arguments [String] :suggest_field Specify which field to use for suggestions
50+
# @option arguments [String] :suggest_mode Specify suggest mode
51+
# (options: missing,popular,always)
52+
53+
# @option arguments [Number] :suggest_size How many suggestions to return in response
54+
# @option arguments [String] :suggest_text The source text for which the suggestions should be returned
55+
# @option arguments [Time] :timeout Explicit operation timeout
56+
# @option arguments [Boolean] :track_scores Whether to calculate and return scores even if they are not used for sorting
57+
# @option arguments [Boolean] :track_total_hits Indicate if the number of documents that match the query should be tracked
58+
# @option arguments [Boolean] :allow_partial_search_results Indicate if an error should be returned if there is a partial search failure or timeout
59+
# @option arguments [Boolean] :typed_keys Specify whether aggregation and suggester names should be prefixed by their respective types in the response
60+
# @option arguments [Boolean] :version Specify whether to return document version as part of a hit
61+
# @option arguments [Boolean] :seq_no_primary_term Specify whether to return sequence number and primary term of the last modification of each hit
62+
# @option arguments [Number] :max_concurrent_shard_requests The number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests
63+
64+
# @option arguments [Hash] :body The search definition using the Query DSL
65+
#
66+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html
67+
#
68+
def submit(arguments = {})
69+
arguments = arguments.clone
70+
71+
_index = arguments.delete(:index)
72+
73+
method = Elasticsearch::API::HTTP_POST
74+
path = if _index
75+
"#{Elasticsearch::API::Utils.__listify(_index)}/_async_search"
76+
else
77+
"_async_search"
78+
end
79+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
80+
81+
body = arguments[:body]
82+
perform_request(method, path, params, body).body
83+
end
84+
85+
# Register this action with its valid params when the module is loaded.
86+
#
87+
# @since 6.2.0
88+
ParamsRegistry.register(:submit, [
89+
:wait_for_completion_timeout,
90+
:keep_on_completion,
91+
:keep_alive,
92+
:batched_reduce_size,
93+
:request_cache,
94+
:analyzer,
95+
:analyze_wildcard,
96+
:default_operator,
97+
:df,
98+
:explain,
99+
:stored_fields,
100+
:docvalue_fields,
101+
:from,
102+
:ignore_unavailable,
103+
:ignore_throttled,
104+
:allow_no_indices,
105+
:expand_wildcards,
106+
:lenient,
107+
:preference,
108+
:q,
109+
:routing,
110+
:search_type,
111+
:size,
112+
:sort,
113+
:_source,
114+
:_source_excludes,
115+
:_source_includes,
116+
:terminate_after,
117+
:stats,
118+
:suggest_field,
119+
:suggest_mode,
120+
:suggest_size,
121+
:suggest_text,
122+
:timeout,
123+
:track_scores,
124+
:track_total_hits,
125+
:allow_partial_search_results,
126+
:typed_keys,
127+
:version,
128+
:seq_no_primary_term,
129+
:max_concurrent_shard_requests
130+
].freeze)
131+
end
132+
end
133+
end
134+
end
135+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Licensed to Elasticsearch B.V under one or more agreements.
2+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
# See the LICENSE file in the project root for more information
4+
5+
module Elasticsearch
6+
module XPack
7+
module API
8+
module AsyncSearch
9+
module Actions; end
10+
11+
class AsyncSearchClient
12+
include Elasticsearch::API::Common::Client, Elasticsearch::API::Common::Client::Base, AsyncSearch::Actions
13+
end
14+
15+
def async_search
16+
@async_search ||= AsyncSearchClient.new(self)
17+
end
18+
19+
end
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)