Make PUT and DELETE consistent for _mapping, _alias and _warmer
See issue #4071 PUT options for _mapping: Single type can now be added with `[PUT|POST] {index|_all|*|regex|blank}/[_mapping|_mappings]/type` and `[PUT|POST] {index|_all|*|regex|blank}/type/[_mapping|_mappings]` PUT options for _warmer: PUT with a single warmer can now be done with `[PUT|POST] {index|_all|*|prefix*|blank}/{type|_all|*|prefix*|blank}/[_warmer|_warmers]/warmer_name` PUT options for _alias: Single alias can now be PUT with `[PUT|POST] {index|_all|*|prefix*|blank}/[_alias|_aliases]/alias` DELETE options _mapping: Several mappings can be deleted at once by defining several indices and types with `[DELETE] /{index}/{type}` `[DELETE] /{index}/{type}/_mapping` `[DELETE] /{index}/_mapping/{type}` where `index= * | _all | glob pattern | name1, name2, …` `type= * | _all | glob pattern | name1, name2, …` Alternatively, the keyword `_mapings` can be used. DELETE options for _warmer: Several warmers can be deleted at once by defining several indices and names with `[DELETE] /{index}/_warmer/{type}` where `index= * | _all | glob pattern | name1, name2, …` `type= * | _all | glob pattern | name1, name2, …` Alternatively, the keyword `_warmers` can be used. DELETE options for _alias: Several aliases can be deleted at once by defining several indices and names with `[DELETE] /{index}/_alias/{type}` where `index= * | _all | glob pattern | name1, name2, …` `type= * | _all | glob pattern | name1, name2, …` Alternatively, the keyword `_aliases` can be used.
This commit is contained in:
parent
d1a4f889ae
commit
411739fe3b
|
@ -153,17 +153,22 @@ curl -XGET 'http://localhost:9200/alias2/_search?q=user:kimchy&routing=2,3'
|
|||
|
||||
[float]
|
||||
[[alias-adding]]
|
||||
=== Add a single index alias
|
||||
=== Add a single alias
|
||||
|
||||
There is also an api to add a single index alias, with options:
|
||||
An alias can also be added with the endpoint
|
||||
|
||||
`PUT /{index}/_alias/{name}`
|
||||
|
||||
|
||||
where
|
||||
|
||||
[horizontal]
|
||||
`index`:: The index to alias refers to. This is a required option.
|
||||
`alias`:: The name of the alias. This is a required option.
|
||||
`index`:: The index to alias refers to. Can be any of `blank | * | _all | glob pattern | name1, name2, …`
|
||||
`name`:: The name of the alias. This is a required option.
|
||||
`routing`:: An optional routing that can be associated with an alias.
|
||||
`filter`:: An optional filter that can be associated with an alias.
|
||||
|
||||
The rest endpoint is: `/{index}/_alias/{alias}`.
|
||||
You can also use the plural `_aliases`.
|
||||
|
||||
[float]
|
||||
==== Examples:
|
||||
|
@ -191,16 +196,18 @@ curl -XPUT 'localhost:9200/users/_alias/user_12' -d '{
|
|||
|
||||
[float]
|
||||
[[deleting]]
|
||||
=== Delete a single index alias
|
||||
=== Delete aliases
|
||||
|
||||
Th API to delete a single index alias, has options:
|
||||
|
||||
The rest endpoint is: `/{index}/_alias/{name}`
|
||||
|
||||
where
|
||||
|
||||
[horizontal]
|
||||
`index`:: The index the alias is in, the needs to be deleted. This is
|
||||
a required option.
|
||||
`alias`:: The name of the alias to delete. This is a required option.
|
||||
`index`:: `* | _all | glob pattern | name1, name2, …`
|
||||
`name`:: `* | _all | glob pattern | name1, name2, …`
|
||||
|
||||
The rest endpoint is: `/{index}/_alias/{alias}`. Example:
|
||||
Alternatively you can use the plural `_aliases`. Example:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
|
|
|
@ -1,8 +1,25 @@
|
|||
[[indices-delete-mapping]]
|
||||
== Delete Mapping
|
||||
|
||||
Allow to delete a mapping (type) along with its data. The REST endpoint
|
||||
is `/{index}/{type}` with `DELETE` method.
|
||||
Allow to delete a mapping (type) along with its data. The REST endpoints are
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
|
||||
[DELETE] /{index}/{type}
|
||||
|
||||
[DELETE] /{index}/{type}/_mapping
|
||||
|
||||
[DELETE] /{index}/_mapping/{type}
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
where
|
||||
|
||||
[horizontal]
|
||||
|
||||
`index`:: `* | _all | glob pattern | name1, name2, …`
|
||||
`type`:: `* | _all | glob pattern | name1, name2, …`
|
||||
|
||||
Note, most times, it make more sense to reindex the data into a fresh
|
||||
index compared to delete large chunks of it.
|
||||
|
|
|
@ -59,3 +59,25 @@ $ curl -XPUT 'http://localhost:9200/kimchy,elasticsearch/tweet/_mapping' -d '
|
|||
}
|
||||
'
|
||||
--------------------------------------------------
|
||||
|
||||
All options:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
|
||||
PUT /{index}/_mapping/{type}
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
|
||||
where
|
||||
|
||||
[horizontal]
|
||||
`{index}`:: `blank | * | _all | glob pattern | name1, name2, …`
|
||||
|
||||
`{type}`:: Name of the type to add. Must be the name of the type defined in the body.
|
||||
|
||||
|
||||
Instead of `_mapping` you can also use the plural `_mappings`.
|
||||
The uri `PUT /{index}/{type}/_mapping` is still supported for backwardscompatibility.
|
||||
|
|
|
@ -112,25 +112,55 @@ curl -XPUT localhost:9200/test/type1/_warmer/warmer_1 -d '{
|
|||
}'
|
||||
--------------------------------------------------
|
||||
|
||||
[float]
|
||||
[[removing]]
|
||||
=== Delete Warmer
|
||||
|
||||
Removing a warmer can be done against an index (or alias / indices)
|
||||
based on its name. The provided name can be a simple wildcard expression
|
||||
or omitted to remove all warmers. Some samples:
|
||||
All options:
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
# delete warmer named warmer_1 on test index
|
||||
curl -XDELETE localhost:9200/test/_warmer/warmer_1
|
||||
|
||||
# delete all warmers that start with warm on test index
|
||||
curl -XDELETE localhost:9200/test/_warmer/warm*
|
||||
PUT _warmer/{warmer_name}
|
||||
|
||||
PUT /{index}/_warmer/{warmer_name}
|
||||
|
||||
PUT /{index}/{type}/_warmer/{warmer_name}
|
||||
|
||||
# delete all warmers for test index
|
||||
curl -XDELETE localhost:9200/test/_warmer/
|
||||
--------------------------------------------------
|
||||
|
||||
|
||||
where
|
||||
|
||||
[horizontal]
|
||||
`{index}`:: `* | _all | glob pattern | name1, name2, …`
|
||||
|
||||
`{type}`:: `* | _all | glob pattern | name1, name2, …`
|
||||
|
||||
Instead of `_warmer` you can also use the plural `_warmers`.
|
||||
|
||||
|
||||
|
||||
[float]
|
||||
[[removing]]
|
||||
=== Delete Warmers
|
||||
|
||||
Warmers can be deleted using the following endpoint:
|
||||
|
||||
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
|
||||
[DELETE] /{index}/_warmer/{name}
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
|
||||
where
|
||||
|
||||
[horizontal]
|
||||
`{index}`:: `* | _all | glob pattern | name1, name2, …`
|
||||
|
||||
`{name}`:: `* | _all | glob pattern | name1, name2, …`
|
||||
|
||||
Instead of `_warmer` you can also use the plural `_warmers`.
|
||||
|
||||
[float]
|
||||
[[warmer-retrieving]]
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"methods": ["DELETE"],
|
||||
"url": {
|
||||
"path": "/{index}/_alias/{name}",
|
||||
"paths": ["/{index}/_alias/{name}"],
|
||||
"paths": ["/{index}/_alias/{name}", "/{index}/_aliases/{name}"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "string",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"methods": ["DELETE"],
|
||||
"url": {
|
||||
"path": "/{index}/{type}/_mapping",
|
||||
"paths": ["/{index}/{type}/_mapping", "/{index}/{type}"],
|
||||
"paths": ["/{index}/{type}/_mapping", "/{index}/{type}", "/{index}/_mapping/{type}", "/{index}/{type}/_mappings", "/{index}/_mappings/{type}"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
"documentation": "http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-warmers.html",
|
||||
"methods": ["DELETE"],
|
||||
"url": {
|
||||
"path": "/{index}/_warmer",
|
||||
"paths": ["/{index}/_warmer", "/{index}/_warmer/{name}", "/{index}/{type}/_warmer/{name}"],
|
||||
"path": "/{index}/_warmer/{name}",
|
||||
"paths": ["/{index}/_warmer", "/{index}/_warmer/{name}", "/{index}/_warmers", "/{index}/_warmers/{name}"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"indices.put_alias": {
|
||||
"documentation": "http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html",
|
||||
"methods": ["PUT"],
|
||||
"methods": ["PUT", "POST"],
|
||||
"url": {
|
||||
"path": "/{index}/_alias/{name}",
|
||||
"paths": ["/{index}/_alias/{name}", "/_alias/{name}", "/{index}/_alias", "/_alias"],
|
||||
"paths": ["/{index}/_alias/{name}", "/_alias/{name}", "/{index}/_aliases/{name}", "/_aliases/{name}"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "string",
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
"methods": ["PUT", "POST"],
|
||||
"url": {
|
||||
"path": "/{index}/{type}/_mapping",
|
||||
"paths": ["/{index}/{type}/_mapping"],
|
||||
"paths": ["/{index}/{type}/_mapping", "/{index}/_mapping/{type}", "/_mapping/{type}", "/{index}/{type}/_mappings", "/{index}/_mappings/{type}", "/_mappings/{type}"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
"required" : true,
|
||||
"required" : false,
|
||||
"description" : "A comma-separated list of index names; use `_all` to perform the operation on all indices"
|
||||
},
|
||||
"type": {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"indices.put_warmer": {
|
||||
"documentation": "http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-warmers.html",
|
||||
"methods": ["PUT"],
|
||||
"methods": ["PUT", "POST"],
|
||||
"url": {
|
||||
"path": "/{index}/_warmer/{name}",
|
||||
"paths": ["/{index}/_warmer/{name}", "/{index}/{type}/_warmer/{name}"],
|
||||
"paths": ["/_warmer/{name}", "/{index}/_warmer/{name}", "/{index}/{type}/_warmer/{name}", "/_warmers/{name}", "/{index}/_warmers/{name}", "/{index}/{type}/_warmers/{name}"],
|
||||
"parts": {
|
||||
"index": {
|
||||
"type" : "list",
|
||||
|
|
|
@ -0,0 +1,225 @@
|
|||
---
|
||||
setup:
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index1
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index2
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: foo
|
||||
|
||||
- do:
|
||||
indices.put_alias:
|
||||
name: alias1
|
||||
body:
|
||||
routing: "routing value"
|
||||
- do:
|
||||
indices.put_alias:
|
||||
name: alias2
|
||||
body:
|
||||
routing: "routing value"
|
||||
|
||||
---
|
||||
"check setup":
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
|
||||
- match: {test_index1.aliases.alias1.search_routing: "routing value"}
|
||||
- match: {test_index2.aliases.alias1.search_routing: "routing value"}
|
||||
- match: {foo.aliases.alias1.search_routing: "routing value"}
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {test_index1.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {test_index2.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
|
||||
---
|
||||
"check delete with _all index":
|
||||
- do:
|
||||
indices.delete_alias:
|
||||
index: _all
|
||||
name: alias1
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {test_index1.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {test_index2.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
|
||||
---
|
||||
"check delete with * index":
|
||||
- do:
|
||||
indices.delete_alias:
|
||||
index: "*"
|
||||
name: alias1
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {test_index1.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {test_index2.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
|
||||
---
|
||||
"check delete with index list":
|
||||
- do:
|
||||
indices.delete_alias:
|
||||
index: "test_index1,test_index2"
|
||||
name: alias1
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
|
||||
- match: {foo.aliases.alias1.search_routing: "routing value"}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {test_index1.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {test_index2.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
|
||||
---
|
||||
"check delete with prefix* index":
|
||||
- do:
|
||||
indices.delete_alias:
|
||||
index: "test_*"
|
||||
name: alias1
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
|
||||
- match: {foo.aliases.alias1.search_routing: "routing value"}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {test_index1.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {test_index2.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
|
||||
|
||||
---
|
||||
"check delete with index list and * aliases":
|
||||
- do:
|
||||
indices.delete_alias:
|
||||
index: "test_index1,test_index2"
|
||||
name: "*"
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
|
||||
- match: {foo.aliases.alias1.search_routing: "routing value"}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
---
|
||||
"check delete with index list and _all aliases":
|
||||
- do:
|
||||
indices.delete_alias:
|
||||
index: "test_index1,test_index2"
|
||||
name: _all
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
|
||||
- match: {foo.aliases.alias1.search_routing: "routing value"}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
---
|
||||
"check delete with index list and wildcard aliases":
|
||||
- do:
|
||||
indices.delete_alias:
|
||||
index: "test_index1,test_index2"
|
||||
name: "*1"
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias1
|
||||
|
||||
- match: {foo.aliases.alias1.search_routing: "routing value"}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias2
|
||||
|
||||
- match: {test_index1.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {test_index2.aliases.alias2.search_routing: "routing value"}
|
||||
- match: {foo.aliases.alias2.search_routing: "routing value"}
|
||||
|
||||
---
|
||||
"check 404 on no matching alias":
|
||||
- do:
|
||||
catch: missing
|
||||
indices.delete_alias:
|
||||
index: "*"
|
||||
name: "non_existent"
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.delete_alias:
|
||||
index: "non_existent"
|
||||
name: "alias1"
|
||||
|
||||
|
||||
---
|
||||
"check delete with blank index and blank alias":
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_alias:
|
||||
name: "alias1"
|
||||
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_alias:
|
||||
index: "test_index1"
|
||||
|
|
@ -0,0 +1,286 @@
|
|||
setup:
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index1
|
||||
body:
|
||||
mappings: { test_type1: { }}
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index2
|
||||
body:
|
||||
mappings: { test_type2: { }}
|
||||
- do:
|
||||
indices.create:
|
||||
index: foo
|
||||
body:
|
||||
mappings: { test_type2: { }}
|
||||
|
||||
---
|
||||
"delete with _all index":
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: _all
|
||||
type: test_type2
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_true: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
---
|
||||
"delete with * index":
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: '*'
|
||||
type: test_type2
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_true: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
---
|
||||
"delete with prefix* index":
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: test*
|
||||
type: test_type2
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_true: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_true: ''
|
||||
|
||||
---
|
||||
"delete with list of indices":
|
||||
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: test_index1,test_index2
|
||||
type: test_type2
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_true: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_true: ''
|
||||
|
||||
---
|
||||
"delete with index list and _all type":
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: test_index1,test_index2
|
||||
type: _all
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_true: ''
|
||||
|
||||
|
||||
---
|
||||
"delete with index list and * type":
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: test_index1,test_index2
|
||||
type: '*'
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_true: ''
|
||||
|
||||
|
||||
---
|
||||
"delete with index list and prefix* type":
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: test_index1,test_index2
|
||||
type: '*2'
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_true: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_true: ''
|
||||
|
||||
---
|
||||
"delete with index list and list of types":
|
||||
- do:
|
||||
indices.delete_mapping:
|
||||
index: test_index1,test_index2
|
||||
type: test_type1,test_type2
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index1
|
||||
type: test_type1
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test_index2
|
||||
type: test_type2
|
||||
|
||||
- is_false: ''
|
||||
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: foo
|
||||
type: test_type2
|
||||
|
||||
- is_true: ''
|
||||
|
||||
---
|
||||
"check 404 on no matching type":
|
||||
- do:
|
||||
catch: missing
|
||||
indices.delete_mapping:
|
||||
index: "*"
|
||||
type: "non_existent"
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.delete_mapping:
|
||||
index: "non_existent"
|
||||
type: "test_type1"
|
||||
|
||||
|
||||
---
|
||||
"check delete with blank index and blank alias":
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_alias:
|
||||
name: "alias1"
|
||||
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_alias:
|
||||
index: "test_index1"
|
||||
|
||||
|
||||
---
|
||||
"check delete with blank index and blank type":
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_mapping:
|
||||
name: "test_type1"
|
||||
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_mapping:
|
||||
index: "test_index1"
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index1
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index2
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: foo
|
||||
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: "test_index1,test_index2,foo"
|
||||
name: test_warmer1
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: "test_index1,test_index2,foo"
|
||||
name: test_warmer2
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
|
||||
---
|
||||
"Check setup":
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: '*' }
|
||||
|
||||
- match: {test_index1.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- match: {test_index1.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {foo.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
|
||||
|
||||
---
|
||||
"check delete with _all index":
|
||||
- do:
|
||||
indices.delete_warmer:
|
||||
index: _all
|
||||
name: test_warmer1
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer1' }
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer2' }
|
||||
|
||||
|
||||
- match: {test_index1.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
|
||||
---
|
||||
"check delete with * index":
|
||||
- do:
|
||||
indices.delete_warmer:
|
||||
index: "*"
|
||||
name: test_warmer1
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer1' }
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer2' }
|
||||
|
||||
|
||||
- match: {test_index1.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
|
||||
---
|
||||
"check delete with index list":
|
||||
- do:
|
||||
indices.delete_warmer:
|
||||
index: "test_index1,test_index2"
|
||||
name: test_warmer1
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer1' }
|
||||
|
||||
- match: {foo.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer2' }
|
||||
|
||||
- match: {test_index1.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
|
||||
---
|
||||
"check delete with prefix* index":
|
||||
- do:
|
||||
indices.delete_warmer:
|
||||
index: "test_*"
|
||||
name: test_warmer1
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer1' }
|
||||
|
||||
- match: {foo.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer2' }
|
||||
|
||||
- match: {test_index1.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
|
||||
|
||||
---
|
||||
"check delete with index list and * warmers":
|
||||
- do:
|
||||
indices.delete_warmer:
|
||||
index: "test_index1,test_index2"
|
||||
name: "*"
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer1' }
|
||||
|
||||
- match: {foo.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer2' }
|
||||
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
---
|
||||
"check delete with index list and _all warmers":
|
||||
- do:
|
||||
indices.delete_warmer:
|
||||
index: "test_index1,test_index2"
|
||||
name: _all
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer1' }
|
||||
|
||||
- match: {foo.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer2' }
|
||||
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
---
|
||||
"check delete with index list and wildcard warmers":
|
||||
- do:
|
||||
indices.delete_warmer:
|
||||
index: "test_index1,test_index2"
|
||||
name: "*1"
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer1' }
|
||||
|
||||
- match: {foo.warmers.test_warmer1.source.query.match_all: {}}
|
||||
- is_false: test_index1
|
||||
- is_false: test_index2
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: 'test_warmer2' }
|
||||
|
||||
- match: {test_index1.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.test_warmer2.source.query.match_all: {}}
|
||||
- match: {foo.warmers.test_warmer2.source.query.match_all: {}}
|
||||
|
||||
---
|
||||
"check 404 on no matching test_warmer":
|
||||
- do:
|
||||
catch: missing
|
||||
indices.delete_warmer:
|
||||
index: "*"
|
||||
name: "non_existent"
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.delete_warmer:
|
||||
index: "non_existent"
|
||||
name: "test_warmer1"
|
||||
|
||||
|
||||
---
|
||||
"check delete with blank index and blank test_warmer":
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_warmer:
|
||||
name: "test_warmer1"
|
||||
|
||||
- do:
|
||||
catch: param
|
||||
indices.delete_warmer:
|
||||
index: "test_index1"
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
---
|
||||
setup:
|
||||
# create three indices
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index1
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index2
|
||||
- do:
|
||||
indices.create:
|
||||
index: foo
|
||||
|
||||
---
|
||||
"put alias per index":
|
||||
|
||||
- do:
|
||||
indices.put_alias:
|
||||
index: test_index1
|
||||
name: alias
|
||||
- do:
|
||||
indices.put_alias:
|
||||
index: test_index2
|
||||
name: alias
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias
|
||||
|
||||
- match: {test_index1.aliases.alias: {}}
|
||||
|
||||
- match: {test_index2.aliases.alias: {}}
|
||||
|
||||
- is_false: foo
|
||||
|
||||
---
|
||||
"put alias in _all index":
|
||||
|
||||
- do:
|
||||
indices.put_alias:
|
||||
index: _all
|
||||
name: alias
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias
|
||||
|
||||
- match: {test_index1.aliases.alias: {}}
|
||||
- match: {test_index2.aliases.alias: {}}
|
||||
- match: {foo.aliases.alias: {}}
|
||||
|
||||
---
|
||||
"put alias in * index":
|
||||
|
||||
|
||||
- do:
|
||||
indices.put_alias:
|
||||
index: '*'
|
||||
name: alias
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias
|
||||
|
||||
- match: {test_index1.aliases.alias: {}}
|
||||
- match: {test_index2.aliases.alias: {}}
|
||||
- match: {foo.aliases.alias: {}}
|
||||
|
||||
---
|
||||
"put alias prefix* index":
|
||||
|
||||
|
||||
- do:
|
||||
indices.put_alias:
|
||||
index: "test_*"
|
||||
name: alias
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias
|
||||
|
||||
- match: {test_index1.aliases.alias: {}}
|
||||
- match: {test_index2.aliases.alias: {}}
|
||||
- is_false: foo
|
||||
|
||||
---
|
||||
"put alias in list of indices":
|
||||
|
||||
|
||||
- do:
|
||||
indices.put_alias:
|
||||
index: "test_index1,test_index2"
|
||||
name: alias
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias
|
||||
|
||||
- match: {test_index1.aliases.alias: {}}
|
||||
- match: {test_index2.aliases.alias: {}}
|
||||
- is_false: foo
|
||||
|
||||
---
|
||||
"put alias with blank index":
|
||||
|
||||
|
||||
- do:
|
||||
indices.put_alias:
|
||||
name: alias
|
||||
|
||||
- do:
|
||||
indices.get_alias:
|
||||
name: alias
|
||||
|
||||
- match: {test_index1.aliases.alias: {}}
|
||||
- match: {test_index2.aliases.alias: {}}
|
||||
- match: {foo.aliases.alias: {}}
|
||||
|
||||
---
|
||||
"put alias with mising name":
|
||||
|
||||
|
||||
- do:
|
||||
catch: param
|
||||
indices.put_alias: {}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index1
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index2
|
||||
- do:
|
||||
indices.create:
|
||||
index: foo
|
||||
|
||||
|
||||
---
|
||||
"put one mapping per index":
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: test_index1
|
||||
type: test_type
|
||||
body:
|
||||
test_type:
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
analyzer: whitespace
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: test_index2
|
||||
type: test_type
|
||||
body:
|
||||
test_type:
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
analyzer: whitespace
|
||||
|
||||
|
||||
- do:
|
||||
indices.get_mapping: {}
|
||||
|
||||
- match: {test_index1.test_type.properties.text.type: string}
|
||||
- match: {test_index1.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {test_index2.test_type.properties.text.type: string}
|
||||
- match: {test_index2.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {foo: {}}
|
||||
|
||||
---
|
||||
"put mapping in _all index":
|
||||
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: _all
|
||||
type: test_type
|
||||
body:
|
||||
test_type:
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
analyzer: whitespace
|
||||
|
||||
- do:
|
||||
indices.get_mapping: {}
|
||||
|
||||
- match: {test_index1.test_type.properties.text.type: string}
|
||||
- match: {test_index1.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {test_index2.test_type.properties.text.type: string}
|
||||
- match: {test_index2.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {foo.test_type.properties.text.type: string}
|
||||
- match: {foo.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
---
|
||||
"put mapping in * index":
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: "*"
|
||||
type: test_type
|
||||
body:
|
||||
test_type:
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
analyzer: whitespace
|
||||
|
||||
- do:
|
||||
indices.get_mapping: {}
|
||||
|
||||
- match: {test_index1.test_type.properties.text.type: string}
|
||||
- match: {test_index1.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {test_index2.test_type.properties.text.type: string}
|
||||
- match: {test_index2.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {foo.test_type.properties.text.type: string}
|
||||
- match: {foo.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
---
|
||||
"put mapping in prefix* index":
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: "test_index*"
|
||||
type: test_type
|
||||
body:
|
||||
test_type:
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
analyzer: whitespace
|
||||
|
||||
- do:
|
||||
indices.get_mapping: {}
|
||||
|
||||
- match: {test_index1.test_type.properties.text.type: string}
|
||||
- match: {test_index1.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {test_index2.test_type.properties.text.type: string}
|
||||
- match: {test_index2.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {foo: {}}
|
||||
|
||||
---
|
||||
"put mapping in list of indices":
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: [test_index1, test_index2]
|
||||
type: test_type
|
||||
body:
|
||||
test_type:
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
analyzer: whitespace
|
||||
|
||||
- do:
|
||||
indices.get_mapping: {}
|
||||
|
||||
- match: {test_index1.test_type.properties.text.type: string}
|
||||
- match: {test_index1.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {test_index2.test_type.properties.text.type: string}
|
||||
- match: {test_index2.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {foo: {}}
|
||||
|
||||
---
|
||||
"put mapping with blank index":
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
type: test_type
|
||||
body:
|
||||
test_type:
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
analyzer: whitespace
|
||||
|
||||
- do:
|
||||
indices.get_mapping: {}
|
||||
|
||||
- match: {test_index1.test_type.properties.text.type: string}
|
||||
- match: {test_index1.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {test_index2.test_type.properties.text.type: string}
|
||||
- match: {test_index2.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
- match: {foo.test_type.properties.text.type: string}
|
||||
- match: {foo.test_type.properties.text.analyzer: whitespace}
|
||||
|
||||
---
|
||||
"put mapping with mising type":
|
||||
|
||||
|
||||
- do:
|
||||
catch: param
|
||||
indices.put_mapping: {}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index1
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index2
|
||||
- do:
|
||||
indices.create:
|
||||
index: foo
|
||||
|
||||
|
||||
---
|
||||
"put settings per index":
|
||||
- do:
|
||||
indices.put_settings:
|
||||
index: test_index1
|
||||
body:
|
||||
refresh_interval: 1s
|
||||
|
||||
- do:
|
||||
indices.put_settings:
|
||||
index: test_index2
|
||||
body:
|
||||
refresh_interval: 1s
|
||||
|
||||
|
||||
- do:
|
||||
indices.get_settings: {}
|
||||
|
||||
- match: {test_index1.settings.index.refresh_interval: 1s}
|
||||
- match: {test_index2.settings.index.refresh_interval: 1s}
|
||||
- is_false: foo.settings.index.refresh_interval
|
||||
|
||||
---
|
||||
"put settings in _all index":
|
||||
- do:
|
||||
indices.put_settings:
|
||||
index: _all
|
||||
body:
|
||||
refresh_interval: 1s
|
||||
|
||||
- do:
|
||||
indices.get_settings: {}
|
||||
|
||||
- match: {test_index1.settings.index.refresh_interval: 1s}
|
||||
- match: {test_index2.settings.index.refresh_interval: 1s}
|
||||
- match: {foo.settings.index.refresh_interval: 1s}
|
||||
|
||||
---
|
||||
"put settings in * index":
|
||||
- do:
|
||||
indices.put_settings:
|
||||
index: '*'
|
||||
body:
|
||||
refresh_interval: 1s
|
||||
|
||||
- do:
|
||||
indices.get_settings: {}
|
||||
|
||||
- match: {test_index1.settings.index.refresh_interval: 1s}
|
||||
- match: {test_index2.settings.index.refresh_interval: 1s}
|
||||
- match: {foo.settings.index.refresh_interval: 1s}
|
||||
|
||||
|
||||
---
|
||||
"put settings in prefix* index":
|
||||
- do:
|
||||
indices.put_settings:
|
||||
index: 'test*'
|
||||
body:
|
||||
refresh_interval: 1s
|
||||
|
||||
- do:
|
||||
indices.get_settings: {}
|
||||
|
||||
- match: {test_index1.settings.index.refresh_interval: 1s}
|
||||
- match: {test_index2.settings.index.refresh_interval: 1s}
|
||||
- is_false: foo.settings.index.refresh_interval
|
||||
|
||||
---
|
||||
"put settings in list of indices":
|
||||
- skip:
|
||||
version: 1 - 999
|
||||
reason: list of indices not implemented yet
|
||||
- do:
|
||||
indices.put_settings:
|
||||
index: test_index1, test_index2
|
||||
body:
|
||||
refresh_interval: 1s
|
||||
|
||||
- do:
|
||||
indices.get_settings: {}
|
||||
|
||||
- match: {test_index1.settings.index.refresh_interval: 1s}
|
||||
- match: {test_index2.settings.index.refresh_interval: 1s}
|
||||
- is_false: foo.settings.index.refresh_interval
|
||||
|
||||
|
||||
---
|
||||
"put settings in blank index":
|
||||
- do:
|
||||
indices.put_settings:
|
||||
body:
|
||||
refresh_interval: 1s
|
||||
|
||||
- do:
|
||||
indices.get_settings: {}
|
||||
|
||||
- match: {test_index1.settings.index.refresh_interval: 1s}
|
||||
- match: {test_index2.settings.index.refresh_interval: 1s}
|
||||
- match: {foo.settings.index.refresh_interval: 1s}
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
- do:
|
||||
indices.delete_warmer:
|
||||
index: test_index
|
||||
name: test_warmer
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
---
|
||||
setup:
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index1
|
||||
- do:
|
||||
indices.create:
|
||||
index: test_index2
|
||||
- do:
|
||||
indices.create:
|
||||
index: foo
|
||||
|
||||
---
|
||||
"put warmer per index":
|
||||
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: test_index1
|
||||
name: warmer
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: test_index2
|
||||
name: warmer
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: '*' }
|
||||
|
||||
- match: {test_index1.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.warmer.source.query.match_all: {}}
|
||||
- is_false: foo
|
||||
|
||||
---
|
||||
"put warmer in _all index":
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: _all
|
||||
name: warmer
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: '*' }
|
||||
|
||||
- match: {test_index1.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {foo.warmers.warmer.source.query.match_all: {}}
|
||||
|
||||
---
|
||||
"put warmer in * index":
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: "*"
|
||||
name: warmer
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: '*' }
|
||||
|
||||
- match: {test_index1.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {foo.warmers.warmer.source.query.match_all: {}}
|
||||
|
||||
---
|
||||
"put warmer prefix* index":
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: "test_index*"
|
||||
name: warmer
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: '*' }
|
||||
|
||||
- match: {test_index1.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.warmer.source.query.match_all: {}}
|
||||
- is_false: foo
|
||||
|
||||
---
|
||||
"put warmer in list of indices":
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
index: [test_index1, test_index2]
|
||||
name: warmer
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: '*' }
|
||||
|
||||
- match: {test_index1.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.warmer.source.query.match_all: {}}
|
||||
- is_false: foo
|
||||
|
||||
---
|
||||
"put warmer with blank index":
|
||||
- do:
|
||||
indices.put_warmer:
|
||||
name: warmer
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
- do:
|
||||
indices.get_warmer: { index: _all, name: '*' }
|
||||
|
||||
- match: {test_index1.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {test_index2.warmers.warmer.source.query.match_all: {}}
|
||||
- match: {foo.warmers.warmer.source.query.match_all: {}}
|
||||
|
||||
---
|
||||
"put warmer with mising name":
|
||||
|
||||
|
||||
- do:
|
||||
catch: param
|
||||
indices.put_warmer: {}
|
||||
|
||||
|
||||
|
||||
|
|
@ -19,21 +19,25 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.alias;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.elasticsearch.ElasticsearchGenerationException;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.cluster.metadata.AliasAction;
|
||||
import org.elasticsearch.cluster.metadata.AliasAction.Type;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
import org.elasticsearch.index.query.FilterBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
@ -46,115 +50,260 @@ import static org.elasticsearch.cluster.metadata.AliasAction.readAliasAction;
|
|||
*/
|
||||
public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesRequest> {
|
||||
|
||||
private List<AliasAction> aliasActions = Lists.newArrayList();
|
||||
private List<AliasActions> allAliasActions = Lists.newArrayList();
|
||||
|
||||
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, false);
|
||||
|
||||
public IndicesAliasesRequest() {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Aliases can be added by passing multiple indices to the Request and
|
||||
* deleted by passing multiple indices and aliases. They are expanded into
|
||||
* distinct AliasAction instances when the request is processed. This class
|
||||
* holds the AliasAction and in addition the arrays or alias names and
|
||||
* indices that is later used to create the final AliasAction instances.
|
||||
*/
|
||||
public static class AliasActions {
|
||||
private String[] indices = Strings.EMPTY_ARRAY;
|
||||
private String[] aliases = Strings.EMPTY_ARRAY;
|
||||
private AliasAction aliasAction;
|
||||
|
||||
public AliasActions(AliasAction.Type type, String[] indices, String[] aliases) {
|
||||
aliasAction = new AliasAction(type);
|
||||
indices(indices);
|
||||
aliases(aliases);
|
||||
}
|
||||
|
||||
public AliasActions(AliasAction.Type type, String index, String alias) {
|
||||
aliasAction = new AliasAction(type);
|
||||
indices(index);
|
||||
aliases(alias);
|
||||
}
|
||||
|
||||
AliasActions(AliasAction.Type type, String[] index, String alias) {
|
||||
aliasAction = new AliasAction(type);
|
||||
indices(index);
|
||||
aliases(alias);
|
||||
}
|
||||
|
||||
public AliasActions(AliasAction action) {
|
||||
this.aliasAction = action;
|
||||
indices(action.index());
|
||||
aliases(action.alias());
|
||||
}
|
||||
|
||||
public AliasActions(Type type, String index, String[] aliases) {
|
||||
aliasAction = new AliasAction(type);
|
||||
indices(index);
|
||||
aliases(aliases);
|
||||
}
|
||||
|
||||
public AliasActions() {
|
||||
}
|
||||
|
||||
public AliasActions filter(Map<String, Object> filter) {
|
||||
aliasAction.filter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AliasActions filter(FilterBuilder filter) {
|
||||
aliasAction.filter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Type actionType() {
|
||||
return aliasAction.actionType();
|
||||
}
|
||||
|
||||
public void routing(String routing) {
|
||||
aliasAction.routing(routing);
|
||||
}
|
||||
|
||||
public void searchRouting(String searchRouting) {
|
||||
aliasAction.searchRouting(searchRouting);
|
||||
}
|
||||
|
||||
public void indexRouting(String indexRouting) {
|
||||
aliasAction.indexRouting(indexRouting);
|
||||
}
|
||||
|
||||
public AliasActions filter(String filter) {
|
||||
aliasAction.filter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void indices(String... indices) {
|
||||
List<String> finalIndices = new ArrayList<String>();
|
||||
for (String index : indices) {
|
||||
if (index != null) {
|
||||
finalIndices.add(index);
|
||||
}
|
||||
}
|
||||
this.indices = finalIndices.toArray(new String[finalIndices.size()]);
|
||||
}
|
||||
|
||||
public void aliases(String... aliases) {
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
public String[] aliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public String[] indices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
public AliasAction aliasAction() {
|
||||
return aliasAction;
|
||||
}
|
||||
|
||||
public String[] concreteAliases(MetaData metaData, String concreteIndex) {
|
||||
if (aliasAction.actionType() == Type.REMOVE) {
|
||||
//for DELETE we expand the aliases
|
||||
String[] indexAsArray = {concreteIndex};
|
||||
ImmutableOpenMap<String, ImmutableList<AliasMetaData>> aliasMetaData = metaData.findAliases(aliases, indexAsArray);
|
||||
List<String> finalAliases = new ArrayList<String> ();
|
||||
for (ObjectCursor<ImmutableList<AliasMetaData>> curAliases : aliasMetaData.values()) {
|
||||
for (AliasMetaData aliasMeta: curAliases.value) {
|
||||
finalAliases.add(aliasMeta.alias());
|
||||
}
|
||||
}
|
||||
return finalAliases.toArray(new String[finalAliases.size()]);
|
||||
} else {
|
||||
//for add we just return the current aliases
|
||||
return aliases;
|
||||
}
|
||||
}
|
||||
public AliasActions readFrom(StreamInput in) throws IOException {
|
||||
indices = in.readStringArray();
|
||||
aliases = in.readStringArray();
|
||||
aliasAction = readAliasAction(in);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeStringArray(indices);
|
||||
out.writeStringArray(aliases);
|
||||
this.aliasAction.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
* @param indices The indices
|
||||
*/
|
||||
public IndicesAliasesRequest addAlias(String index, String alias) {
|
||||
aliasActions.add(new AliasAction(AliasAction.Type.ADD, index, alias));
|
||||
public IndicesAliasesRequest addAlias(String alias, String... indices) {
|
||||
addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void addAliasAction(AliasActions aliasAction) {
|
||||
allAliasActions.add(aliasAction);
|
||||
}
|
||||
|
||||
|
||||
public IndicesAliasesRequest addAliasAction(AliasAction action) {
|
||||
addAliasAction(new AliasActions(action));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
* @param alias The alias
|
||||
* @param filter The filter
|
||||
* @param indices The indices
|
||||
*/
|
||||
public IndicesAliasesRequest addAlias(String alias, Map<String, Object> filter, String... indices) {
|
||||
addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filter));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
* @param filter The filter
|
||||
*/
|
||||
public IndicesAliasesRequest addAlias(String index, String alias, String filter) {
|
||||
aliasActions.add(new AliasAction(AliasAction.Type.ADD, index, alias, filter));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
* @param filter The filter
|
||||
*/
|
||||
public IndicesAliasesRequest addAlias(String index, String alias, Map<String, Object> filter) {
|
||||
if (filter == null || filter.isEmpty()) {
|
||||
aliasActions.add(new AliasAction(AliasAction.Type.ADD, index, alias));
|
||||
return this;
|
||||
}
|
||||
try {
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
builder.map(filter);
|
||||
aliasActions.add(new AliasAction(AliasAction.Type.ADD, index, alias, builder.string()));
|
||||
return this;
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchGenerationException("Failed to generate [" + filter + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
* @param filterBuilder The filter
|
||||
* @param indices The indices
|
||||
*/
|
||||
public IndicesAliasesRequest addAlias(String index, String alias, FilterBuilder filterBuilder) {
|
||||
if (filterBuilder == null) {
|
||||
aliasActions.add(new AliasAction(AliasAction.Type.ADD, index, alias));
|
||||
return this;
|
||||
}
|
||||
try {
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
filterBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.close();
|
||||
return addAlias(index, alias, builder.string());
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
|
||||
}
|
||||
public IndicesAliasesRequest addAlias(String alias, FilterBuilder filterBuilder, String... indices) {
|
||||
addAliasAction(new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filterBuilder));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes an alias to the index.
|
||||
*
|
||||
* @param indices The indices
|
||||
* @param aliases The aliases
|
||||
*/
|
||||
public IndicesAliasesRequest removeAlias(String[] indices, String... aliases) {
|
||||
addAliasAction(new AliasActions(AliasAction.Type.REMOVE, indices, aliases));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
* @param aliases The aliases
|
||||
*/
|
||||
public IndicesAliasesRequest removeAlias(String index, String alias) {
|
||||
aliasActions.add(new AliasAction(AliasAction.Type.REMOVE, index, alias));
|
||||
public IndicesAliasesRequest removeAlias(String index, String... aliases) {
|
||||
addAliasAction(new AliasActions(AliasAction.Type.REMOVE, index, aliases));
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndicesAliasesRequest addAliasAction(AliasAction action) {
|
||||
aliasActions.add(action);
|
||||
return this;
|
||||
List<AliasActions> aliasActions() {
|
||||
return this.allAliasActions;
|
||||
}
|
||||
|
||||
List<AliasAction> aliasActions() {
|
||||
return this.aliasActions;
|
||||
}
|
||||
|
||||
public List<AliasAction> getAliasActions() {
|
||||
public List<AliasActions> getAliasActions() {
|
||||
return aliasActions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
ActionRequestValidationException validationException = null;
|
||||
if (aliasActions.isEmpty()) {
|
||||
if (allAliasActions.isEmpty()) {
|
||||
return addValidationError("Must specify at least one alias action", validationException);
|
||||
}
|
||||
for (AliasAction aliasAction : aliasActions) {
|
||||
if (!Strings.hasText(aliasAction.alias())) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH) + "] requires an [alias] to be set", validationException);
|
||||
for (AliasActions aliasAction : allAliasActions) {
|
||||
if (aliasAction.actionType() == AliasAction.Type.ADD) {
|
||||
if (aliasAction.aliases.length != 1) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
||||
+ "] requires exactly one [alias] to be set", validationException);
|
||||
}
|
||||
if (!Strings.hasText(aliasAction.aliases[0])) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
||||
+ "] requires an [alias] to be set", validationException);
|
||||
}
|
||||
} else {
|
||||
if (aliasAction.aliases.length == 0) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
||||
+ "]: aliases may not be empty", validationException);
|
||||
}
|
||||
for (String alias : aliasAction.aliases) {
|
||||
if (!Strings.hasText(alias)) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
||||
+ "]: [alias] may not be empty string", validationException);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isEmpty(aliasAction.indices)) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
||||
+ "]: indices may not be empty", validationException);
|
||||
}
|
||||
}
|
||||
if (!Strings.hasText(aliasAction.index())) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH) + "] requires an [index] to be set", validationException);
|
||||
if (!CollectionUtils.isEmpty(aliasAction.indices)) {
|
||||
for (String index : aliasAction.indices) {
|
||||
if (!Strings.hasText(index)) {
|
||||
validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
|
||||
+ "]: [index] may not be empty string", validationException);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return validationException;
|
||||
|
@ -165,7 +314,7 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|||
super.readFrom(in);
|
||||
int size = in.readVInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
aliasActions.add(readAliasAction(in));
|
||||
allAliasActions.add(readAliasActions(in));
|
||||
}
|
||||
readTimeout(in);
|
||||
}
|
||||
|
@ -173,10 +322,20 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
|||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeVInt(aliasActions.size());
|
||||
for (AliasAction aliasAction : aliasActions) {
|
||||
out.writeVInt(allAliasActions.size());
|
||||
for (AliasActions aliasAction : allAliasActions) {
|
||||
aliasAction.writeTo(out);
|
||||
}
|
||||
writeTimeout(out);
|
||||
}
|
||||
|
||||
public IndicesOptions indicesOptions() {
|
||||
return indicesOptions;
|
||||
}
|
||||
|
||||
private AliasActions readAliasActions(StreamInput in) throws IOException {
|
||||
AliasActions actions = new AliasActions();
|
||||
return actions.readFrom(in);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.action.admin.indices.alias;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
|
||||
|
@ -36,15 +37,26 @@ public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder<Ind
|
|||
public IndicesAliasesRequestBuilder(IndicesAdminClient indicesClient) {
|
||||
super((InternalIndicesAdminClient) indicesClient, new IndicesAliasesRequest());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String index, String alias) {
|
||||
request.addAlias(index, alias);
|
||||
request.addAlias(alias, index);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The indices
|
||||
* @param alias The alias
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String[] indices, String alias) {
|
||||
request.addAlias(alias, indices);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -56,46 +68,74 @@ public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder<Ind
|
|||
* @param filter The filter
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String index, String alias, String filter) {
|
||||
request.addAlias(index, alias, filter);
|
||||
AliasActions action = new AliasActions(AliasAction.Type.ADD, index, alias).filter(filter);
|
||||
request.addAliasAction(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param indices The indices
|
||||
* @param alias The alias
|
||||
* @param filter The filter
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String indices[], String alias, String filter) {
|
||||
AliasActions action = new AliasActions(AliasAction.Type.ADD, indices, alias).filter(filter);
|
||||
request.addAliasAction(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param indices The indices
|
||||
* @param alias The alias
|
||||
* @param filter The filter
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String[] indices, String alias, Map<String, Object> filter) {
|
||||
request.addAlias(alias, filter, indices);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The indices
|
||||
* @param alias The alias
|
||||
* @param filter The filter
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String index, String alias, Map<String, Object> filter) {
|
||||
request.addAlias(index, alias, filter);
|
||||
request.addAlias(alias, filter, index);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param indices The indices
|
||||
* @param alias The alias
|
||||
* @param filterBuilder The filter
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String indices[], String alias, FilterBuilder filterBuilder) {
|
||||
request.addAlias(alias, filterBuilder, indices);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias to the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
* @param filterBuilder The filter
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAlias(String index, String alias, FilterBuilder filterBuilder) {
|
||||
request.addAlias(index, alias, filterBuilder);
|
||||
request.addAlias(alias, filterBuilder, index);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias action to the request.
|
||||
*
|
||||
* @param aliasAction The alias Action
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAliasAction(AliasAction aliasAction) {
|
||||
request.addAliasAction(aliasAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an alias to the index.
|
||||
* Removes an alias from the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param alias The alias
|
||||
|
@ -104,9 +144,54 @@ public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder<Ind
|
|||
request.removeAlias(index, alias);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes aliases from the index.
|
||||
*
|
||||
* @param indices The indices
|
||||
* @param aliases The aliases
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder removeAlias(String[] indices, String... aliases) {
|
||||
request.removeAlias(indices, aliases);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes aliases from the index.
|
||||
*
|
||||
* @param index The index
|
||||
* @param aliases The aliases
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder removeAlias(String index, String[] aliases) {
|
||||
request.removeAlias(index, aliases);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<IndicesAliasesResponse> listener) {
|
||||
((IndicesAdminClient) client).aliases(request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias action to the request.
|
||||
*
|
||||
* @param aliasAction The alias action
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAliasAction(AliasAction aliasAction) {
|
||||
request.addAliasAction(aliasAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an alias action to the request.
|
||||
*
|
||||
* @param aliasAction The alias action
|
||||
*/
|
||||
public IndicesAliasesRequestBuilder addAliasAction(
|
||||
AliasActions action) {
|
||||
request.addAliasAction(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.action.admin.indices.alias;
|
|||
import com.google.common.collect.Sets;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
|
@ -33,9 +34,13 @@ import org.elasticsearch.cluster.metadata.AliasAction;
|
|||
import org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -76,8 +81,10 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeOperationA
|
|||
@Override
|
||||
protected ClusterBlockException checkBlock(IndicesAliasesRequest request, ClusterState state) {
|
||||
Set<String> indices = Sets.newHashSet();
|
||||
for (AliasAction aliasAction : request.aliasActions()) {
|
||||
indices.add(aliasAction.index());
|
||||
for (AliasActions aliasAction : request.aliasActions()) {
|
||||
for (String index : aliasAction.indices()) {
|
||||
indices.add(index);
|
||||
}
|
||||
}
|
||||
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, indices.toArray(new String[indices.size()]));
|
||||
}
|
||||
|
@ -85,9 +92,36 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeOperationA
|
|||
@Override
|
||||
protected void masterOperation(final IndicesAliasesRequest request, final ClusterState state, final ActionListener<IndicesAliasesResponse> listener) throws ElasticsearchException {
|
||||
|
||||
//Expand the indices names
|
||||
List<AliasActions> actions = request.aliasActions();
|
||||
List<AliasAction> finalActions = new ArrayList<AliasAction>();
|
||||
boolean hasOnlyDeletesButNoneCanBeDone = true;
|
||||
Set<String> aliases = new HashSet<String>();
|
||||
for (AliasActions action : actions) {
|
||||
//expand indices
|
||||
String[] concreteIndices = state.metaData().concreteIndices(action.indices(), request.indicesOptions());
|
||||
//collect the aliases
|
||||
for (String alias : action.aliases()) {
|
||||
aliases.add(alias);
|
||||
}
|
||||
for (String index : concreteIndices) {
|
||||
for (String alias : action.concreteAliases(state.metaData(), index)) {
|
||||
AliasAction finalAction = new AliasAction(action.aliasAction());
|
||||
finalAction.index(index);
|
||||
finalAction.alias(alias);
|
||||
finalActions.add(finalAction);
|
||||
//if there is only delete requests, none will be added if the types do not map to any existing type
|
||||
hasOnlyDeletesButNoneCanBeDone = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasOnlyDeletesButNoneCanBeDone && actions.size() != 0) {
|
||||
throw new AliasesMissingException(aliases.toArray(new String[aliases.size()]));
|
||||
}
|
||||
request.aliasActions().clear();
|
||||
IndicesAliasesClusterStateUpdateRequest updateRequest = new IndicesAliasesClusterStateUpdateRequest()
|
||||
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
|
||||
.actions(request.aliasActions().toArray(new AliasAction[request.aliasActions().size()]));
|
||||
.actions(finalActions.toArray(new AliasAction[finalActions.size()]));
|
||||
|
||||
indexAliasesService.indicesAliases(updateRequest, new ClusterStateUpdateListener() {
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.cluster.ack.IndicesClusterStateUpdateRequest;
|
|||
*/
|
||||
public class DeleteMappingClusterStateUpdateRequest extends IndicesClusterStateUpdateRequest<DeleteMappingClusterStateUpdateRequest> {
|
||||
|
||||
private String type;
|
||||
private String[] types;
|
||||
|
||||
DeleteMappingClusterStateUpdateRequest() {
|
||||
|
||||
|
@ -35,15 +35,15 @@ public class DeleteMappingClusterStateUpdateRequest extends IndicesClusterStateU
|
|||
/**
|
||||
* Returns the type to be removed
|
||||
*/
|
||||
public String type() {
|
||||
return type;
|
||||
public String[] types() {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type to be removed
|
||||
*/
|
||||
public DeleteMappingClusterStateUpdateRequest type(String type) {
|
||||
this.type = type;
|
||||
public DeleteMappingClusterStateUpdateRequest types(String[] types) {
|
||||
this.types = types;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,10 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -37,7 +39,7 @@ public class DeleteMappingRequest extends AcknowledgedRequest<DeleteMappingReque
|
|||
|
||||
private String[] indices;
|
||||
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, false);
|
||||
private String type;
|
||||
private String[] types;
|
||||
|
||||
DeleteMappingRequest() {
|
||||
}
|
||||
|
@ -53,8 +55,29 @@ public class DeleteMappingRequest extends AcknowledgedRequest<DeleteMappingReque
|
|||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
ActionRequestValidationException validationException = null;
|
||||
if (type == null) {
|
||||
if (CollectionUtils.isEmpty(types)) {
|
||||
validationException = addValidationError("mapping type is missing", validationException);
|
||||
} else {
|
||||
validationException = checkForEmptyString(validationException, types);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(indices)) {
|
||||
validationException = addValidationError("index is missing", validationException);
|
||||
} else {
|
||||
validationException = checkForEmptyString(validationException, indices);
|
||||
}
|
||||
|
||||
return validationException;
|
||||
}
|
||||
|
||||
private ActionRequestValidationException checkForEmptyString(ActionRequestValidationException validationException, String[] strings) {
|
||||
boolean containsEmptyString = false;
|
||||
for (String string : strings) {
|
||||
if (!Strings.hasText(string)) {
|
||||
containsEmptyString = true;
|
||||
}
|
||||
}
|
||||
if (containsEmptyString) {
|
||||
validationException = addValidationError("types must not contain empty strings", validationException);
|
||||
}
|
||||
return validationException;
|
||||
}
|
||||
|
@ -84,52 +107,35 @@ public class DeleteMappingRequest extends AcknowledgedRequest<DeleteMappingReque
|
|||
}
|
||||
|
||||
/**
|
||||
* The mapping type.
|
||||
* The mapping types.
|
||||
*/
|
||||
public String type() {
|
||||
return type;
|
||||
public String[] types() {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the mappings to remove.
|
||||
*/
|
||||
public DeleteMappingRequest type(String type) {
|
||||
this.type = type;
|
||||
public DeleteMappingRequest types(String... types) {
|
||||
this.types = types;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
indices = new String[in.readVInt()];
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
indices[i] = in.readString();
|
||||
}
|
||||
indices = in.readStringArray();
|
||||
indicesOptions = IndicesOptions.readIndicesOptions(in);
|
||||
if (in.readBoolean()) {
|
||||
type = in.readString();
|
||||
}
|
||||
types = in.readStringArray();
|
||||
readTimeout(in, Version.V_0_90_6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
if (indices == null) {
|
||||
out.writeVInt(0);
|
||||
} else {
|
||||
out.writeVInt(indices.length);
|
||||
for (String index : indices) {
|
||||
out.writeString(index);
|
||||
}
|
||||
}
|
||||
out.writeStringArrayNullable(indices);
|
||||
indicesOptions.writeIndicesOptions(out);
|
||||
if (type == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeString(type);
|
||||
}
|
||||
out.writeStringArrayNullable(types);
|
||||
writeTimeout(out, Version.V_0_90_6);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ public class DeleteMappingRequestBuilder extends AcknowledgedRequestBuilder<Dele
|
|||
/**
|
||||
* Sets the type of the mapping to remove
|
||||
*/
|
||||
public DeleteMappingRequestBuilder setType(String type) {
|
||||
request.type(type);
|
||||
public DeleteMappingRequestBuilder setType(String... types) {
|
||||
request.types(types);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.mapping.delete;
|
||||
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
|
||||
|
@ -37,15 +38,21 @@ import org.elasticsearch.cluster.ack.ClusterStateUpdateListener;
|
|||
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaDataMappingService;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.FilterBuilders;
|
||||
import org.elasticsearch.index.query.OrFilterBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.TypeFilterBuilder;
|
||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Delete mapping action.
|
||||
*/
|
||||
|
@ -108,8 +115,23 @@ public class TransportDeleteMappingAction extends TransportMasterNodeOperationAc
|
|||
flushAction.execute(Requests.flushRequest(request.indices()), new ActionListener<FlushResponse>() {
|
||||
@Override
|
||||
public void onResponse(FlushResponse flushResponse) {
|
||||
|
||||
// get all types that need to be deleted.
|
||||
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> result = state.metaData().findMappings(
|
||||
request.indices(), request.types()
|
||||
);
|
||||
// create OrFilter with type filters within to account for different types
|
||||
OrFilterBuilder filterBuilder = new OrFilterBuilder();
|
||||
Set<String> types = new HashSet<String>();
|
||||
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> typesMeta : result) {
|
||||
for (ObjectObjectCursor<String, MappingMetaData> type : typesMeta.value) {
|
||||
filterBuilder.add(new TypeFilterBuilder(type.key));
|
||||
types.add(type.key);
|
||||
}
|
||||
}
|
||||
request.types(types.toArray(new String[types.size()]));
|
||||
QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder()
|
||||
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.typeFilter(request.type())));
|
||||
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filterBuilder));
|
||||
deleteByQueryAction.execute(Requests.deleteByQueryRequest(request.indices()).source(querySourceBuilder), new ActionListener<DeleteByQueryResponse>() {
|
||||
@Override
|
||||
public void onResponse(DeleteByQueryResponse deleteByQueryResponse) {
|
||||
|
@ -126,7 +148,7 @@ public class TransportDeleteMappingAction extends TransportMasterNodeOperationAc
|
|||
|
||||
protected void removeMapping() {
|
||||
DeleteMappingClusterStateUpdateRequest clusterStateUpdateRequest = new DeleteMappingClusterStateUpdateRequest()
|
||||
.indices(request.indices()).type(request.type())
|
||||
.indices(request.indices()).types(request.types())
|
||||
.ackTimeout(request.timeout())
|
||||
.masterNodeTimeout(request.masterNodeTimeout());
|
||||
|
||||
|
|
|
@ -26,15 +26,18 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||
|
||||
/**
|
||||
* A request to delete an index warmer.
|
||||
*/
|
||||
public class DeleteWarmerRequest extends AcknowledgedRequest<DeleteWarmerRequest> {
|
||||
|
||||
private String name;
|
||||
private String[] names = Strings.EMPTY_ARRAY;
|
||||
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, false);
|
||||
private String[] indices = Strings.EMPTY_ARRAY;
|
||||
|
||||
|
@ -46,36 +49,60 @@ public class DeleteWarmerRequest extends AcknowledgedRequest<DeleteWarmerRequest
|
|||
*
|
||||
* @param name: the name (or wildcard expression) of the warmer to match, null to delete all.
|
||||
*/
|
||||
public DeleteWarmerRequest(String name) {
|
||||
this.name = name;
|
||||
public DeleteWarmerRequest(String... names) {
|
||||
names(names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
ActionRequestValidationException validationException = null;
|
||||
if (CollectionUtils.isEmpty(names)) {
|
||||
validationException = addValidationError("warmer names are missing", validationException);
|
||||
} else {
|
||||
validationException = checkForEmptyString(validationException, names);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(indices)) {
|
||||
validationException = addValidationError("indices are missing", validationException);
|
||||
} else {
|
||||
validationException = checkForEmptyString(validationException, indices);
|
||||
}
|
||||
return validationException;
|
||||
}
|
||||
|
||||
private ActionRequestValidationException checkForEmptyString(ActionRequestValidationException validationException, String[] strings) {
|
||||
boolean containsEmptyString = false;
|
||||
for (String string : strings) {
|
||||
if (!Strings.hasText(string)) {
|
||||
containsEmptyString = true;
|
||||
}
|
||||
}
|
||||
if (containsEmptyString) {
|
||||
validationException = addValidationError("types must not contain empty strings", validationException);
|
||||
}
|
||||
return validationException;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name to delete.
|
||||
*/
|
||||
@Nullable
|
||||
String name() {
|
||||
return name;
|
||||
String[] names() {
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name (or wildcard expression) of the index warmer to delete, or null
|
||||
* to delete all warmers.
|
||||
*/
|
||||
public DeleteWarmerRequest name(@Nullable String name) {
|
||||
this.name = name;
|
||||
public DeleteWarmerRequest names(@Nullable String... names) {
|
||||
this.names = names;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the indices this put mapping operation will execute on.
|
||||
*/
|
||||
public DeleteWarmerRequest indices(String[] indices) {
|
||||
public DeleteWarmerRequest indices(String... indices) {
|
||||
this.indices = indices;
|
||||
return this;
|
||||
}
|
||||
|
@ -99,7 +126,7 @@ public class DeleteWarmerRequest extends AcknowledgedRequest<DeleteWarmerRequest
|
|||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
name = in.readOptionalString();
|
||||
names = in.readStringArray();
|
||||
indices = in.readStringArray();
|
||||
indicesOptions = IndicesOptions.readIndicesOptions(in);
|
||||
readTimeout(in, Version.V_0_90_6);
|
||||
|
@ -108,7 +135,7 @@ public class DeleteWarmerRequest extends AcknowledgedRequest<DeleteWarmerRequest
|
|||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeOptionalString(name);
|
||||
out.writeStringArrayNullable(names);
|
||||
out.writeStringArrayNullable(indices);
|
||||
indicesOptions.writeIndicesOptions(out);
|
||||
writeTimeout(out, Version.V_0_90_6);
|
||||
|
|
|
@ -43,8 +43,8 @@ public class DeleteWarmerRequestBuilder extends AcknowledgedRequestBuilder<Delet
|
|||
* The name (or wildcard expression) of the index warmer to delete, or null
|
||||
* to delete all warmers.
|
||||
*/
|
||||
public DeleteWarmerRequestBuilder setName(String name) {
|
||||
request.name(name);
|
||||
public DeleteWarmerRequestBuilder setNames(String... names) {
|
||||
request.names(names);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.elasticsearch.search.warmer.IndexWarmersMetaData;
|
|||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -89,7 +90,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
|
|||
|
||||
@Override
|
||||
protected void masterOperation(final DeleteWarmerRequest request, final ClusterState state, final ActionListener<DeleteWarmerResponse> listener) throws ElasticsearchException {
|
||||
clusterService.submitStateUpdateTask("delete_warmer [" + request.name() + "]", new AckedClusterStateUpdateTask() {
|
||||
clusterService.submitStateUpdateTask("delete_warmer [" + Arrays.toString(request.names()) + "]", new AckedClusterStateUpdateTask() {
|
||||
|
||||
@Override
|
||||
public boolean mustAck(DiscoveryNode discoveryNode) {
|
||||
|
@ -118,7 +119,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
|
|||
|
||||
@Override
|
||||
public void onFailure(String source, Throwable t) {
|
||||
logger.debug("failed to delete warmer [{}] on indices [{}]", t, request.name(), request.indices());
|
||||
logger.debug("failed to delete warmer [{}] on indices [{}]", t, Arrays.toString(request.names()), request.indices());
|
||||
listener.onFailure(t);
|
||||
}
|
||||
|
||||
|
@ -136,10 +137,16 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
|
|||
if (warmers != null) {
|
||||
List<IndexWarmersMetaData.Entry> entries = Lists.newArrayList();
|
||||
for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
|
||||
if (request.name() == null || Regex.simpleMatch(request.name(), entry.name())) {
|
||||
globalFoundAtLeastOne = true;
|
||||
// don't add it...
|
||||
} else {
|
||||
boolean keepWarmer = true;
|
||||
for (String warmer : request.names()) {
|
||||
if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals("_all")) {
|
||||
globalFoundAtLeastOne = true;
|
||||
keepWarmer = false;
|
||||
// don't add it...
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (keepWarmer) {
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
|
@ -153,11 +160,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
|
|||
}
|
||||
|
||||
if (!globalFoundAtLeastOne) {
|
||||
if (request.name() == null) {
|
||||
// full match, just return with no failure
|
||||
return currentState;
|
||||
}
|
||||
throw new IndexWarmerMissingException(request.name());
|
||||
throw new IndexWarmerMissingException(request.names());
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
|
@ -169,8 +172,10 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
|
|||
IndexWarmersMetaData warmers = indexMetaData.custom(IndexWarmersMetaData.TYPE);
|
||||
if (warmers != null) {
|
||||
for (IndexWarmersMetaData.Entry entry : warmers.entries()) {
|
||||
if (Regex.simpleMatch(request.name(), entry.name())) {
|
||||
logger.info("[{}] delete warmer [{}]", index, entry.name());
|
||||
for (String warmer : request.names()) {
|
||||
if (Regex.simpleMatch(warmer, entry.name()) || warmer.equals("_all")) {
|
||||
logger.info("[{}] delete warmer [{}]", index, entry.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,20 @@ public class AliasAction implements Streamable {
|
|||
private AliasAction() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public AliasAction(AliasAction other) {
|
||||
this.actionType = other.actionType;
|
||||
this.index = other.index;
|
||||
this.alias = other.alias;
|
||||
this.filter = other.filter;
|
||||
this.indexRouting = other.indexRouting;
|
||||
this.searchRouting = other.searchRouting;
|
||||
}
|
||||
|
||||
public AliasAction(Type actionType) {
|
||||
this.actionType = actionType;
|
||||
}
|
||||
|
||||
public AliasAction(Type actionType, String index, String alias) {
|
||||
this.actionType = actionType;
|
||||
this.index = index;
|
||||
|
@ -99,10 +112,20 @@ public class AliasAction implements Streamable {
|
|||
public Type actionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public AliasAction index(String index) {
|
||||
this.index = index;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String index() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public AliasAction alias(String alias) {
|
||||
this.alias = alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String alias() {
|
||||
return alias;
|
||||
|
@ -181,42 +204,21 @@ public class AliasAction implements Streamable {
|
|||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
actionType = Type.fromValue(in.readByte());
|
||||
index = in.readString();
|
||||
alias = in.readString();
|
||||
if (in.readBoolean()) {
|
||||
filter = in.readString();
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
indexRouting = in.readString();
|
||||
}
|
||||
if (in.readBoolean()) {
|
||||
searchRouting = in.readString();
|
||||
}
|
||||
index = in.readOptionalString();
|
||||
alias = in.readOptionalString();
|
||||
filter = in.readOptionalString();
|
||||
indexRouting = in.readOptionalString();
|
||||
searchRouting = in.readOptionalString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeByte(actionType.value());
|
||||
out.writeString(index);
|
||||
out.writeString(alias);
|
||||
if (filter == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeString(filter);
|
||||
}
|
||||
if (indexRouting == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeString(indexRouting);
|
||||
}
|
||||
if (searchRouting == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeString(searchRouting);
|
||||
}
|
||||
out.writeOptionalString(index);
|
||||
out.writeOptionalString(alias);
|
||||
out.writeOptionalString(filter);
|
||||
out.writeOptionalString(indexRouting);
|
||||
out.writeOptionalString(searchRouting);
|
||||
}
|
||||
|
||||
public static AliasAction newAddAliasAction(String index, String alias) {
|
||||
|
|
|
@ -279,7 +279,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
return ImmutableOpenMap.of();
|
||||
}
|
||||
|
||||
boolean matchAllAliases = aliases.length == 0;
|
||||
boolean matchAllAliases = matchAllAliases(aliases);
|
||||
ImmutableOpenMap.Builder<String, ImmutableList<AliasMetaData>> mapBuilder = ImmutableOpenMap.builder();
|
||||
Iterable<String> intersection = HppcMaps.intersection(ObjectOpenHashSet.from(concreteIndices), indices.keys());
|
||||
for (String index : intersection) {
|
||||
|
@ -298,6 +298,15 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
}
|
||||
return mapBuilder.build();
|
||||
}
|
||||
|
||||
private boolean matchAllAliases(final String[] aliases) {
|
||||
for (String alias : aliases) {
|
||||
if (alias.equals("_all")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return aliases.length == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the
|
||||
|
@ -331,6 +340,12 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds all mappings for types and concrete indices. Types are expanded to
|
||||
* include all types that match the glob patterns in the types array. Empty
|
||||
* types array, null or {"_all"} will be expanded to all types available for
|
||||
* the given indices.
|
||||
*/
|
||||
public ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> findMappings(String[] concreteIndices, final String[] types) {
|
||||
assert types != null;
|
||||
assert concreteIndices != null;
|
||||
|
@ -343,7 +358,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
for (String index : intersection) {
|
||||
IndexMetaData indexMetaData = indices.get(index);
|
||||
ImmutableOpenMap.Builder<String, MappingMetaData> filteredMappings;
|
||||
if (types.length == 0) {
|
||||
if (isAllTypes(types)) {
|
||||
indexMapBuilder.put(index, indexMetaData.getMappings()); // No types specified means get it all
|
||||
|
||||
} else {
|
||||
|
@ -945,7 +960,18 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
* @return true if the provided array maps to all indices, false otherwise
|
||||
*/
|
||||
public boolean isAllIndices(String[] aliasesOrIndices) {
|
||||
return aliasesOrIndices == null || aliasesOrIndices.length == 0 || isExplicitAllIndices(aliasesOrIndices);
|
||||
return aliasesOrIndices == null || aliasesOrIndices.length == 0 || isExplicitAllPattern(aliasesOrIndices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies whether the array containing type names given as argument refers to all types
|
||||
* The empty or null array identifies all types
|
||||
*
|
||||
* @param types the array containing index names
|
||||
* @return true if the provided array maps to all indices, false otherwise
|
||||
*/
|
||||
public boolean isAllTypes(String[] types) {
|
||||
return types == null || types.length == 0 || isExplicitAllPattern(types);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -955,7 +981,7 @@ public class MetaData implements Iterable<IndexMetaData> {
|
|||
* @param aliasesOrIndices the array containing index names
|
||||
* @return true if the provided array explicitly maps to all indices, false otherwise
|
||||
*/
|
||||
public boolean isExplicitAllIndices(String[] aliasesOrIndices) {
|
||||
public boolean isExplicitAllPattern(String[] aliasesOrIndices) {
|
||||
return aliasesOrIndices != null && aliasesOrIndices.length == 1 && "_all".equals(aliasesOrIndices[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -385,7 +385,7 @@ public class MetaDataMappingService extends AbstractComponent {
|
|||
}
|
||||
|
||||
public void removeMapping(final DeleteMappingClusterStateUpdateRequest request, final ClusterStateUpdateListener listener) {
|
||||
clusterService.submitStateUpdateTask("remove-mapping [" + request.type() + "]", Priority.HIGH, new AckedClusterStateUpdateTask() {
|
||||
clusterService.submitStateUpdateTask("remove-mapping [" + Arrays.toString(request.types()) + "]", Priority.HIGH, new AckedClusterStateUpdateTask() {
|
||||
|
||||
@Override
|
||||
public boolean mustAck(DiscoveryNode discoveryNode) {
|
||||
|
@ -428,21 +428,30 @@ public class MetaDataMappingService extends AbstractComponent {
|
|||
String latestIndexWithout = null;
|
||||
for (String indexName : request.indices()) {
|
||||
IndexMetaData indexMetaData = currentState.metaData().index(indexName);
|
||||
IndexMetaData.Builder indexBuilder = IndexMetaData.builder(indexMetaData);
|
||||
|
||||
if (indexMetaData != null) {
|
||||
if (indexMetaData.mappings().containsKey(request.type())) {
|
||||
builder.put(IndexMetaData.builder(indexMetaData).removeMapping(request.type()));
|
||||
changed = true;
|
||||
} else {
|
||||
boolean isLatestIndexWithout = true;
|
||||
for (String type : request.types()) {
|
||||
if (indexMetaData.mappings().containsKey(type)) {
|
||||
indexBuilder.removeMapping(type);
|
||||
changed = true;
|
||||
isLatestIndexWithout = false;
|
||||
}
|
||||
}
|
||||
if (isLatestIndexWithout) {
|
||||
latestIndexWithout = indexMetaData.index();
|
||||
}
|
||||
|
||||
}
|
||||
builder.put(indexBuilder);
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
throw new TypeMissingException(new Index(latestIndexWithout), request.type());
|
||||
throw new TypeMissingException(new Index(latestIndexWithout), request.types());
|
||||
}
|
||||
|
||||
logger.info("[{}] remove_mapping [{}]", request.indices(), request.type());
|
||||
logger.info("[{}] remove_mapping [{}]", request.indices(), request.types());
|
||||
|
||||
return ClusterState.builder(currentState).metaData(builder).build();
|
||||
}
|
||||
|
|
|
@ -187,5 +187,16 @@ public enum CollectionUtils {
|
|||
}
|
||||
return uniqueCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given array contains any elements.
|
||||
*
|
||||
* @param array The array to check
|
||||
*
|
||||
* @return false if the array contains an element, true if not or the array is null.
|
||||
*/
|
||||
public static boolean isEmpty(Object[] array) {
|
||||
return array == null || array.length == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,17 +23,19 @@ import org.elasticsearch.index.Index;
|
|||
import org.elasticsearch.index.IndexException;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TypeMissingException extends IndexException {
|
||||
|
||||
public TypeMissingException(Index index, String type) {
|
||||
super(index, "type[" + type + "] missing");
|
||||
public TypeMissingException(Index index, String... types) {
|
||||
super(index, "type[" + Arrays.toString(types) + "] missing");
|
||||
}
|
||||
|
||||
public TypeMissingException(Index index, String type, String message) {
|
||||
super(index, "type[" + type + "] missing: " + message);
|
||||
public TypeMissingException(Index index, String[] types, String message) {
|
||||
super(index, "type[" + Arrays.toString(types) + "] missing: " + message);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.rest.action.admin.indices.alias.delete;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AliasesMissingException extends ElasticsearchException {
|
||||
|
||||
private final String[] names;
|
||||
|
||||
public AliasesMissingException(String... names) {
|
||||
super("aliases [" + Arrays.toString(names) + "] missing");
|
||||
this.names = names;
|
||||
}
|
||||
|
||||
public String[] names() {
|
||||
return this.names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestStatus status() {
|
||||
return RestStatus.NOT_FOUND;
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.rest.action.admin.indices.alias.delete;
|
|||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
|
@ -35,15 +36,16 @@ public class RestIndexDeleteAliasesAction extends BaseRestHandler {
|
|||
public RestIndexDeleteAliasesAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(DELETE, "/{index}/_alias/{name}", this);
|
||||
controller.registerHandler(DELETE, "/{index}/_aliases/{name}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
final String index = request.param("index");
|
||||
String alias = request.param("name");
|
||||
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));
|
||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
|
||||
indicesAliasesRequest.removeAlias(index, alias);
|
||||
indicesAliasesRequest.removeAlias(indices, aliases);
|
||||
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
|
||||
|
||||
client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestResponseActionListener<IndicesAliasesResponse>(request, channel, logger));
|
||||
|
|
|
@ -20,9 +20,11 @@ package org.elasticsearch.rest.action.admin.indices.alias.put;
|
|||
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.metadata.AliasAction;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
@ -32,6 +34,7 @@ import org.elasticsearch.rest.*;
|
|||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||
|
||||
/**
|
||||
|
@ -43,13 +46,22 @@ public class RestIndexPutAliasAction extends BaseRestHandler {
|
|||
super(settings, client);
|
||||
controller.registerHandler(PUT, "/{index}/_alias/{name}", this);
|
||||
controller.registerHandler(PUT, "/_alias/{name}", this);
|
||||
controller.registerHandler(PUT, "/{index}/_aliases/{name}", this);
|
||||
controller.registerHandler(PUT, "/_aliases/{name}", this);
|
||||
controller.registerHandler(PUT, "/{index}/_alias", this);
|
||||
controller.registerHandler(PUT, "/_alias", this);
|
||||
|
||||
controller.registerHandler(POST, "/{index}/_alias/{name}", this);
|
||||
controller.registerHandler(POST, "/_alias/{name}", this);
|
||||
controller.registerHandler(POST, "/{index}/_aliases/{name}", this);
|
||||
controller.registerHandler(POST, "/_aliases/{name}", this);
|
||||
controller.registerHandler(PUT, "/{index}/_aliases", this);
|
||||
//we cannot add POST for "/_aliases" because this is the _aliases api already defined in RestIndicesAliasesAction
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
String index = request.param("index");
|
||||
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
String alias = request.param("name");
|
||||
Map<String, Object> filter = null;
|
||||
String routing = null;
|
||||
|
@ -70,7 +82,7 @@ public class RestIndexPutAliasAction extends BaseRestHandler {
|
|||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("index".equals(currentFieldName)) {
|
||||
index = parser.text();
|
||||
indices = Strings.splitStringByCommaToArray(parser.text());
|
||||
} else if ("alias".equals(currentFieldName)) {
|
||||
alias = parser.text();
|
||||
} else if ("routing".equals(currentFieldName)) {
|
||||
|
@ -102,9 +114,11 @@ public class RestIndexPutAliasAction extends BaseRestHandler {
|
|||
|
||||
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
|
||||
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
|
||||
AliasAction aliasAction = new AliasAction(AliasAction.Type.ADD, index, alias);
|
||||
String[] aliases = new String[] {alias};
|
||||
IndicesAliasesRequest.AliasActions aliasAction = new AliasActions(AliasAction.Type.ADD, indices, aliases);
|
||||
indicesAliasesRequest.addAliasAction(aliasAction);
|
||||
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
|
||||
|
||||
|
||||
if (routing != null) {
|
||||
aliasAction.routing(routing);
|
||||
|
|
|
@ -41,13 +41,18 @@ public class RestDeleteMappingAction extends BaseRestHandler {
|
|||
super(settings, client);
|
||||
controller.registerHandler(DELETE, "/{index}/{type}/_mapping", this);
|
||||
controller.registerHandler(DELETE, "/{index}/{type}", this);
|
||||
controller.registerHandler(DELETE, "/{index}/_mapping/{type}", this);
|
||||
|
||||
//support _mappings also
|
||||
controller.registerHandler(DELETE, "/{index}/{type}/_mappings", this);
|
||||
controller.registerHandler(DELETE, "/{index}/_mappings/{type}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
DeleteMappingRequest deleteMappingRequest = deleteMappingRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
deleteMappingRequest.listenerThreaded(false);
|
||||
deleteMappingRequest.type(request.param("type"));
|
||||
deleteMappingRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
|
||||
deleteMappingRequest.timeout(request.paramAsTime("timeout", deleteMappingRequest.timeout()));
|
||||
deleteMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteMappingRequest.masterNodeTimeout()));
|
||||
deleteMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteMappingRequest.indicesOptions()));
|
||||
|
|
|
@ -37,14 +37,30 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
|||
*/
|
||||
public class RestPutMappingAction extends BaseRestHandler {
|
||||
|
||||
|
||||
@Inject
|
||||
public RestPutMappingAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(PUT, "/{index}/_mapping", this);
|
||||
controller.registerHandler(PUT, "/{index}/_mapping/", this);
|
||||
controller.registerHandler(PUT, "/{index}/{type}/_mapping", this);
|
||||
controller.registerHandler(PUT, "/{index}/_mapping/{type}", this);
|
||||
controller.registerHandler(PUT, "/_mapping/{type}", this);
|
||||
|
||||
controller.registerHandler(POST, "/{index}/_mapping", this);
|
||||
controller.registerHandler(POST, "/{index}/_mapping/", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_mapping", this);
|
||||
controller.registerHandler(POST, "/{index}/_mapping/{type}", this);
|
||||
controller.registerHandler(POST, "/_mapping/{type}", this);
|
||||
|
||||
//register the same paths, but with plural form _mappings
|
||||
controller.registerHandler(PUT, "/{index}/_mappings/", this);
|
||||
controller.registerHandler(PUT, "/{index}/{type}/_mappings", this);
|
||||
controller.registerHandler(PUT, "/{index}/_mappings/{type}", this);
|
||||
controller.registerHandler(PUT, "/_mappings/{type}", this);
|
||||
|
||||
controller.registerHandler(POST, "/{index}/_mappings/", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_mappings", this);
|
||||
controller.registerHandler(POST, "/{index}/_mappings/{type}", this);
|
||||
controller.registerHandler(POST, "/_mappings/{type}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,12 +37,13 @@ public class RestDeleteWarmerAction extends BaseRestHandler {
|
|||
super(settings, client);
|
||||
controller.registerHandler(DELETE, "/{index}/_warmer", this);
|
||||
controller.registerHandler(DELETE, "/{index}/_warmer/{name}", this);
|
||||
controller.registerHandler(DELETE, "/{index}/{type}/_warmer/{name}", this);
|
||||
controller.registerHandler(DELETE, "/{index}/_warmers", this);
|
||||
controller.registerHandler(DELETE, "/{index}/_warmers/{name}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
DeleteWarmerRequest deleteWarmerRequest = new DeleteWarmerRequest(request.param("name"))
|
||||
DeleteWarmerRequest deleteWarmerRequest = new DeleteWarmerRequest(Strings.splitStringByCommaToArray(request.param("name")))
|
||||
.indices(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
deleteWarmerRequest.listenerThreaded(false);
|
||||
deleteWarmerRequest.timeout(request.paramAsTime("timeout", deleteWarmerRequest.timeout()));
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.inject.Inject;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.*;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||
|
||||
/**
|
||||
|
@ -36,8 +37,21 @@ public class RestPutWarmerAction extends BaseRestHandler {
|
|||
@Inject
|
||||
public RestPutWarmerAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
controller.registerHandler(PUT, "/_warmer/{name}", this);
|
||||
controller.registerHandler(PUT, "/{index}/_warmer/{name}", this);
|
||||
controller.registerHandler(PUT, "/{index}/{type}/_warmer/{name}", this);
|
||||
|
||||
controller.registerHandler(PUT, "/_warmers/{name}", this);
|
||||
controller.registerHandler(PUT, "/{index}/_warmers/{name}", this);
|
||||
controller.registerHandler(PUT, "/{index}/{type}/_warmers/{name}", this);
|
||||
|
||||
controller.registerHandler(POST, "/_warmer/{name}", this);
|
||||
controller.registerHandler(POST, "/{index}/_warmer/{name}", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_warmer/{name}", this);
|
||||
|
||||
controller.registerHandler(POST, "/_warmers/{name}", this);
|
||||
controller.registerHandler(POST, "/{index}/_warmers/{name}", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_warmers/{name}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,20 +21,22 @@ package org.elasticsearch.search.warmer;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class IndexWarmerMissingException extends ElasticsearchException {
|
||||
|
||||
private final String name;
|
||||
private final String[] names;
|
||||
|
||||
public IndexWarmerMissingException(String name) {
|
||||
super("index_warmer [" + name + "] missing");
|
||||
this.name = name;
|
||||
public IndexWarmerMissingException(String... names) {
|
||||
super("index_warmer [" + Arrays.toString(names) + "] missing");
|
||||
this.names = names;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return this.name;
|
||||
public String[] names() {
|
||||
return this.names;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class DeleteWarmerRequestTests extends ElasticsearchTestCase {
|
|||
DeleteWarmerRequest inRequest = new DeleteWarmerRequest();
|
||||
inRequest.readFrom(esBuffer);
|
||||
|
||||
assertThat(inRequest.name(), equalTo("warmer1"));
|
||||
assertThat(inRequest.names()[0], equalTo("warmer1"));
|
||||
//timeout is default as we don't read it from the received buffer
|
||||
assertThat(inRequest.timeout().millis(), equalTo(new DeleteWarmerRequest().timeout().millis()));
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class DeleteWarmerRequestTests extends ElasticsearchTestCase {
|
|||
DeleteWarmerRequest inRequest = new DeleteWarmerRequest();
|
||||
inRequest.readFrom(esBuffer);
|
||||
|
||||
assertThat(inRequest.name(), equalTo("warmer1"));
|
||||
assertThat(inRequest.names()[0], equalTo("warmer1"));
|
||||
//timeout is default as we don't read it from the received buffer
|
||||
assertThat(inRequest.timeout().millis(), equalTo(outRequest.timeout().millis()));
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.query.FilterBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.indices.IndexMissingException;
|
||||
import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.facet.FacetBuilders;
|
||||
|
@ -90,7 +92,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
|
|||
ensureGreen();
|
||||
|
||||
logger.info("--> remove [alias1], Aliasing index [test_x] with [alias1]");
|
||||
admin().indices().aliases(indexAliasesRequest().removeAlias("test", "alias1").addAlias("test_x", "alias1")).actionGet();
|
||||
admin().indices().aliases(indexAliasesRequest().removeAlias("test", "alias1").addAlias("alias1", "test_x")).actionGet();
|
||||
Thread.sleep(300);
|
||||
|
||||
logger.info("--> indexing against [alias1], should work against [test_x]");
|
||||
|
@ -412,6 +414,43 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
|
|||
assertHits(searchResponse.getHits(), "4");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteAliases() throws Exception {
|
||||
|
||||
logger.info("--> creating index [test1]");
|
||||
admin().indices().create(createIndexRequest("test1")).actionGet();
|
||||
|
||||
logger.info("--> creating index [test2]");
|
||||
admin().indices().create(createIndexRequest("test2")).actionGet();
|
||||
|
||||
ensureGreen();
|
||||
|
||||
logger.info("--> adding filtering aliases to index [test1]");
|
||||
admin().indices().prepareAliases().addAlias("test1", "aliasToTest1").execute().actionGet();
|
||||
admin().indices().prepareAliases().addAlias("test1", "aliasToTests").execute().actionGet();
|
||||
admin().indices().prepareAliases().addAlias("test1", "foos", termFilter("name", "foo")).execute().actionGet();
|
||||
admin().indices().prepareAliases().addAlias("test1", "bars", termFilter("name", "bar")).execute().actionGet();
|
||||
admin().indices().prepareAliases().addAlias("test1", "tests", termFilter("name", "test")).execute().actionGet();
|
||||
|
||||
logger.info("--> adding filtering aliases to index [test2]");
|
||||
admin().indices().prepareAliases().addAlias("test2", "aliasToTest2").execute().actionGet();
|
||||
admin().indices().prepareAliases().addAlias("test2", "aliasToTests").execute().actionGet();
|
||||
admin().indices().prepareAliases().addAlias("test2", "foos", termFilter("name", "foo")).execute().actionGet();
|
||||
admin().indices().prepareAliases().addAlias("test2", "tests", termFilter("name", "test")).execute().actionGet();
|
||||
|
||||
String[] indices = {"test1", "test2"};
|
||||
String[] aliases = {"aliasToTest1", "foos", "bars", "tests", "aliasToTest2", "aliasToTests"};
|
||||
|
||||
admin().indices().prepareAliases().removeAlias(indices, aliases).execute().actionGet();
|
||||
|
||||
AliasesExistResponse response = admin().indices().prepareAliasesExist(aliases).execute().actionGet();
|
||||
assertThat(response.exists(), equalTo(false));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWaitForAliasCreationMultipleShards() throws Exception {
|
||||
|
||||
|
@ -512,10 +551,16 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(admin().indices().prepareAliases().removeAlias("test", "alias1").setTimeout(timeout).execute().actionGet().isAcknowledged(), equalTo(true));
|
||||
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
|
||||
|
||||
logger.info("--> deleting alias1 one more time");
|
||||
stopWatch.start();
|
||||
assertThat(admin().indices().prepareAliases().removeAlias("test", "alias1").setTimeout(timeout).execute().actionGet().isAcknowledged(), equalTo(true));
|
||||
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = AliasesMissingException.class)
|
||||
public void testIndicesRemoveNonExistingAliasResponds404() throws Exception {
|
||||
logger.info("--> creating index [test]");
|
||||
createIndex("test");
|
||||
ensureGreen();
|
||||
logger.info("--> deleting alias1 which does not exist");
|
||||
assertThat(admin().indices().prepareAliases().removeAlias("test", "alias1").execute().actionGet().isAcknowledged(), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -729,7 +774,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(existsResponse.exists(), equalTo(false));
|
||||
}
|
||||
|
||||
@Test(expected = ActionRequestValidationException.class)
|
||||
@Test(expected = IndexMissingException.class)
|
||||
public void testAddAliasNullIndex() {
|
||||
|
||||
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, "alias1"))
|
||||
|
@ -765,7 +810,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
|
|||
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
|
||||
} catch (ActionRequestValidationException e) {
|
||||
assertThat(e.validationErrors(), notNullValue());
|
||||
assertThat(e.validationErrors().size(), equalTo(2));
|
||||
assertThat(e.validationErrors().size(), equalTo(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -808,7 +853,7 @@ public class IndexAliasesTests extends ElasticsearchIntegrationTest {
|
|||
@Test
|
||||
public void testRemoveAliasNullAliasNullIndex() {
|
||||
try {
|
||||
admin().indices().prepareAliases().addAliasAction(AliasAction.newAddAliasAction(null, null))
|
||||
admin().indices().prepareAliases().addAliasAction(AliasAction.newRemoveAliasAction(null, null))
|
||||
.execute().actionGet();
|
||||
assertTrue("Should throw " + ActionRequestValidationException.class.getSimpleName(), false);
|
||||
} catch (ActionRequestValidationException e) {
|
||||
|
|
|
@ -123,7 +123,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
assertAcked(client().admin().indices().preparePutWarmer("custom_warmer")
|
||||
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())));
|
||||
|
||||
assertAcked(client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("custom_warmer"));
|
||||
assertAcked(client().admin().indices().prepareDeleteWarmer().setIndices("test").setNames("custom_warmer"));
|
||||
|
||||
for (Client client : clients()) {
|
||||
GetWarmersResponse getWarmersResponse = client.admin().indices().prepareGetWarmers().setLocal(true).get();
|
||||
|
|
|
@ -369,37 +369,37 @@ public class MetaDataTests extends ElasticsearchTestCase {
|
|||
@Test
|
||||
public void testIsExplicitAllIndices_null() throws Exception {
|
||||
MetaData metaData = MetaData.builder().build();
|
||||
assertThat(metaData.isExplicitAllIndices(null), equalTo(false));
|
||||
assertThat(metaData.isExplicitAllPattern(null), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsExplicitAllIndices_empty() throws Exception {
|
||||
MetaData metaData = MetaData.builder().build();
|
||||
assertThat(metaData.isExplicitAllIndices(new String[0]), equalTo(false));
|
||||
assertThat(metaData.isExplicitAllPattern(new String[0]), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsExplicitAllIndices_explicitAll() throws Exception {
|
||||
MetaData metaData = MetaData.builder().build();
|
||||
assertThat(metaData.isExplicitAllIndices(new String[]{"_all"}), equalTo(true));
|
||||
assertThat(metaData.isExplicitAllPattern(new String[]{"_all"}), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsExplicitAllIndices_explicitAllPlusOther() throws Exception {
|
||||
MetaData metaData = MetaData.builder().build();
|
||||
assertThat(metaData.isExplicitAllIndices(new String[]{"_all", "other"}), equalTo(false));
|
||||
assertThat(metaData.isExplicitAllPattern(new String[]{"_all", "other"}), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsExplicitAllIndices_normalIndexes() throws Exception {
|
||||
MetaData metaData = MetaData.builder().build();
|
||||
assertThat(metaData.isExplicitAllIndices(new String[]{"index1", "index2", "index3"}), equalTo(false));
|
||||
assertThat(metaData.isExplicitAllPattern(new String[]{"index1", "index2", "index3"}), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsExplicitAllIndices_wildcard() throws Exception {
|
||||
MetaData metaData = MetaData.builder().build();
|
||||
assertThat(metaData.isExplicitAllIndices(new String[]{"*"}), equalTo(false));
|
||||
assertThat(metaData.isExplicitAllPattern(new String[]{"*"}), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -55,6 +55,7 @@ import org.elasticsearch.cluster.block.ClusterBlockException;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
|
@ -537,6 +538,103 @@ public class IndicesOptionsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type1").get().isExists(), equalTo(false));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPutWarmer() throws Exception {
|
||||
assertAcked(prepareCreate("foobar"));
|
||||
ensureYellow();
|
||||
verify(client().admin().indices().preparePutWarmer("warmer1").setSearchRequest(client().prepareSearch().setIndices("foobar").setQuery(QueryBuilders.matchAllQuery())), false);
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foobar").setWarmers("warmer1").get().getWarmers().size(), equalTo(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutWarmer_wildcard() throws Exception {
|
||||
|
||||
assertAcked(prepareCreate("foo"));
|
||||
assertAcked(prepareCreate("foobar"));
|
||||
assertAcked(prepareCreate("bar"));
|
||||
assertAcked(prepareCreate("barbaz"));
|
||||
ensureYellow();
|
||||
|
||||
verify(client().admin().indices().preparePutWarmer("warmer1").setSearchRequest(client().prepareSearch().setIndices("foo*").setQuery(QueryBuilders.matchAllQuery())), false);
|
||||
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foo").setWarmers("warmer1").get().getWarmers().size(), equalTo(1));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foobar").setWarmers("warmer1").get().getWarmers().size(), equalTo(1));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("bar").setWarmers("warmer1").get().getWarmers().size(), equalTo(0));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("barbaz").setWarmers("warmer1").get().getWarmers().size(), equalTo(0));
|
||||
|
||||
verify(client().admin().indices().preparePutWarmer("warmer2").setSearchRequest(client().prepareSearch().setIndices().setQuery(QueryBuilders.matchAllQuery())), false);
|
||||
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foo").setWarmers("warmer2").get().getWarmers().size(), equalTo(1));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foobar").setWarmers("warmer2").get().getWarmers().size(), equalTo(1));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("bar").setWarmers("warmer2").get().getWarmers().size(), equalTo(1));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("barbaz").setWarmers("warmer2").get().getWarmers().size(), equalTo(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutAlias() throws Exception {
|
||||
assertAcked(prepareCreate("foobar"));
|
||||
ensureYellow();
|
||||
verify(client().admin().indices().prepareAliases().addAlias("foobar", "foobar_alias"), false);
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("foobar").get().exists(), equalTo(true));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutAlias_wildcard() throws Exception {
|
||||
|
||||
assertAcked(prepareCreate("foo"));
|
||||
assertAcked(prepareCreate("foobar"));
|
||||
assertAcked(prepareCreate("bar"));
|
||||
assertAcked(prepareCreate("barbaz"));
|
||||
ensureYellow();
|
||||
|
||||
verify(client().admin().indices().prepareAliases().addAlias("foo*", "foobar_alias"), false);
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("foo").get().exists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("foobar").get().exists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("bar").get().exists(), equalTo(false));
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("barbaz").get().exists(), equalTo(false));
|
||||
|
||||
verify(client().admin().indices().prepareAliases().addAlias("*", "foobar_alias"), false);
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("foo").get().exists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("foobar").get().exists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("bar").get().exists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareAliasesExist("foobar_alias").setIndices("barbaz").get().exists(), equalTo(true));
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testDeleteMapping_typeWildcard() throws Exception {
|
||||
verify(client().admin().indices().prepareDeleteMapping("_all").setType("type1"), true);
|
||||
|
||||
assertAcked(prepareCreate("foo").addMapping("type1", "field", "type=string"));
|
||||
assertAcked(prepareCreate("foobar").addMapping("type2", "field", "type=string"));
|
||||
assertAcked(prepareCreate("bar").addMapping("type3", "field", "type=string"));
|
||||
assertAcked(prepareCreate("barbaz").addMapping("type4", "field", "type=string"));
|
||||
|
||||
ensureYellow();
|
||||
|
||||
assertThat(client().admin().indices().prepareTypesExists("foo").setTypes("type1").get().isExists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareTypesExists("foobar").setTypes("type2").get().isExists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type3").get().isExists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type4").get().isExists(), equalTo(true));
|
||||
|
||||
verify(client().admin().indices().prepareDeleteMapping("foo*").setType("type*"), false);
|
||||
assertThat(client().admin().indices().prepareTypesExists("foo").setTypes("type1").get().isExists(), equalTo(false));
|
||||
assertThat(client().admin().indices().prepareTypesExists("foobar").setTypes("type2").get().isExists(), equalTo(false));
|
||||
assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type3").get().isExists(), equalTo(true));
|
||||
assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type4").get().isExists(), equalTo(true));
|
||||
|
||||
assertAcked(client().admin().indices().prepareDelete("foo*"));
|
||||
|
||||
verify(client().admin().indices().prepareDeleteMapping("foo*").setType("type1"), true);
|
||||
|
||||
verify(client().admin().indices().prepareDeleteMapping("_all").setType("type3","type4"), false);
|
||||
assertThat(client().admin().indices().prepareTypesExists("bar").setTypes("type3").get().isExists(), equalTo(false));
|
||||
assertThat(client().admin().indices().prepareTypesExists("barbaz").setTypes("type4").get().isExists(), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteWarmer() throws Exception {
|
||||
IndexWarmersMetaData.Entry entry = new IndexWarmersMetaData.Entry(
|
||||
|
@ -545,15 +643,15 @@ public class IndicesOptionsTests extends ElasticsearchIntegrationTest {
|
|||
assertAcked(prepareCreate("foobar").addCustom(new IndexWarmersMetaData(entry)));
|
||||
ensureYellow();
|
||||
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foo").setName("test1"), true);
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foo").setNames("test1"), true);
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foobar").setWarmers("test1").get().getWarmers().size(), equalTo(1));
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foobar").setName("test1"), false);
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foobar").setNames("test1"), false);
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foobar").setWarmers("test1").get().getWarmers().size(), equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteWarmer_wildcard() throws Exception {
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("_all").setName("test1"), true);
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("_all").setNames("test1"), true);
|
||||
|
||||
IndexWarmersMetaData.Entry entry = new IndexWarmersMetaData.Entry(
|
||||
"test1", new String[]{"type1"}, new BytesArray("{\"query\" : { \"match_all\" : {}}}")
|
||||
|
@ -564,7 +662,7 @@ public class IndicesOptionsTests extends ElasticsearchIntegrationTest {
|
|||
assertAcked(prepareCreate("barbaz").addCustom(new IndexWarmersMetaData(entry)));
|
||||
ensureYellow();
|
||||
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foo*").setName("test1"), false);
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foo*").setNames("test1"), false);
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foo").setWarmers("test1").get().getWarmers().size(), equalTo(0));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("foobar").setWarmers("test1").get().getWarmers().size(), equalTo(0));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("bar").setWarmers("test1").get().getWarmers().size(), equalTo(1));
|
||||
|
@ -572,9 +670,9 @@ public class IndicesOptionsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
assertAcked(client().admin().indices().prepareDelete("foo*"));
|
||||
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foo*").setName("test1"), true);
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("foo*").setNames("test1"), true);
|
||||
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("_all").setName("test1"), false);
|
||||
verify(client().admin().indices().prepareDeleteWarmer().setIndices("_all").setNames("test1"), false);
|
||||
assertThat(client().admin().indices().prepareGetWarmers("bar").setWarmers("test1").get().getWarmers().size(), equalTo(0));
|
||||
assertThat(client().admin().indices().prepareGetWarmers("barbaz").setWarmers("test1").get().getWarmers().size(), equalTo(0));
|
||||
}
|
||||
|
@ -622,12 +720,18 @@ public class IndicesOptionsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar").get("type2"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type2"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type2"), notNullValue());
|
||||
verify(client().admin().indices().preparePutMapping().setType("type3").setSource("field", "type=string"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type3"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar").get("type3"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type3"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type3"), notNullValue());
|
||||
|
||||
|
||||
verify(client().admin().indices().preparePutMapping("c*").setType("type1").setSource("field", "type=string"), true);
|
||||
|
||||
assertAcked(client().admin().indices().prepareClose("barbaz").get());
|
||||
verify(client().admin().indices().preparePutMapping("barbaz").setType("type3").setSource("field", "type=string"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type3"), notNullValue());
|
||||
verify(client().admin().indices().preparePutMapping("barbaz").setType("type4").setSource("field", "type=string"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type4"), notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -19,14 +19,17 @@
|
|||
|
||||
package org.elasticsearch.indices.mapping;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
|
@ -43,7 +46,7 @@ public class SimpleDeleteMappingTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
ensureGreen();
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
refresh();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
|
||||
|
@ -51,15 +54,13 @@ public class SimpleDeleteMappingTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
|
||||
for (int i = 0; i < 10 && !clusterState.metaData().index("test").mappings().containsKey("type1"); i++, Thread.sleep(100)) ;
|
||||
|
||||
assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(true));
|
||||
|
||||
GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings("test").setTypes("type1").execute().actionGet();
|
||||
assertThat(mappingsResponse.getMappings().get("test").get("type1"), notNullValue());
|
||||
|
||||
client().admin().indices().prepareDeleteMapping().setType("type1").execute().actionGet();
|
||||
Thread.sleep(500); // for now, we don't have ack logic, so just wait
|
||||
ElasticsearchAssertions.assertAcked(client().admin().indices().prepareDeleteMapping().setIndices("test").setType("type1"));
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
|
||||
|
@ -71,4 +72,35 @@ public class SimpleDeleteMappingTests extends ElasticsearchIntegrationTest {
|
|||
mappingsResponse = client().admin().indices().prepareGetMappings("test").setTypes("type1").execute().actionGet();
|
||||
assertThat(mappingsResponse.getMappings().get("test"), nullValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteMappingAllowNoBlankIndexAndNoEmptyStrings() throws Exception {
|
||||
assertAcked(client().admin().indices().prepareCreate("index1").addMapping("1", "field1", "type=string").get());
|
||||
assertAcked(client().admin().indices().prepareCreate("1index").addMapping("1", "field1", "type=string").get());
|
||||
|
||||
// Should succeed, since no wildcards
|
||||
client().admin().indices().prepareDeleteMapping("1index").setType("1").get();
|
||||
try {
|
||||
client().admin().indices().prepareDeleteMapping("_all").get();
|
||||
fail();
|
||||
} catch (ActionRequestValidationException e) {}
|
||||
|
||||
try {
|
||||
client().admin().indices().prepareDeleteMapping("_all").setType("").get();
|
||||
fail();
|
||||
} catch (ActionRequestValidationException e) {}
|
||||
|
||||
try {
|
||||
client().admin().indices().prepareDeleteMapping().setType("1").get();
|
||||
fail();
|
||||
} catch (ActionRequestValidationException e) {}
|
||||
|
||||
try {
|
||||
client().admin().indices().prepareDeleteMapping("").setType("1").get();
|
||||
fail();
|
||||
} catch (ActionRequestValidationException e) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class LocalGatewayIndicesWarmerTests extends ElasticsearchIntegrationTest
|
|||
|
||||
|
||||
logger.info("--> delete warmer warmer_1");
|
||||
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("warmer_1").execute().actionGet();
|
||||
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer().setIndices("test").setNames("warmer_1").execute().actionGet();
|
||||
assertThat(deleteWarmerResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
logger.info("--> verify warmers (delete) are registered in cluster state");
|
||||
|
|
|
@ -175,10 +175,10 @@ public class SimpleIndicesWarmerTests extends ElasticsearchIntegrationTest {
|
|||
createIndex("test");
|
||||
|
||||
try {
|
||||
client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("foo").execute().actionGet(1000);
|
||||
client().admin().indices().prepareDeleteWarmer().setIndices("test").setNames("foo").execute().actionGet(1000);
|
||||
assert false : "warmer foo should not exist";
|
||||
} catch (IndexWarmerMissingException ex) {
|
||||
assertThat(ex.name(), equalTo("foo"));
|
||||
assertThat(ex.names()[0], equalTo("foo"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ public class SimpleIndicesWarmerTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(entry.value.size(), equalTo(1));
|
||||
assertThat(entry.value.iterator().next().name(), equalTo("custom_warmer"));
|
||||
|
||||
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("custom_warmer").get();
|
||||
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer().setIndices("test").setNames("custom_warmer").get();
|
||||
assertThat(deleteWarmerResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
getWarmersResponse = client().admin().indices().prepareGetWarmers("test").get();
|
||||
|
|
|
@ -93,8 +93,8 @@ public class MoreLikeThisActionTests extends ElasticsearchIntegrationTest {
|
|||
.startObject("text").field("type", "string").endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
logger.info("Creating aliases alias release");
|
||||
client().admin().indices().aliases(indexAliasesRequest().addAlias("test", "release", termFilter("text", "release"))).actionGet();
|
||||
client().admin().indices().aliases(indexAliasesRequest().addAlias("test", "beta", termFilter("text", "beta"))).actionGet();
|
||||
client().admin().indices().aliases(indexAliasesRequest().addAlias("release", termFilter("text", "release"), "test")).actionGet();
|
||||
client().admin().indices().aliases(indexAliasesRequest().addAlias("beta", termFilter("text", "beta"), "test")).actionGet();
|
||||
|
||||
logger.info("Running Cluster Health");
|
||||
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
|
||||
|
|
|
@ -149,7 +149,8 @@ public class DestructiveOperationsIntegrationTests extends ElasticsearchIntegrat
|
|||
.put(DestructiveOperations.REQUIRES_NAME, true)
|
||||
.build();
|
||||
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings));
|
||||
|
||||
|
||||
|
||||
assertAcked(client().admin().indices().prepareCreate("index1").addMapping("1", "field1", "type=string").get());
|
||||
assertAcked(client().admin().indices().prepareCreate("1index").addMapping("1", "field1", "type=string").get());
|
||||
|
||||
|
@ -158,20 +159,19 @@ public class DestructiveOperationsIntegrationTests extends ElasticsearchIntegrat
|
|||
try {
|
||||
client().admin().indices().prepareDeleteMapping("_all").setType("1").get();
|
||||
fail();
|
||||
} catch (ElasticsearchIllegalArgumentException e) {}
|
||||
|
||||
} catch (ElasticsearchIllegalArgumentException e) {
|
||||
}
|
||||
try {
|
||||
client().admin().indices().prepareDeleteMapping().setType("1").get();
|
||||
client().admin().indices().prepareDeleteMapping().setIndices("*").setType("1").get();
|
||||
fail();
|
||||
} catch (ElasticsearchIllegalArgumentException e) {}
|
||||
} catch (ElasticsearchIllegalArgumentException e) {
|
||||
}
|
||||
|
||||
settings = ImmutableSettings.builder()
|
||||
.put(DestructiveOperations.REQUIRES_NAME, false)
|
||||
.build();
|
||||
settings = ImmutableSettings.builder().put(DestructiveOperations.REQUIRES_NAME, false).build();
|
||||
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings));
|
||||
|
||||
assertAcked(client().admin().indices().preparePutMapping("1index").setType("1").setSource("field1", "type=string"));
|
||||
assertAcked(client().admin().indices().prepareDeleteMapping().setType("1"));
|
||||
assertAcked(client().admin().indices().prepareDeleteMapping().setIndices("*").setType("1"));
|
||||
assertAcked(client().admin().indices().preparePutMapping("1index").setType("1").setSource("field1", "type=string"));
|
||||
assertAcked(client().admin().indices().prepareDeleteMapping("_all").setType("1"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue