Skip to content

Commit 5ecc460

Browse files
committed
[API] Adds indices.disk_usage
1 parent ba1a290 commit 5ecc460

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed
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 API
20+
module Indices
21+
module Actions
22+
# Analyzes the disk usage of each field of an index or data stream
23+
# This functionality is Experimental and may be changed or removed
24+
# completely in a future release. Elastic will take a best effort approach
25+
# to fix any issues, but experimental features are not subject to the
26+
# support SLA of official GA features.
27+
#
28+
# @option arguments [String] :index Comma-separated list of indices or data streams to analyze the disk usage
29+
# @option arguments [Boolean] :run_expensive_tasks Must be set to [true] in order for the task to be performed. Defaults to false.
30+
# @option arguments [Boolean] :flush Whether flush or not before analyzing the index disk usage. Defaults to true
31+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
32+
# @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)
33+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both. (options: open, closed, hidden, none, all)
34+
# @option arguments [Hash] :headers Custom HTTP headers
35+
#
36+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/indices-disk-usage.html
37+
#
38+
def disk_usage(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 = "#{Utils.__listify(_index)}/_disk_usage"
49+
params = 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(:disk_usage, [
59+
:run_expensive_tasks,
60+
:flush,
61+
:ignore_unavailable,
62+
:allow_no_indices,
63+
:expand_wildcards
64+
].freeze)
65+
end
66+
end
67+
end
68+
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 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+
require 'spec_helper'
19+
20+
describe 'client.indices#disk_usage' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
"#{index}/_disk_usage",
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
let(:index) { 'foo' }
32+
33+
it 'performs the request' do
34+
expect(client_double.indices.disk_usage(index: index)).to eq({})
35+
end
36+
37+
context 'when there is no index specified' do
38+
let(:client) do
39+
Class.new { include Elasticsearch::API }.new
40+
end
41+
42+
it 'raises an exception' do
43+
expect do
44+
client.indices.disk_usage
45+
end.to raise_exception(ArgumentError)
46+
end
47+
end
48+
end

elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/sql/clear_cursor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Actions
2525
# @option arguments [Hash] :headers Custom HTTP headers
2626
# @option arguments [Hash] :body Specify the cursor value in the `cursor` element to clean the cursor. (*Required*)
2727
#
28-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/sql-pagination.html
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/clear-sql-cursor-api.html
2929
#
3030
def clear_cursor(arguments = {})
3131
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/sql/query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Actions
2626
# @option arguments [Hash] :headers Custom HTTP headers
2727
# @option arguments [Hash] :body Use the `query` element to start a query. Use the `cursor` element to continue a query. (*Required*)
2828
#
29-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/sql-rest-overview.html
29+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/sql-search-api.html
3030
#
3131
def query(arguments = {})
3232
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/sql/translate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Actions
2525
# @option arguments [Hash] :headers Custom HTTP headers
2626
# @option arguments [Hash] :body Specify the query in the `query` element. (*Required*)
2727
#
28-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/sql-translate.html
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/sql-translate-api.html
2929
#
3030
def translate(arguments = {})
3131
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]

0 commit comments

Comments
 (0)