Skip to content
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

Merged
merged 1 commit into from Jul 29, 2015

Conversation

martijnvg
Copy link
Member

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.

The following index names can be specified: (assuming now is 2024.03.22 noon utc)

  • <logstash-{now/d}> translates into logstash-2024.03.22
  • <logstash-{now/M}> translates into logstash-2024.03.01
  • <logstash-{now/M{YYYY.MM}}> translates into logstash-2024.03
  • <logstash-{now/M-1M{YYYY.MM}}> translates into logstash-2024.02
  • <logstash-{now/d{YYYY.MM.dd|+12:00}}> translates into logstash-2024.03.23

The following example shows a search request that searches the Logstash indices for the past
three days:

curl -XGET 'localhost:9200/<logstash-{now/d-2d}>,<logstash-{now/d-1d}>,<logstash-{now/d}>/_search' {
  "query" : {
    ...
  }
}

PR for #12059


Where:

* `static_name` is the static text part of the name

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....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much nicer now :)

@martijnvg
Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why one node only?

Copy link
Member Author

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

@javanna
Copy link
Member

javanna commented Jul 27, 2015

left a few comments

@martijnvg
Copy link
Member Author

@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());
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened: #12512

@javanna
Copy link
Member

javanna commented Jul 28, 2015

did another round, left a couple minor comments

@martijnvg
Copy link
Member Author

@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;
Copy link
Member

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?

@javanna
Copy link
Member

javanna commented Jul 29, 2015

LGTM

@martijnvg martijnvg removed the review label Jul 29, 2015
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants