New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add date math support in index names #12209
Conversation
01b7e84
to
754a106
Compare
|
||
Where: | ||
|
||
* `static_name` is the static text part of the name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format this as:
[horizontal]
`static_name`:: The static text part of the name
`date_math_expr`:: A dynamic....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much nicer now :)
Updated the pr to fix @clintongormley's docs feedback. |
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
@ElasticsearchIntegrationTest.ClusterScope(numDataNodes = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why one node only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this just to make the the test run a bit faster during development. This can be removed
left a few comments |
232a28c
to
1892452
Compare
@javanna I rebased the PR to master and applied your comments. |
// TODO: I think startTime() should become part of ActionRequest and that should be used both for index name | ||
// data math expressions and $now in scripts. This way all apis will deal with now in the same way instead | ||
// of just for the _search api | ||
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request.indicesOptions(), startTime(), request.indices()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this //TODO will have to stay right? maybe we want to open an issue instead to keep track of this? also s/data/date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened: #12512
did another round, left a couple minor comments |
@javanna I updated the PR. |
* @return whether the specified alias or index exists. If the alias or index contains datemath then that is resolved too. | ||
*/ | ||
public boolean hasIndexOrAliasAndResolveDateMath(String aliasOrIndex, ClusterState state) { | ||
assert expressionResolvers.get(0) instanceof DateMathExpressionResolver; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that we add the expression resolvers manually to the list, maybe keep a reference to it instead so we can use it directly instead of getting it from the list?
LGTM |
Date math index name resolution enables you to search a range of time-series indices, rather than searching all of your time-series indices and filtering the the results or maintaining aliases. Limiting the number of indices that are searched reduces the load on the cluster and improves execution performance. For example, if you are searching for errors in your daily logs, you can use a date math name template to restrict the search to the past two days. The added `ExpressionResolver` implementation that is responsible for resolving date math expressions in index names. This resolver is evaluated before wildcard expressions are evaluated. The supported format: `<static_name{date_math_expr{date_format|timezone_id}}>` and the date math expressions must be enclosed within angle brackets. The `date_format` is optional and defaults to `YYYY.MM.dd`. The `timezone_id` id is optional too and defaults to `utc`. The `{` character can be escaped by places `\\` before it. Closes elastic#12059
091e686
to
ac3d090
Compare
Date math index name resolution enables you to search a range of time-series indices, rather than searching all of your time-series indices and filtering the the results or maintaining aliases. Limiting the number of indices that are searched reduces the load on the cluster and improves execution performance. For example, if you are searching for errors in your daily logs, you can use a date math name template to restrict the search to the past two days.
The added
ExpressionResolver
implementation that is responsible for resolving date math expressions in index names. This resolver is evaluated before wildcard expressions are evaluated.The supported format:
<static_name{date_math_expr{date_format|timezone_id}}>
and the date math expressions must be enclosed within angle brackets. Thedate_format
is optional and defaults toYYYY.MM.dd
. Thetimezone_id
id is optional too and defaults toutc
.The
{
character can be escaped by places\\
before it.The following index names can be specified: (assuming now is 2024.03.22 noon utc)
<logstash-{now/d}>
translates intologstash-2024.03.22
<logstash-{now/M}>
translates intologstash-2024.03.01
<logstash-{now/M{YYYY.MM}}>
translates intologstash-2024.03
<logstash-{now/M-1M{YYYY.MM}}>
translates intologstash-2024.02
<logstash-{now/d{YYYY.MM.dd|+12:00}}>
translates intologstash-2024.03.23
The following example shows a search request that searches the Logstash indices for the past
three days:
PR for #12059