Skip to content

Commit 6a775a8

Browse files
committed
[API] Add indices/status back
1 parent ad23256 commit 6a775a8

File tree

2 files changed

+155
-0
lines changed
  • elasticsearch-api

2 files changed

+155
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module Elasticsearch
2+
module API
3+
module Indices
4+
module Actions
5+
6+
# Return information about one or more indices
7+
#
8+
# @example Get information about all indices
9+
#
10+
# client.indices.status
11+
#
12+
# @example Get information about a specific index
13+
#
14+
# client.indices.status index: 'foo'
15+
#
16+
# @example Get information about shard recovery for a specific index
17+
#
18+
# client.indices.status index: 'foo', recovery: true
19+
#
20+
# @option arguments [List] :index A comma-separated list of index names; use `_all` or empty string
21+
# to perform the operation on all indices
22+
# @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into
23+
# no concrete indices. (This includes `_all` string or when no
24+
# indices have been specified)
25+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that
26+
# are open, closed or both. (options: open, closed)
27+
# @option arguments [String] :ignore_indices When performed on multiple indices, allows to ignore
28+
# `missing` ones (options: none, missing) @until 1.0
29+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when
30+
# unavailable (missing, closed, etc)
31+
# @option arguments [Boolean] :recovery Return information about shard recovery (progress, size, etc)
32+
# @option arguments [Boolean] :snapshot Return information about snapshots (when shared gateway is used)
33+
#
34+
# @see http://elasticsearch.org/guide/reference/api/admin-indices-status/
35+
#
36+
def status(arguments={})
37+
method = HTTP_GET
38+
path = Utils.__pathify Utils.__listify(arguments[:index]), '_status'
39+
40+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
41+
body = nil
42+
43+
if Array(arguments[:ignore]).include?(404)
44+
Utils.__rescue_from_not_found { perform_request(method, path, params, body).body }
45+
else
46+
perform_request(method, path, params, body).body
47+
end
48+
end
49+
50+
# Register this action with its valid params when the module is loaded.
51+
#
52+
# @since 6.2.0
53+
ParamsRegistry.register(:status, [
54+
:ignore_indices,
55+
:ignore_unavailable,
56+
:allow_no_indices,
57+
:expand_wildcards,
58+
:recovery,
59+
:snapshot ].freeze)
60+
end
61+
end
62+
end
63+
end
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
require 'spec_helper'
2+
3+
describe 'client.cluster#status' do
4+
5+
let(:expected_args) do
6+
[
7+
'GET',
8+
url,
9+
params,
10+
body,
11+
nil
12+
]
13+
end
14+
15+
let(:url) do
16+
'_status'
17+
end
18+
19+
let(:body) do
20+
nil
21+
end
22+
23+
let(:params) do
24+
{}
25+
end
26+
27+
it 'performs the request' do
28+
expect(client_double.indices.status).to eq({})
29+
end
30+
31+
context 'when an index is specified' do
32+
33+
let(:url) do
34+
'foo/_status'
35+
end
36+
37+
it 'performs the request' do
38+
expect(client_double.indices.status(index: 'foo')).to eq({})
39+
end
40+
end
41+
42+
context 'when multiple indicies are specified as a list' do
43+
44+
let(:url) do
45+
'foo,bar/_status'
46+
end
47+
48+
it 'performs the request' do
49+
expect(client_double.indices.status(index: ['foo', 'bar'])).to eq({})
50+
end
51+
end
52+
53+
context 'when multiple indicies are specified as a string' do
54+
55+
56+
let(:url) do
57+
'foo,bar/_status'
58+
end
59+
60+
it 'performs the request' do
61+
expect(client_double.indices.status(index: 'foo,bar')).to eq({})
62+
end
63+
end
64+
65+
context 'when parameters are specified' do
66+
67+
let(:params) do
68+
{ recovery: true }
69+
end
70+
71+
let(:url) do
72+
'foo/_status'
73+
end
74+
75+
it 'performs the request' do
76+
expect(client_double.indices.status(index: 'foo', recovery: true)).to eq({})
77+
end
78+
end
79+
80+
context 'when a \'not found\' exception is raised' do
81+
82+
let(:client) do
83+
Class.new { include Elasticsearch::API }.new.tap do |_client|
84+
expect(_client).to receive(:perform_request).and_raise(NotFound)
85+
end
86+
end
87+
88+
it 'does not raise the exception' do
89+
expect(client.indices.status(index: 'foo', ignore: 404)).to eq(false)
90+
end
91+
end
92+
end

0 commit comments

Comments
 (0)