Skip to content

Commit 3eed594

Browse files
committed
[XPACK] Generate indices endpoints
1 parent 87368e1 commit 3eed594

File tree

6 files changed

+304
-0
lines changed

6 files changed

+304
-0
lines changed

elasticsearch-xpack/lib/elasticsearch/xpack.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def async_search
104104
def cat
105105
@cat ||= xpack.cat
106106
end
107+
108+
def indices
109+
@indices ||= xpack.indices
110+
end
107111
end
108112
end
109113
end if defined?(Elasticsearch::Transport::Client)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 Indices
22+
module Actions
23+
# Freezes an index. A frozen index has almost no overhead on the cluster (except for maintaining its metadata in memory) and is read-only.
24+
#
25+
# @option arguments [String] :index The name of the index to freeze
26+
# @option arguments [Time] :timeout Explicit operation timeout
27+
# @option arguments [Time] :master_timeout Specify timeout for connection to master
28+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
29+
# @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)
30+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both.
31+
# (options: open,closed,hidden,none,all)
32+
33+
# @option arguments [String] :wait_for_active_shards Sets the number of active shards to wait for before the operation returns.
34+
# @option arguments [Hash] :headers Custom HTTP headers
35+
#
36+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/freeze-index-api.html
37+
#
38+
def freeze(arguments = {})
39+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
40+
41+
headers = arguments.delete(:headers) || {}
42+
43+
arguments = arguments.clone
44+
45+
_index = arguments.delete(:index)
46+
47+
method = Elasticsearch::API::HTTP_POST
48+
path = "#{Elasticsearch::API::Utils.__listify(_index)}/_freeze"
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(:freeze, [
59+
:timeout,
60+
:master_timeout,
61+
:ignore_unavailable,
62+
:allow_no_indices,
63+
:expand_wildcards,
64+
:wait_for_active_shards
65+
].freeze)
66+
end
67+
end
68+
end
69+
end
70+
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 Indices
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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 Indices
22+
module Actions
23+
# Reloads an index's search analyzers and their resources.
24+
#
25+
# @option arguments [List] :index A comma-separated list of index names to reload analyzers for
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,hidden,none,all)
30+
31+
# @option arguments [Hash] :headers Custom HTTP headers
32+
#
33+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-reload-analyzers.html
34+
#
35+
def reload_search_analyzers(arguments = {})
36+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
37+
38+
headers = arguments.delete(:headers) || {}
39+
40+
arguments = arguments.clone
41+
42+
_index = arguments.delete(:index)
43+
44+
method = Elasticsearch::API::HTTP_GET
45+
path = "#{Elasticsearch::API::Utils.__listify(_index)}/_reload_search_analyzers"
46+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
47+
48+
body = nil
49+
perform_request(method, path, params, body, headers).body
50+
end
51+
52+
# Register this action with its valid params when the module is loaded.
53+
#
54+
# @since 6.2.0
55+
ParamsRegistry.register(:reload_search_analyzers, [
56+
:ignore_unavailable,
57+
:allow_no_indices,
58+
:expand_wildcards
59+
].freeze)
60+
end
61+
end
62+
end
63+
end
64+
end
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 Indices
22+
module Actions
23+
# Unfreezes an index. When a frozen index is unfrozen, the index goes through the normal recovery process and becomes writeable again.
24+
#
25+
# @option arguments [String] :index The name of the index to unfreeze
26+
# @option arguments [Time] :timeout Explicit operation timeout
27+
# @option arguments [Time] :master_timeout Specify timeout for connection to master
28+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
29+
# @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)
30+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both.
31+
# (options: open,closed,hidden,none,all)
32+
33+
# @option arguments [String] :wait_for_active_shards Sets the number of active shards to wait for before the operation returns.
34+
# @option arguments [Hash] :headers Custom HTTP headers
35+
#
36+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/unfreeze-index-api.html
37+
#
38+
def unfreeze(arguments = {})
39+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
40+
41+
headers = arguments.delete(:headers) || {}
42+
43+
arguments = arguments.clone
44+
45+
_index = arguments.delete(:index)
46+
47+
method = Elasticsearch::API::HTTP_POST
48+
path = "#{Elasticsearch::API::Utils.__listify(_index)}/_unfreeze"
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(:unfreeze, [
59+
:timeout,
60+
:master_timeout,
61+
:ignore_unavailable,
62+
:allow_no_indices,
63+
:expand_wildcards,
64+
:wait_for_active_shards
65+
].freeze)
66+
end
67+
end
68+
end
69+
end
70+
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 Indices
22+
module Actions; end
23+
24+
class IndicesClient < Elasticsearch::API::Indices::IndicesClient
25+
include Elasticsearch::API::Common::Client, Elasticsearch::API::Common::Client::Base, Indices::Actions
26+
end
27+
28+
def indices
29+
@indices ||= IndicesClient.new(self)
30+
end
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)