Skip to content

Commit 5fe782b

Browse files
committed
Indices API: Added GET Index API
Returns information about settings, aliases, warmers, and mappings. Basically returns the IndexMetadata. This new endpoint replaces the /{index}/_alias|_aliases|_mapping|_mappings|_settings|_warmer|_warmers and /_alias|_aliases|_mapping|_mappings|_settings|_warmer|_warmers endpoints whilst maintaining the same response formats. The only exception to this is on the /_alias|_aliases|_warmer|_warmers endpoint which will now return a section for 'aliases' or 'warmers' even if no aliases or warmers exist. This backwards compatibility change is documented in the reference docs. Closes #4069
1 parent a50934e commit 5fe782b

28 files changed

+1329
-24
lines changed

docs/reference/indices.asciidoc

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and warmers.
1313

1414
* <<indices-create-index>>
1515
* <<indices-delete-index>>
16+
* <<indices-get-index>>
1617
* <<indices-exists>>
1718
* <<indices-open-close>>
1819

@@ -61,6 +62,8 @@ include::indices/create-index.asciidoc[]
6162

6263
include::indices/delete-index.asciidoc[]
6364

65+
include::indices/get-index.asciidoc[]
66+
6467
include::indices/indices-exists.asciidoc[]
6568

6669
include::indices/open-close.asciidoc[]

docs/reference/indices/aliases.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ Possible options:
314314

315315
The rest endpoint is: `/{index}/_alias/{alias}`.
316316

