2019-08-29 10:38:48 -04:00
|
|
|
[[indices-add-alias]]
|
|
|
|
=== Add index alias API
|
|
|
|
++++
|
|
|
|
<titleabbrev>Add index alias</titleabbrev>
|
|
|
|
++++
|
|
|
|
|
|
|
|
Creates or updates an index alias.
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/glossary.asciidoc[tag=index-alias-desc]
|
2019-08-29 10:38:48 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-08-29 10:38:48 -04:00
|
|
|
----
|
2020-07-31 09:51:47 -04:00
|
|
|
PUT /my-index-000001/_alias/alias1
|
2019-08-29 10:38:48 -04:00
|
|
|
----
|
2020-07-31 09:51:47 -04:00
|
|
|
// TEST[setup:my_index]
|
2019-08-29 10:38:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[add-alias-api-request]]
|
|
|
|
==== {api-request-title}
|
|
|
|
|
|
|
|
`PUT /<index>/_alias/<alias>`
|
|
|
|
|
|
|
|
`POST /<index>/_alias/<alias>`
|
|
|
|
|
|
|
|
`PUT /<index>/_aliases/<alias>`
|
|
|
|
|
|
|
|
`POST /<index>/_aliases/<alias>`
|
|
|
|
|
|
|
|
|
|
|
|
[[add-alias-api-path-params]]
|
|
|
|
==== {api-path-parms-title}
|
|
|
|
|
|
|
|
`<index>`::
|
|
|
|
(Required, string)
|
|
|
|
Comma-separated list or wildcard expression of index names
|
|
|
|
to add to the alias.
|
|
|
|
+
|
|
|
|
To add all indices in the cluster to the alias,
|
|
|
|
use a value of `_all`.
|
2020-07-09 16:51:58 -04:00
|
|
|
+
|
|
|
|
NOTE: You cannot add <<data-streams,data streams>> to an index alias.
|
2019-08-29 10:38:48 -04:00
|
|
|
|
|
|
|
`<alias>`::
|
|
|
|
(Required, string)
|
|
|
|
Name of the index alias to create or update.
|
|
|
|
|
|
|
|
|
|
|
|
[[add-alias-api-query-params]]
|
|
|
|
==== {api-query-parms-title}
|
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
|
2019-08-29 10:38:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
[[add-alias-api-request-body]]
|
|
|
|
==== {api-request-body-title}
|
|
|
|
|
|
|
|
`filter`::
|
|
|
|
(Required, query object)
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-alias-filter]
|
2019-08-29 10:38:48 -04:00
|
|
|
|
2020-06-01 19:42:53 -04:00
|
|
|
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-routing]
|
2019-08-29 10:38:48 -04:00
|
|
|
|
|
|
|
[[add-alias-api-example]]
|
|
|
|
==== {api-examples-title}
|
|
|
|
|
|
|
|
[[alias-adding]]
|
|
|
|
===== Add a time-based alias
|
|
|
|
|
|
|
|
The following request creates an alias, `2030`,
|
|
|
|
for the `logs_20302801` index.
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-08-29 10:38:48 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
PUT /logs_20302801/_alias/2030
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[s/^/PUT logs_20302801\n/]
|
|
|
|
|
|
|
|
[[add-alias-api-user-ex]]
|
|
|
|
===== Add a user-based alias
|
|
|
|
|
|
|
|
First, create an index, `users`,
|
|
|
|
with a mapping for the `user_id` field:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-08-29 10:38:48 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
PUT /users
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"mappings" : {
|
|
|
|
"properties" : {
|
|
|
|
"user_id" : {"type" : "integer"}
|
2019-08-29 10:38:48 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2019-08-29 10:38:48 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Then add the index alias for a specific user, `user_12`:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-08-29 10:38:48 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
PUT /users/_alias/user_12
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"routing" : "12",
|
|
|
|
"filter" : {
|
|
|
|
"term" : {
|
|
|
|
"user_id" : 12
|
2019-08-29 10:38:48 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2019-08-29 10:38:48 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
[[alias-index-creation]]
|
|
|
|
===== Add an alias during index creation
|
|
|
|
|
|
|
|
You can use the <<create-index-aliases,create index API>>
|
|
|
|
to add an index alias during index creation.
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2019-08-29 10:38:48 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
PUT /logs_20302801
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"year": { "type": "integer" }
|
2019-08-29 10:38:48 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
},
|
|
|
|
"aliases": {
|
|
|
|
"current_day": {},
|
|
|
|
"2030": {
|
|
|
|
"filter": {
|
|
|
|
"term": { "year": 2030 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-29 10:38:48 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|