Skip to content

Commit cab4520

Browse files
committed
[XPACK] Adds searchable snapshots endpoints
1 parent 3eed594 commit cab4520

File tree

7 files changed

+336
-0
lines changed

7 files changed

+336
-0
lines changed

elasticsearch-xpack/lib/elasticsearch/xpack.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def cat
108108
def indices
109109
@indices ||= xpack.indices
110110
end
111+
112+
def searchable_snapshots
113+
@searchable_snapshots ||= xpack.searchable_snapshots
114+
end
111115
end
112116
end
113117
end if defined?(Elasticsearch::Transport::Client)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SearchableSnapshots
22+
module Actions
23+
# Clear the cache of searchable snapshots.
24+
#
25+
# @option arguments [List] :index A comma-separated list of index names
26+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
27+
# @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)
28+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both.
29+
# (options: open,closed,none,all)
30+
31+
# @option arguments [List] :index A comma-separated list of index name to limit the operation
32+
# @option arguments [Hash] :headers Custom HTTP headers
33+
#
34+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/searchable-snapshots-api-clear-cache.html
35+
#
36+
def clear_cache(arguments = {})
37+
headers = arguments.delete(:headers) || {}
38+
39+
arguments = arguments.clone
40+
41+
_index = arguments.delete(:index)
42+
43+
method = Elasticsearch::API::HTTP_POST
44+
path = if _index
45+
"#{Elasticsearch::API::Utils.__listify(_index)}/_searchable_snapshots/cache/clear"
46+
else
47+
"_searchable_snapshots/cache/clear"
48+
end
49+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
50+
51+
body = nil
52+
perform_request(method, path, params, body, headers).body
53+
end
54+
55+
# Register this action with its valid params when the module is loaded.
56+
#
57+
# @since 6.2.0
58+
ParamsRegistry.register(:clear_cache, [
59+
:ignore_unavailable,
60+
:allow_no_indices,
61+
:expand_wildcards,
62+
:index
63+
].freeze)
64+
end
65+
end
66+
end
67+
end
68+
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SearchableSnapshots
22+
module Actions
23+
# Mount a snapshot as a searchable index.
24+
#
25+
# @option arguments [String] :repository The name of the repository containing the snapshot of the index to mount
26+
# @option arguments [String] :snapshot The name of the snapshot of the index to mount
27+
# @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
28+
# @option arguments [Boolean] :wait_for_completion Should this request wait until the operation has completed before returning
29+
# @option arguments [Hash] :headers Custom HTTP headers
30+
# @option arguments [Hash] :body The restore configuration for mounting the snapshot as searchable (*Required*)
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/searchable-snapshots-api-mount-snapshot.html
33+
#
34+
def mount(arguments = {})
35+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
36+
raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
37+
raise ArgumentError, "Required argument 'snapshot' missing" unless arguments[:snapshot]
38+
39+
headers = arguments.delete(:headers) || {}
40+
41+
arguments = arguments.clone
42+
43+
_repository = arguments.delete(:repository)
44+
45+
_snapshot = arguments.delete(:snapshot)
46+
47+
method = Elasticsearch::API::HTTP_POST
48+
path = "_snapshot/#{Elasticsearch::API::Utils.__listify(_repository)}/#{Elasticsearch::API::Utils.__listify(_snapshot)}/_mount"
49+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
50+
51+
body = arguments[:body]
52+
perform_request(method, path, params, body, headers).body
53+
end
54+
55+
# Register this action with its valid params when the module is loaded.
56+
#
57+
# @since 6.2.0
58+
ParamsRegistry.register(:mount, [
59+
:master_timeout,
60+
:wait_for_completion
61+
].freeze)
62+
end
63+
end
64+
end
65+
end
66+
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SearchableSnapshots
22+
module Actions
23+
module ParamsRegistry
24+
extend self
25+
26+
# A Mapping of all the actions to their list of valid params.
27+
#
28+
# @since 7.4.0
29+
PARAMS = {}
30+
31+
# Register an action with its list of valid params.
32+
#
33+
# @example Register the action.
34+
# ParamsRegistry.register(:benchmark, [ :verbose ])
35+
#
36+
# @param [ Symbol ] action The action to register.
37+
# @param [ Array[Symbol] ] valid_params The list of valid params.
38+
#
39+
# @since 7.4.0
40+
def register(action, valid_params)
41+
PARAMS[action.to_sym] = valid_params
42+
end
43+
44+
# Get the list of valid params for a given action.
45+
#
46+
# @example Get the list of valid params.
47+
# ParamsRegistry.get(:benchmark)
48+
#
49+
# @param [ Symbol ] action The action.
50+
#
51+
# @return [ Array<Symbol> ] The list of valid params for the action.
52+
#
53+
# @since 7.4.0
54+
def get(action)
55+
PARAMS.fetch(action, [])
56+
end
57+
end
58+
end
59+
end
60+
end
61+
end
62+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SearchableSnapshots
22+
module Actions
23+
# Retrieve usage statistics about a snapshot repository.
24+
#
25+
# @option arguments [String] :repository The repository for which to get the stats for
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/searchable-snapshots-repository-stats.html
29+
#
30+
def repository_stats(arguments = {})
31+
raise ArgumentError, "Required argument 'repository' missing" unless arguments[:repository]
32+
33+
headers = arguments.delete(:headers) || {}
34+
35+
arguments = arguments.clone
36+
37+
_repository = arguments.delete(:repository)
38+
39+
method = Elasticsearch::API::HTTP_GET
40+
path = "_snapshot/#{Elasticsearch::API::Utils.__listify(_repository)}/_stats"
41+
params = {}
42+
43+
body = nil
44+
perform_request(method, path, params, body, headers).body
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SearchableSnapshots
22+
module Actions
23+
# Retrieve various statistics about searchable snapshots.
24+
#
25+
# @option arguments [List] :index A comma-separated list of index names
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/searchable-snapshots-api-stats.html
29+
#
30+
def stats(arguments = {})
31+
headers = arguments.delete(:headers) || {}
32+
33+
arguments = arguments.clone
34+
35+
_index = arguments.delete(:index)
36+
37+
method = Elasticsearch::API::HTTP_GET
38+
path = if _index
39+
"#{Elasticsearch::API::Utils.__listify(_index)}/_searchable_snapshots/stats"
40+
else
41+
"_searchable_snapshots/stats"
42+
end
43+
params = {}
44+
45+
body = nil
46+
perform_request(method, path, params, body, headers).body
47+
end
48+
end
49+
end
50+
end
51+
end
52+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SearchableSnapshots
22+
module Actions; end
23+
24+
class SearchableSnapshotsClient
25+
include Elasticsearch::API::Common::Client, Elasticsearch::API::Common::Client::Base, SearchableSnapshots::Actions
26+
end
27+
28+
def searchable_snapshots
29+
@searchable_snapshots ||= SearchableSnapshotsClient.new(self)
30+
end
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)