317+
coming[1.4.0,The API will always include an `aliases` section, even if there aren't any aliases. Previous versions would not return the `aliases` section]
318+
317319
[float]
318320
==== Examples:
319321

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[[indices-get-index]]
2+
== Get Index
3+
4+
The get index API allows to retrieve information about one or more indexes.
5+
6+
[source,js]
7+
--------------------------------------------------
8+
$ curl -XGET 'http://localhost:9200/twitter/'
9+
--------------------------------------------------
10+
11+
The above example gets the information for an index called `twitter`. Specifying an index,
12+
alias or wildcard expression is required.
13+
14+
The get index API can also be applied to more than one index, or on
15+
all indices by using `_all` or `*` as index.
16+
17+
[float]
18+
=== Filtering index information
19+
20+
The information returned by the get API can be filtered to include only specific features
21+
by specifying a comma delimited list of features in the URL:
22+
23+
[source,js]
24+
--------------------------------------------------
25+
$ curl -XGET 'http://localhost:9200/twitter/_settings,_mappings'
26+
--------------------------------------------------
27+
28+
The above command will only return the settings and mappings for the index called `twitter`.
29+
30+
The available features are `_settings`, `_mappings`, `_warmers` and `_aliases`.

docs/reference/indices/warmers.asciidoc

+6-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ Instead of `_warmer` you can also use the plural `_warmers`.
180180

181181
Getting a warmer for specific index (or alias, or several indices) based
182182
on its name. The provided name can be a simple wildcard expression or
183-
omitted to get all warmers. Some examples:
183+
omitted to get all warmers.
184+
185+
coming[1.4.0,The API will always include a `warmers` section, even if there aren't any warmers. Previous versions would not return the `warmers` section]
186+
187+
Some examples:
184188

185189
[source,js]
186190
--------------------------------------------------
@@ -193,3 +197,4 @@ curl -XGET localhost:9200/test/_warmer/warm*
193197
# get all warmers for test index
194198
curl -XGET localhost:9200/test/_warmer/
195199
--------------------------------------------------
200+

docs/reference/migration/migrate_1_x.asciidoc

+22
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,25 @@ pointed to by the alias.
3636
Add or update a mapping via the <<indices-create-index,create index>> or
3737
<<indices-put-mapping,put mapping>> apis.
3838

39+
==== Indices APIs
40+
41+
The <<warmer-retrieving, get warmer api>> will return a section for `warmers` even if there are
42+
no warmers. This ensures that the following two examples are equivalent:
43+
44+
[source,js]
45+
--------------------------------------------------
46+
curl -XGET 'http://localhost:9200/_all/_warmers'
47+
48+
curl -XGET 'http://localhost:9200/_warmers'
49+
--------------------------------------------------
50+
51+
Similarly, the <<alias-retrieving, get alias api>> will return a section for `aliases` even if there are
52+
no aliases. This ensures that the following two examples are equivalent:
53+
54+
[source,js]
55+
--------------------------------------------------
56+
curl -XGET 'http://localhost:9200/_all/_aliases'
57+
58+
curl -XGET 'http://localhost:9200/_aliases'
59+
--------------------------------------------------
60+

rest-api-spec/api/indices.get.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"indices.get":{
3+
"documentation":"http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/indices-get.html",
4+
"methods":[ "GET" ],
5+
"url":{
6+
"path":"/{index}",
7+
"paths":[ "/{index}", "/{index}/{feature}" ],
8+
"parts":{
9+
"index":{
10+
"type":"list",
11+
"description":"A comma-separated list of index names"
12+
},
13+
"feature":{
14+
"type":"list",
15+
"description":"A comma-separated list of features"
16+
}
17+
},
18+
"params":{
19+
"local":{
20+
"type":"boolean",
21+
"description":"Return local information, do not retrieve the state from master node (default: false)"
22+
},
23+
"ignore_unavailable":{
24+
"type":"boolean",
25+
"description":"Ignore unavailable indexes (default: false)"
26+
},
27+
"allow_no_indices":{
28+
"type":"boolean",
29+
"description":"Ignore if a wildcard expression resolves to no concrete indices (default: false)"
30+
},
31+
"expand_wildcards":{
32+
"type":"list",
33+
"description":"Whether wildcard expressions should get expanded to open or closed indices (default: open)"
34+
}
35+
}
36+
}
37+
}
38+
}

rest-api-spec/test/indices.get_mapping/50_wildcard_expansion.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ setup:
9696
"Get test-* with wildcard_expansion=none":
9797

9898
- do:
99-
catch: missing
10099
indices.get_mapping:
101100
index: test-x*
102101
expand_wildcards: none
103102

103+
- match: { $body: "{}" }
104+
104105
---
105106
"Get test-* with wildcard_expansion=open,closed":
106107

rest-api-spec/test/indices.put_mapping/all_path_options.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ setup:
4343
- match: {test_index2.mappings.test_type.properties.text.type: string}
4444
- match: {test_index2.mappings.test_type.properties.text.analyzer: whitespace}
4545

46-
- is_false: foo
46+
- match: { foo.mappings: {} }
4747

4848
---
4949
"put mapping in _all index":
@@ -118,7 +118,7 @@ setup:
118118
- match: {test_index2.mappings.test_type.properties.text.type: string}
119119
- match: {test_index2.mappings.test_type.properties.text.analyzer: whitespace}
120120

121-
- is_false: foo
121+
- match: { foo.mappings: {} }
122122

123123
---
124124
"put mapping in list of indices":
@@ -142,7 +142,7 @@ setup:
142142
- match: {test_index2.mappings.test_type.properties.text.type: string}
143143
- match: {test_index2.mappings.test_type.properties.text.analyzer: whitespace}
144144

145-
- is_false: foo
145+
- match: { foo.mappings: {} }
146146

147147
---
148148
"put mapping with blank index":
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
---
2+
setup:
3+
4+
- do:
5+
indices.create:
6+
index: test_index
7+
body:
8+
aliases:
9+
test_alias: {}
10+
test_blias: {}
11+
mappings:
12+
type_1: {}
13+
warmers:
14+
test_warmer:
15+
source:
16+
query:
17+
match_all: {}
18+
settings:
19+
number_of_shards: 1
20+
number_of_replicas: 1
21+
22+
- do:
23+
indices.create:
24+
index: test_index_2
25+
body:
26+
settings:
27+
number_of_shards: 1
28+
number_of_replicas: 2
29+
aliases:
30+
test_alias: {}
31+
test_blias: {}
32+
33+
- do:
34+
indices.create:
35+
index: test_index_3
36+
body:
37+
aliases:
38+
test_alias: {}
39+
test_blias: {}
40+
41+
- do:
42+
cluster.health:
43+
wait_for_status: yellow
44+
45+
- do:
46+
indices.close:
47+
index: test_index_3
48+
49+
- do:
50+
cluster.health:
51+
wait_for_status: yellow
52+
53+
---
54+
"Get index infos":
55+
56+
- do:
57+
indices.get:
58+
index: test_index
59+
60+
- is_true: test_index.aliases
61+
- is_true: test_index.settings
62+
- is_true: test_index.warmers
63+
- is_true: test_index.mappings
64+
65+
---
66+
"Get index infos for mappings only":
67+
68+
- do:
69+
indices.get:
70+
index: test_index
71+
feature: _mapping
72+
73+
- is_true: test_index.mappings
74+
- is_false: test_index.aliases
75+
- is_false: test_index.settings
76+
- is_false: test_index.warmers
77+
78+
---
79+
"Get index infos for mappings and warmers only":
80+
81+
- do:
82+
indices.get:
83+
index: test_index
84+
feature: _mapping,_warmer
85+
86+
- is_true: test_index.mappings
87+
- is_true: test_index.warmers
88+
- is_false: test_index.aliases
89+
- is_false: test_index.settings
90+
91+
---
92+
"Get index infos should work on aliases":
93+
94+
- do:
95+
indices.get:
96+
index: test_blias
97+
feature: _mapping,_warmer
98+
99+
- is_true: test_index.mappings
100+
- is_true: test_index.warmers
101+
- is_false: test_index.aliases
102+
- is_false: test_index.settings
103+
104+
---
105+
"Get index infos should work for wildcards":
106+
107+
- do:
108+
indices.get:
109+
index: test_*
110+
feature: _mapping,_settings
111+
112+
- is_true: test_index.mappings
113+
- is_true: test_index.settings
114+
- is_true: test_index_2.settings
115+
- is_false: test_index.aliases
116+
- is_false: test_index.warmers
117+
118+
---
119+
"Missing index should throw an Error":
120+
121+
- do:
122+
catch: missing
123+
indices.get:
124+
index: test_not_found
125+
126+
---
127+
"Missing index should return empty object if ignore_unavailable":
128+
129+
- do:
130+
indices.get:
131+
index: test_not_found
132+
ignore_unavailable: true
133+
134+
- match: { $body: "{}" }
135+
136+
---
137+
"Should return empty object if allow_no_indices":
138+
139+
- do:
140+
indices.get:
141+
index: test_not*
142+
143+
- match: { $body: "{}" }
144+
145+
---
146+
"Should throw error if allow_no_indices=false":
147+
148+
- do:
149+
catch: missing
150+
indices.get:
151+
index: test_not*
152+
allow_no_indices: false
153+
154+
---
155+
"Should return test_index_2 if expand_wildcards=open":
156+
157+
- do:
158+
indices.get:
159+
index: test_index_*
160+
expand_wildcards: open
161+
162+
- is_true: test_index_2.settings
163+
- is_false: test_index_3.settings
164+
165+
---
166+
"Should return test_index_3 if expand_wildcards=closed":
167+
168+
- skip:
169+
version: "0 - 2.0.0"
170+
reason: Requires fix for issue 7258
171+
172+
- do:
173+
indices.get:
174+
index: test_index_*
175+
feature: _settings
176+
expand_wildcards: closed
177+
178+
- is_false: test_index_2.settings
179+
- is_true: test_index_3.settings
180+
181+
---
182+
"Should return test_index_2 and test_index_3 if expand_wildcards=open,closed":
183+
184+
- do:
185+
indices.get:
186+
index: test_index_*
187+
feature: _settings
188+
expand_wildcards: open,closed
189+
190+
- is_true: test_index_2.settings
191+
- is_true: test_index_3.settings
192+

src/main/java/org/elasticsearch/action/ActionModule.java

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsAction;
8484
import org.elasticsearch.action.admin.indices.flush.FlushAction;
8585
import org.elasticsearch.action.admin.indices.flush.TransportFlushAction;
86+
import org.elasticsearch.action.admin.indices.get.GetIndexAction;
87+
import org.elasticsearch.action.admin.indices.get.TransportGetIndexAction;
8688
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingAction;
8789
import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction;
8890
import org.elasticsearch.action.admin.indices.mapping.get.*;
@@ -246,6 +248,7 @@ protected void configure() {
246248
registerAction(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class);
247249
registerAction(CreateIndexAction.INSTANCE, TransportCreateIndexAction.class);
248250
registerAction(DeleteIndexAction.INSTANCE, TransportDeleteIndexAction.class);
251+
registerAction(GetIndexAction.INSTANCE, TransportGetIndexAction.class);
249252
registerAction(OpenIndexAction.INSTANCE, TransportOpenIndexAction.class);
250253
registerAction(CloseIndexAction.INSTANCE, TransportCloseIndexAction.class);
251254
registerAction(IndicesExistsAction.INSTANCE, TransportIndicesExistsAction.class);

0 commit comments

Comments
 (0)