Skip to content

Commit

Permalink
Indices API: Added GET Index API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
colings86 committed Sep 11, 2014
1 parent a50934e commit 5fe782b
Show file tree
Hide file tree
Showing 28 changed files with 1,329 additions and 24 deletions.
3 changes: 3 additions & 0 deletions docs/reference/indices.asciidoc
Expand Up @@ -13,6 +13,7 @@ and warmers.

* <<indices-create-index>>
* <<indices-delete-index>>
* <<indices-get-index>>
* <<indices-exists>>
* <<indices-open-close>>

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

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

include::indices/get-index.asciidoc[]

include::indices/indices-exists.asciidoc[]

include::indices/open-close.asciidoc[]
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/indices/aliases.asciidoc
Expand Up @@ -314,6 +314,8 @@ Possible options:

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

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]

[float]
==== Examples:

Expand Down
30 changes: 30 additions & 0 deletions docs/reference/indices/get-index.asciidoc
@@ -0,0 +1,30 @@
[[indices-get-index]]
== Get Index

The get index API allows to retrieve information about one or more indexes.

[source,js]
--------------------------------------------------
$ curl -XGET 'http://localhost:9200/twitter/'
--------------------------------------------------

The above example gets the information for an index called `twitter`. Specifying an index,
alias or wildcard expression is required.

The get index API can also be applied to more than one index, or on
all indices by using `_all` or `*` as index.

[float]
=== Filtering index information

The information returned by the get API can be filtered to include only specific features
by specifying a comma delimited list of features in the URL:

[source,js]
--------------------------------------------------
$ curl -XGET 'http://localhost:9200/twitter/_settings,_mappings'
--------------------------------------------------

The above command will only return the settings and mappings for the index called `twitter`.

The available features are `_settings`, `_mappings`, `_warmers` and `_aliases`.
7 changes: 6 additions & 1 deletion docs/reference/indices/warmers.asciidoc
Expand Up @@ -180,7 +180,11 @@ Instead of `_warmer` you can also use the plural `_warmers`.

Getting a warmer for specific index (or alias, or several indices) based
on its name. The provided name can be a simple wildcard expression or
omitted to get all warmers. Some examples:
omitted to get all warmers.

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]

Some examples:

[source,js]
--------------------------------------------------
Expand All @@ -193,3 +197,4 @@ curl -XGET localhost:9200/test/_warmer/warm*
# get all warmers for test index
curl -XGET localhost:9200/test/_warmer/
--------------------------------------------------

22 changes: 22 additions & 0 deletions docs/reference/migration/migrate_1_x.asciidoc
Expand Up @@ -36,3 +36,25 @@ pointed to by the alias.
Add or update a mapping via the <<indices-create-index,create index>> or
<<indices-put-mapping,put mapping>> apis.

==== Indices APIs

The <<warmer-retrieving, get warmer api>> will return a section for `warmers` even if there are
no warmers. This ensures that the following two examples are equivalent:

[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/_all/_warmers'
curl -XGET 'http://localhost:9200/_warmers'
--------------------------------------------------

Similarly, the <<alias-retrieving, get alias api>> will return a section for `aliases` even if there are
no aliases. This ensures that the following two examples are equivalent:

[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/_all/_aliases'
curl -XGET 'http://localhost:9200/_aliases'
--------------------------------------------------

38 changes: 38 additions & 0 deletions rest-api-spec/api/indices.get.json
@@ -0,0 +1,38 @@
{
"indices.get":{
"documentation":"http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/indices-get.html",
"methods":[ "GET" ],
"url":{
"path":"/{index}",
"paths":[ "/{index}", "/{index}/{feature}" ],
"parts":{
"index":{
"type":"list",
"description":"A comma-separated list of index names"
},
"feature":{
"type":"list",
"description":"A comma-separated list of features"
}
},
"params":{
"local":{
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)"
},
"ignore_unavailable":{
"type":"boolean",
"description":"Ignore unavailable indexes (default: false)"
},
"allow_no_indices":{
"type":"boolean",
"description":"Ignore if a wildcard expression resolves to no concrete indices (default: false)"
},
"expand_wildcards":{
"type":"list",
"description":"Whether wildcard expressions should get expanded to open or closed indices (default: open)"
}
}
}
}
}
Expand Up @@ -96,11 +96,12 @@ setup:
"Get test-* with wildcard_expansion=none":

- do:
catch: missing
indices.get_mapping:
index: test-x*
expand_wildcards: none

- match: { $body: "{}" }

---
"Get test-* with wildcard_expansion=open,closed":

Expand Down
6 changes: 3 additions & 3 deletions rest-api-spec/test/indices.put_mapping/all_path_options.yaml
Expand Up @@ -43,7 +43,7 @@ setup:
- match: {test_index2.mappings.test_type.properties.text.type: string}
- match: {test_index2.mappings.test_type.properties.text.analyzer: whitespace}

- is_false: foo
- match: { foo.mappings: {} }

---
"put mapping in _all index":
Expand Down Expand Up @@ -118,7 +118,7 @@ setup:
- match: {test_index2.mappings.test_type.properties.text.type: string}
- match: {test_index2.mappings.test_type.properties.text.analyzer: whitespace}

- is_false: foo
- match: { foo.mappings: {} }

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

- is_false: foo
- match: { foo.mappings: {} }

---
"put mapping with blank index":
Expand Down
192 changes: 192 additions & 0 deletions rest-api-spec/test/indices/get/10_basic.yaml
@@ -0,0 +1,192 @@
---
setup:

- do:
indices.create:
index: test_index
body:
aliases:
test_alias: {}
test_blias: {}
mappings:
type_1: {}
warmers:
test_warmer:
source:
query:
match_all: {}
settings:
number_of_shards: 1
number_of_replicas: 1

- do:
indices.create:
index: test_index_2
body:
settings:
number_of_shards: 1
number_of_replicas: 2
aliases:
test_alias: {}
test_blias: {}

- do:
indices.create:
index: test_index_3
body:
aliases:
test_alias: {}
test_blias: {}

- do:
cluster.health:
wait_for_status: yellow

- do:
indices.close:
index: test_index_3

- do:
cluster.health:
wait_for_status: yellow

---
"Get index infos":

- do:
indices.get:
index: test_index

- is_true: test_index.aliases
- is_true: test_index.settings
- is_true: test_index.warmers
- is_true: test_index.mappings

---
"Get index infos for mappings only":

- do:
indices.get:
index: test_index
feature: _mapping

- is_true: test_index.mappings
- is_false: test_index.aliases
- is_false: test_index.settings
- is_false: test_index.warmers

---
"Get index infos for mappings and warmers only":

- do:
indices.get:
index: test_index
feature: _mapping,_warmer

- is_true: test_index.mappings
- is_true: test_index.warmers
- is_false: test_index.aliases
- is_false: test_index.settings

---
"Get index infos should work on aliases":

- do:
indices.get:
index: test_blias
feature: _mapping,_warmer

- is_true: test_index.mappings
- is_true: test_index.warmers
- is_false: test_index.aliases
- is_false: test_index.settings

---
"Get index infos should work for wildcards":

- do:
indices.get:
index: test_*
feature: _mapping,_settings

- is_true: test_index.mappings
- is_true: test_index.settings
- is_true: test_index_2.settings
- is_false: test_index.aliases
- is_false: test_index.warmers

---
"Missing index should throw an Error":

- do:
catch: missing
indices.get:
index: test_not_found

---
"Missing index should return empty object if ignore_unavailable":

- do:
indices.get:
index: test_not_found
ignore_unavailable: true

- match: { $body: "{}" }

---
"Should return empty object if allow_no_indices":

- do:
indices.get:
index: test_not*

- match: { $body: "{}" }

---
"Should throw error if allow_no_indices=false":

- do:
catch: missing
indices.get:
index: test_not*
allow_no_indices: false

---
"Should return test_index_2 if expand_wildcards=open":

- do:
indices.get:
index: test_index_*
expand_wildcards: open

- is_true: test_index_2.settings
- is_false: test_index_3.settings

---
"Should return test_index_3 if expand_wildcards=closed":

- skip:
version: "0 - 2.0.0"
reason: Requires fix for issue 7258

- do:
indices.get:
index: test_index_*
feature: _settings
expand_wildcards: closed

- is_false: test_index_2.settings
- is_true: test_index_3.settings

---
"Should return test_index_2 and test_index_3 if expand_wildcards=open,closed":

- do:
indices.get:
index: test_index_*
feature: _settings
expand_wildcards: open,closed

- is_true: test_index_2.settings
- is_true: test_index_3.settings

3 changes: 3 additions & 0 deletions src/main/java/org/elasticsearch/action/ActionModule.java
Expand Up @@ -83,6 +83,8 @@
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsAction;
import org.elasticsearch.action.admin.indices.flush.FlushAction;
import org.elasticsearch.action.admin.indices.flush.TransportFlushAction;
import org.elasticsearch.action.admin.indices.get.GetIndexAction;
import org.elasticsearch.action.admin.indices.get.TransportGetIndexAction;
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingAction;
import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction;
import org.elasticsearch.action.admin.indices.mapping.get.*;
Expand Down Expand Up @@ -246,6 +248,7 @@ protected void configure() {
registerAction(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class);
registerAction(CreateIndexAction.INSTANCE, TransportCreateIndexAction.class);
registerAction(DeleteIndexAction.INSTANCE, TransportDeleteIndexAction.class);
registerAction(GetIndexAction.INSTANCE, TransportGetIndexAction.class);
registerAction(OpenIndexAction.INSTANCE, TransportOpenIndexAction.class);
registerAction(CloseIndexAction.INSTANCE, TransportCloseIndexAction.class);
registerAction(IndicesExistsAction.INSTANCE, TransportIndicesExistsAction.class);
Expand Down

0 comments on commit 5fe782b

Please sign in to comment.