Skip to content

Commit a767350

Browse files
Tommmsterjrodewig
andauthored
[DOCS] Document date math support for aliases (#70535)
Co-authored-by: James Rodewig <[email protected]>
1 parent 737d850 commit a767350

File tree

5 files changed

+84
-33
lines changed

5 files changed

+84
-33
lines changed

docs/reference/api-conventions.asciidoc

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,17 @@ IMPORTANT: Direct access to system indices is deprecated and
7979
will no longer be allowed in the next major version.
8080

8181
[[date-math-index-names]]
82-
=== Date math support in index names
82+
=== Date math support in index and index alias names
8383

84-
Date math index name resolution enables you to search a range of time series indices, rather
85-
than searching all of your time series indices and filtering the results or maintaining aliases.
86-
Limiting the number of indices that are searched reduces the load on the cluster and improves
87-
execution performance. For example, if you are searching for errors in your
88-
daily logs, you can use a date math name template to restrict the search to the past
89-
two days.
84+
Date math name resolution lets you to search a range of time series indices or
85+
index aliases rather than searching all of your indices and filtering the
86+
results. Limiting the number of searched indices reduces cluster load and
87+
improves search performance. For example, if you are searching for errors in
88+
your daily logs, you can use a date math name template to restrict the search to
89+
the past two days.
9090

91-
Almost all APIs that have an `index` parameter support date math in the `index` parameter
92-
value.
93-
94-
A date math index name takes the following form:
91+
Most APIs that accept an index or index alias argument support date math. A date
92+
math name takes the following form:
9593

9694
[source,txt]
9795
----------------------------------------------------------------------
@@ -101,10 +99,10 @@ A date math index name takes the following form:
10199
Where:
102100

103101
[horizontal]
104-
`static_name`:: is the static text part of the name
105-
`date_math_expr`:: is a dynamic date math expression that computes the date dynamically
106-
`date_format`:: is the optional format in which the computed date should be rendered. Defaults to `yyyy.MM.dd`. Format should be compatible with java-time https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
107-
`time_zone`:: is the optional time zone. Defaults to `utc`.
102+
`static_name`:: Static text
103+
`date_math_expr`:: Dynamic date math expression that computes the date dynamically
104+
`date_format`:: Optional format in which the computed date should be rendered. Defaults to `yyyy.MM.dd`. Format should be compatible with java-time https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
105+
`time_zone`:: Optional time zone. Defaults to `UTC`.
108106

109107
NOTE: Pay attention to the usage of small vs capital letters used in the `date_format`. For example:
110108
`mm` denotes minute of hour, while `MM` denotes month of year. Similarly `hh` denotes the hour in the
@@ -113,8 +111,8 @@ NOTE: Pay attention to the usage of small vs capital letters used in the `date_f
113111
Date math expressions are resolved locale-independent. Consequently, it is not possible to use any other
114112
calendars than the Gregorian calendar.
115113

116-
You must enclose date math index name expressions within angle brackets, and
117-
all special characters should be URI encoded. For example:
114+
You must enclose date math names in angle brackets. If you use the name in a
115+
request path, special characters must be URI encoded. For example:
118116

119117
[source,console]
120118
----
@@ -139,8 +137,8 @@ The special characters used for date rounding must be URI encoded as follows:
139137
`,`:: `%2C`
140138
======================================================
141139

142-
The following example shows different forms of date math index names and the final index names
143-
they resolve to given the current time is 22nd March 2024 noon utc.
140+
The following example shows different forms of date math names and the final names
141+
they resolve to given the current time is 22nd March 2024 noon UTC.
144142

145143
[options="header"]
146144
|======
@@ -152,7 +150,7 @@ they resolve to given the current time is 22nd March 2024 noon utc.
152150
| `<logstash-{now/d{yyyy.MM.dd\|+12:00}}>` | `logstash-2024.03.23`
153151
|======
154152

155-
To use the characters `{` and `}` in the static part of an index name template, escape them
153+
To use the characters `{` and `}` in the static part of a name template, escape them
156154
with a backslash `\`, for example:
157155

158156
* `<elastic\\{ON\\}-{now/M}>` resolves to `elastic{ON}-2024.03.01`

docs/reference/indices/add-alias.asciidoc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ NOTE: You cannot add <<data-streams,data streams>> to an index alias.
4747

4848
`<alias>`::
4949
(Required, string)
50-
Name of the index alias to create or update.
50+
Name of the index alias to create or update. Supports
51+
<<date-math-index-names,date math>>.
5152

5253

5354
[[add-alias-api-query-params]]
@@ -68,6 +69,18 @@ include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-routing]
6869
[[add-alias-api-example]]
6970
==== {api-examples-title}
7071

72+
[[alias-date-math-support]]
73+
===== Date math support
74+
75+
Index alias names support <<date-math-index-names,date math>>.
76+
77+
[source,console]
78+
----
79+
# POST /logs/_alias/<logs_{now/M}>
80+
POST /logs/_alias/%3Clogs_%7Bnow%2FM%7D%3E
81+
----
82+
// TEST[s/^/PUT logs\n/]
83+
7184
[[alias-adding]]
7285
===== Add a time-based alias
7386

@@ -139,3 +152,16 @@ PUT /logs_20302801
139152
}
140153
}
141154
--------------------------------------------------
155+
156+
The create index API also supports <<date-math-index-names,date math>> in index
157+
alias names.
158+
159+
[source,console]
160+
----
161+
PUT /logs
162+
{
163+
"aliases": {
164+
"<logs_{now/M}>": {}
165+
}
166+
}
167+
----

docs/reference/indices/aliases.asciidoc

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ NOTE: You cannot add <<data-streams,data streams>> to an index alias.
103103

104104
`alias`::
105105
(String)
106-
Comma-separated list or wildcard expression of index alias names to
107-
add, remove, or delete.
106+
Comma-separated list or wildcard expression of index alias names to add, remove,
107+
or delete. Supports <<date-math-index-names,date math>>.
108108
+
109109
If the `aliases` parameter is not specified,
110110
this parameter is required for the `add` or `remove` action.
111111

112112
`aliases`::
113113
(Array of strings)
114-
Array of index alias names to
115-
add, remove, or delete.
114+
Array of index alias names to add, remove, or delete. Supports
115+
<<date-math-index-names,date math>>.
116116
+
117-
If the `alias` parameter is not specified,
118-
this parameter is required for the `add` or `remove` action.
117+
If the `alias` parameter is not specified, this parameter is required for the
118+
`add` or `remove` action.
119119

120120
`filter`::
121121
(Optional, query object)
@@ -190,6 +190,20 @@ POST /_aliases
190190
--------------------------------------------------
191191
// TEST[s/^/PUT test1\nPUT test2\n/]
192192

193+
Index alias names support <<date-math-index-names,date math>>.
194+
195+
[source,console]
196+
----
197+
POST /_aliases
198+
{
199+
"actions" : [
200+
{ "add" : { "index" : "logs", "alias" : "<logs_{now/M}>" } }
201+
]
202+
}
203+
----
204+
// TEST[s/^/PUT logs\n/]
205+
// TEST[continued]
206+
193207
[[indices-aliases-api-remove-alias-ex]]
194208
===== Remove an alias
195209

docs/reference/indices/create-index.asciidoc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
6868

6969
`aliases`::
7070
(Optional, <<indices-aliases,alias object>>) Index aliases which include the
71-
index. See <<indices-aliases>>.
71+
index. Index alias names support <<date-math-index-names,date math>>.
7272

7373
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=mappings]
7474

@@ -161,6 +161,18 @@ PUT /test
161161
}
162162
--------------------------------------------------
163163

164+
Index alias names also support <<date-math-index-names,date math>>.
165+
166+
[source,console]
167+
----
168+
PUT /logs
169+
{
170+
"aliases": {
171+
"<logs_{now/M}>": {}
172+
}
173+
}
174+
----
175+
164176
[[create-index-wait-for-active-shards]]
165177
===== Wait for active shards
166178

@@ -173,7 +185,7 @@ what happened:
173185
{
174186
"acknowledged": true,
175187
"shards_acknowledged": true,
176-
"index": "test"
188+
"index": "logs"
177189
}
178190
--------------------------------------------------
179191

docs/reference/rest-api/common-parms.asciidoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ end::index-alias[]
2525

2626
tag::aliases[]
2727
`aliases`::
28-
(Optional, <<indices-aliases,alias object>>) Index aliases which include the
29-
index. See <<indices-aliases>>.
28+
(Optional, <<indices-aliases,alias object>>) <<indices-aliases,Index aliases>>
29+
which include the index. Index alias names support <<date-math-index-names,date
30+
math>>.
3031
end::aliases[]
3132

3233
tag::target-index-aliases[]
3334
`aliases`::
3435
(Optional, <<indices-aliases,alias object>>)
35-
Index aliases which include the target index.
36-
See <<indices-aliases>>.
36+
<<indices-aliases,Index aliases>> which include the target index. Index alias
37+
names support <<date-math-index-names,date math>>.
3738
end::target-index-aliases[]
3839

3940
tag::allow-no-indices[]

0 commit comments

Comments
 (0)