Skip to content

Conversation

javanna
Copy link
Member

@javanna javanna commented Sep 26, 2025

We recently added relevant attributes to the existing shard search latency metrics (#134798). This commit introduces an additional attribute that analyzes the parsed time range filter against the @timestamp field and reports back whether it is within the last 15 minutes, last hour, last 12 hours, last day, last three days, last seven days, or last 14 days.

We recently added relevant attributes to the existing shard search latency metrics (elastic#134798).
This commit introduces an additional attribute that analyzes the parsed time range filter against the @timestamp field and
reports back whether it is within the last 15 minutes, last hour, last 12 hours, last day, last three days, last seven days,
or last 14 days.
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Sep 26, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @javanna, I've created a changelog YAML for you.

if (hasDocValues()) {
Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
query = new IndexOrDocValuesQuery(query, dvQuery);
DateMathParser parser = resolveDateMathParser(forcedDateParser, lowerTerm, upperTerm);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just addressing some duplication on parsing the time ranges that I spotted while i was working on it, no functional change

if (includeLower == false) {
++l;
}
if (fieldName.equals(DataStream.TIMESTAMP_FIELD_NAME)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the core of the change: as we parse the lower bound of a time range, if it is against the @timestamp field, we save the parsed value in the context for later retrieval. This is good so we don't reparse dates multiple times which would be expensive.

Copy link
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Luca!

SearchRequestAttributesExtractor.introspectTimeRange(randomLongBetween(threeDaysAgo, oneDayAgo), nowInMillis)
);

long sevenDaysAgo = nowInMillis - (7 * 24 * 60 * 60 * 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could use TimeValue.ofDays(7).toMilliseconds() throughout this test for readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey, i tried to stay away from that because otherwise it is a 1:1 copy of the code it's testing. Maybe not so important, but I'd prefer keeping the test super simple.

@javanna javanna merged commit b3124f7 into elastic:main Sep 26, 2025
34 checks passed
@javanna javanna deleted the enhancement/time_range_metrics branch September 26, 2025 12:36
javanna added a commit to javanna/elasticsearch that referenced this pull request Sep 26, 2025
This is similar to elastic#135524, but adding the attribute to the took time latency metric.
That requires a bit of ceremony as the took time metric is recorded on the
coordinating node, while the time range filter is parsed on each shard. We
don't have mappings available on the coord node, which are needed to parse
dates on the coord node. Thus we need to rely on date parsing done on the
data nodes, which requires sending back the parsed value to the coord node,
performing some simple reduction on it, and adding it back to the search
response.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants