Skip to content

Commit 0086f62

Browse files
jrodewigTommmster
andauthored
[DOCS] Document date math support for aliases (#70535) (#70567)
Co-authored-by: James Rodewig <[email protected]> Co-authored-by: Tommmster <[email protected]>
1 parent 4db8153 commit 0086f62

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
@@ -70,7 +70,7 @@ include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
7070

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

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

@@ -167,6 +167,18 @@ PUT /test
167167
}
168168
--------------------------------------------------
169169

170+
Index alias names also support <<date-math-index-names,date math>>.
171+
172+
[source,console]
173+
----
174+
PUT /logs
175+
{
176+
"aliases": {
177+
"<logs_{now/M}>": {}
178+
}
179+
}
180+
----
181+
170182
[[create-index-wait-for-active-shards]]
171183
===== Wait for active shards
172184

@@ -179,7 +191,7 @@ what happened:
179191
{
180192
"acknowledged": true,
181193
"shards_acknowledged": true,
182-
"index": "test"
194+
"index": "logs"
183195
}
184196
--------------------------------------------------
185197

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

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

2828
tag::aliases[]
2929
`aliases`::
30-
(Optional, <<indices-aliases,alias object>>) Index aliases which include the
31-
index. See <<indices-aliases>>.
30+
(Optional, <<indices-aliases,alias object>>) <<indices-aliases,Index aliases>>
31+
which include the index. Index alias names support <<date-math-index-names,date
32+
math>>.
3233
end::aliases[]
3334

3435
tag::target-index-aliases[]
3536
`aliases`::
3637
(Optional, <<indices-aliases,alias object>>)
37-
Index aliases which include the target index.
38-
See <<indices-aliases>>.
38+
<<indices-aliases,Index aliases>> which include the target index. Index alias
39+
names support <<date-math-index-names,date math>>.
3940
end::target-index-aliases[]
4041

4142
tag::allow-no-indices[]

0 commit comments

Comments
 (0)