Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GET Index API #7234

Merged
merged 1 commit into from Sep 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: {} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these breaking changes properly documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added notes to the relevant pages and to the breaking changes in 1.4 page. This required me to rebase on master as the breaking changes page is new


---
"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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some negative tests, like what happens if the index is not there etc.? Also does the api support the ignore_unavailable flag & co.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!


---
"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