Skip to content

Commit b2f0825

Browse files
committed
[API] Added the "Get Indices Info" API
Related: elastic/elasticsearch#7234, elasticsearch/elasticsearch/#4069
1 parent c631d58 commit b2f0825

File tree

2 files changed

+86
-0
lines changed
  • elasticsearch-api

2 files changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Elasticsearch
2+
module API
3+
module Indices
4+
module Actions
5+
6+
# Retrieve information about one or more indices
7+
#
8+
# @option arguments [List] :index A comma-separated list of index names (*Required*)
9+
# @option arguments [List] :feature A comma-separated list of features
10+
# @option arguments [Boolean] :local Return local information, do not retrieve the state from master node
11+
# (default: false)
12+
# @option arguments [Boolean] :ignore_unavailable Ignore unavailable indexes (default: false)
13+
# @option arguments [Boolean] :allow_no_indices Ignore if a wildcard expression resolves to no concrete
14+
# indices (default: false)
15+
# @option arguments [List] :expand_wildcards Whether wildcard expressions should get expanded
16+
# to open or closed indices (default: open)
17+
#
18+
# @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/indices-get-index.html
19+
#
20+
def get(arguments={})
21+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
22+
23+
valid_params = [
24+
:local,
25+
:ignore_unavailable,
26+
:allow_no_indices,
27+
:expand_wildcards ]
28+
29+
method = 'GET'
30+
31+
path = Utils.__pathify Utils.__listify(arguments[:index]), Utils.__listify(arguments.delete(:feature))
32+
33+
params = Utils.__validate_and_extract_params arguments, valid_params
34+
body = nil
35+
36+
perform_request(method, path, params, body).body
37+
end
38+
end
39+
end
40+
end
41+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'test_helper'
2+
3+
module Elasticsearch
4+
module Test
5+
class IndicesGetTest < ::Test::Unit::TestCase
6+
7+
context "Indices: Get" do
8+
subject { FakeClient.new }
9+
10+
should "perform correct request" do
11+
subject.expects(:perform_request).with do |method, url, params, body|
12+
assert_equal 'GET', method
13+
assert_equal 'foo', url
14+
assert_equal Hash.new, params
15+
assert_nil body
16+
true
17+
end.returns(FakeResponse.new)
18+
19+
subject.indices.get :index => 'foo'
20+
end
21+
22+
should "pass the URL parameters" do
23+
subject.expects(:perform_request).with do |method, url, params, body|
24+
assert_equal 'foo', url
25+
assert_equal 1, params[:ignore_unavailable]
26+
true
27+
end.returns(FakeResponse.new)
28+
29+
subject.indices.get :index => 'foo', :ignore_unavailable => 1
30+
end
31+
32+
should "encode features in URL" do
33+
subject.expects(:perform_request).with do |method, url, params, body|
34+
assert_equal 'foo/_settings', url
35+
true
36+
end.returns(FakeResponse.new)
37+
38+
subject.indices.get :index => 'foo', :feature => '_settings'
39+
end
40+
41+
end
42+
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)