Skip to content

Commit 13d52cd

Browse files
committed
[API] Adds indices.field_usage_stats
1 parent 5ecc460 commit 13d52cd

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
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 API
20+
module Indices
21+
module Actions
22+
# Returns the field usage stats for each field of an index
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 A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices
29+
# @option arguments [List] :fields A comma-separated list of fields to include in the stats if only a subset of fields should be returned (supports wildcards)
30+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
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. (options: open, closed, hidden, none, all)
33+
# @option arguments [Hash] :headers Custom HTTP headers
34+
#
35+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/field-usage-stats.html
36+
#
37+
def field_usage_stats(arguments = {})
38+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
39+
40+
headers = arguments.delete(:headers) || {}
41+
42+
arguments = arguments.clone
43+
44+
_index = arguments.delete(:index)
45+
46+
method = Elasticsearch::API::HTTP_GET
47+
path = "#{Utils.__listify(_index)}/_field_usage_stats"
48+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
49+
50+
body = nil
51+
perform_request(method, path, params, body, headers).body
52+
end
53+
54+
# Register this action with its valid params when the module is loaded.
55+
#
56+
# @since 6.2.0
57+
ParamsRegistry.register(:field_usage_stats, [
58+
:fields,
59+
:ignore_unavailable,
60+
:allow_no_indices,
61+
:expand_wildcards
62+
].freeze)
63+
end
64+
end
65+
end
66+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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#field_usage_stats' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'foo/_field_usage_stats',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.indices.field_usage_stats(index: 'foo')).to eq({})
33+
end
34+
35+
context 'when there is no index specified' do
36+
let(:client) do
37+
Class.new { include Elasticsearch::API }.new
38+
end
39+
40+
it 'raises an exception' do
41+
expect {
42+
client.indices.field_usage_stats
43+
}.to raise_exception(ArgumentError)
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)