Skip to content

Commit 2816ab6

Browse files
committed
[DOCS] Reformat update index aliases API docs (#46093)
1 parent 629232d commit 2816ab6

File tree

1 file changed

+156
-17
lines changed

1 file changed

+156
-17
lines changed

docs/reference/indices/aliases.asciidoc

Lines changed: 156 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
[[indices-aliases]]
2-
=== Index Aliases
2+
=== Update index alias API
3+
++++
4+
<titleabbrev>Update index alias</titleabbrev>
5+
++++
6+
7+
Adds or removes index aliases.
8+
9+
include::alias-exists.asciidoc[tag=index-alias-def]
10+
11+
[source,js]
12+
----
13+
POST /_aliases
14+
{
15+
"actions" : [
16+
{ "add" : { "index" : "twitter", "alias" : "alias1" } }
17+
]
18+
}
19+
----
20+
// CONSOLE
21+
// TEST[setup:twitter]
22+
23+
24+
[[indices-aliases-api-request]]
25+
==== {api-request-title}
26+
27+
`POST /_aliases`
28+
29+
30+
[[indices-aliases-api-desc]]
31+
==== {api-description-title}
332

433
APIs in Elasticsearch accept an index name when working against a
534
specific index, and several indices when applicable. The index aliases
@@ -10,7 +39,119 @@ automatically expand to the aliased indices. An alias can also be
1039
associated with a filter that will automatically be applied when
1140
searching, and routing values. An alias cannot have the same name as an index.
1241

13-
Here is a sample of associating the alias `alias1` with index `test1`:
42+
43+
[[indices-aliases-api-query-params]]
44+
==== {api-query-parms-title}
45+
46+
include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
47+
48+
49+
[[indices-aliases-api-request-body]]
50+
==== {api-request-body-title}
51+
52+
`actions`::
53+
+
54+
--
55+
(Required, array of actions)
56+
Set of actions to perform.
57+
Valid actions include:
58+
59+
`add`::
60+
Adds an alias to an index.
61+
62+
`remove`::
63+
Removes an alias from an index.
64+
65+
`remove_index`::
66+
Deletes an index or index alias,
67+
like the <<indices-delete-index,delete index API>>.
68+
69+
You can perform these actions on alias objects.
70+
Valid parameters for alias objects include:
71+
72+
`index`::
73+
(String)
74+
Wildcard expression of index names
75+
used to perform the action.
76+
+
77+
If the `indices` parameter is not specified,
78+
this parameter is required.
79+
80+
`indices`::
81+
(Array)
82+
Array of index names
83+
used to perform the action.
84+
+
85+
If the `index` parameter is not specified,
86+
this parameter is required.
87+
88+
`alias`::
89+
(String)
90+
Comma-separated list or wildcard expression of index alias names to
91+
add, remove, or delete.
92+
+
93+
If the `aliases` parameter is not specified,
94+
this parameter is required for the `add` or `remove` action.
95+
96+
`aliases`::
97+
(String)
98+
Comma-separated list or wildcard expression of index alias names to
99+
add, remove, or delete.
100+
+
101+
If the `alias` parameter is not specified,
102+
this parameter is required for the `add` or `remove` action.
103+
104+
`filter`::
105+
(Optional, query object)
106+
include::{docdir}/rest-api/common-parms.asciidoc[tag=index-alias-filter]
107+
+
108+
See <<filtered>> for an example.
109+
110+
`is_write_index`::
111+
(Optional, boolean)
112+
If `true`, assigns the index as an alias's write index.
113+
Defaults to `false`.
114+
+
115+
An alias can have one write index at a time.
116+
+
117+
See <<aliases-write-index>> for an example.
118+
+
119+
[IMPORTANT]
120+
====
121+
Aliases that do not explicitly set `is_write_index: true` for an index, and
122+
only reference one index, will have that referenced index behave as if it is the write index
123+
until an additional index is referenced. At that point, there will be no write index and
124+
writes will be rejected.
125+
====
126+
127+
include::{docdir}/rest-api/common-parms.asciidoc[tag=index-routing]
128+
+
129+
See <<aliases-routing>> for an example.
130+
131+
`index_routing`::
132+
(Optional, string)
133+
Custom <<mapping-routing-field, routing value>> used
134+
for the alias's indexing operations.
135+
+
136+
See <<aliases-routing>> for an example.
137+
138+
`search_routing`::
139+
`index_routing`::
140+
(Optional, string)
141+
Custom <<mapping-routing-field, routing value>> used
142+
for the alias's search operations.
143+
+
144+
See <<aliases-routing>> for an example.
145+
--
146+
147+
148+
[[indices-aliases-api-example]]
149+
==== {api-examples-title}
150+
151+
[[indices-aliases-api-add-alias-ex]]
152+
===== Add an alias
153+
154+
The following request adds the `alias1` alias to the `test1` index.
14155

15156
[source,js]
16157
--------------------------------------------------
@@ -24,7 +165,10 @@ POST /_aliases
24165
// CONSOLE
25166
// TEST[s/^/PUT test1\nPUT test2\n/]
26167

27-
And here is removing that same alias:
168+
[[indices-aliases-api-remove-alias-ex]]
169+
===== Remove an alias
170+
171+
The following request removes the `alias1` alias.
28172

29173
[source,js]
30174
--------------------------------------------------
@@ -38,6 +182,9 @@ POST /_aliases
38182
// CONSOLE
39183
// TEST[continued]
40184

185+
[[indices-aliases-api-rename-alias-ex]]
186+
===== Rename an alias
187+
41188
Renaming an alias is a simple `remove` then `add` operation within the
42189
same API. This operation is atomic, no need to worry about a short
43190
period of time where the alias does not point to an index:
@@ -48,13 +195,16 @@ POST /_aliases
48195
{
49196
"actions" : [
50197
{ "remove" : { "index" : "test1", "alias" : "alias1" } },
51-
{ "add" : { "index" : "test2", "alias" : "alias1" } }
198+
{ "add" : { "index" : "test1", "alias" : "alias2" } }
52199
]
53200
}
54201
--------------------------------------------------
55202
// CONSOLE
56203
// TEST[continued]
57204

205+
[[indices-aliases-api-add-multi-alias-ex]]
206+
===== Add an alias to multiple indices
207+
58208
Associating an alias with more than one index is simply several `add`
59209
actions:
60210

@@ -128,9 +278,8 @@ POST /_aliases
128278
<2> The index we should have added
129279
<3> `remove_index` is just like <<indices-delete-index>>
130280

131-
[float]
132281
[[filtered]]
133-
==== Filtered Aliases
282+
===== Filtered aliases
134283

135284
Aliases with filters provide an easy way to create different "views" of
136285
the same index. The filter can be defined using Query DSL and is applied
@@ -175,7 +324,6 @@ POST /_aliases
175324
// CONSOLE
176325
// TEST[continued]
177326

178-
[float]
179327
[[aliases-routing]]
180328
===== Routing
181329

@@ -242,9 +390,8 @@ GET /alias2/_search?q=user:kimchy&routing=2,3
242390
// CONSOLE
243391
// TEST[continued]
244392

245-
[float]
246393
[[aliases-write-index]]
247-
===== Write Index
394+
===== Write index
248395

249396
It is possible to associate the index pointed to by an alias as the write index.
250397
When specified, all index and update requests against an alias that point to multiple
@@ -331,11 +478,3 @@ POST /_aliases
331478
--------------------------------------------------
332479
// CONSOLE
333480
// TEST[s/^/PUT test\nPUT test2\n/]
334-
335-
[IMPORTANT]
336-
=====================================
337-
Aliases that do not explicitly set `is_write_index: true` for an index, and
338-
only reference one index, will have that referenced index behave as if it is the write index
339-
until an additional index is referenced. At that point, there will be no write index and
340-
writes will be rejected.
341-
=====================================

0 commit comments

Comments
 (0)