Bird
Raised Fist0

You want to create a Kibana dashboard showing average transaction duration per service over the last day. Which Elasticsearch query aggregation setup supports this?

hard📝 Workflow Q9 of Q15
Elasticsearch - ELK Stack Integration
You want to create a Kibana dashboard showing average transaction duration per service over the last day. Which Elasticsearch query aggregation setup supports this?
A{ "size": 10, "query": { "match_all": {} }, "aggs": { "avg_duration": { "avg": { "field": "transaction.duration.us" } } } }
B{ "size": 0, "query": { "range": { "@timestamp": { "gte": "now-1d" } } }, "aggs": { "services": { "terms": { "field": "service.name.keyword" }, "aggs": { "avg_duration": { "avg": { "field": "transaction.duration.us" } } } } } }
C{ "size": 0, "query": { "range": { "transaction.duration.us": { "gte": "now-1d" } } }, "aggs": { "services": { "terms": { "field": "service.name" } } } }
D{ "size": 0, "query": { "range": { "@timestamp": { "gte": "now-1d" } } }, "aggs": { "avg_duration": { "avg": { "field": "service.name.keyword" } } } }
Step-by-Step Solution
Solution:
  1. Step 1: Filter data for the last day

    The range query on '@timestamp' with 'now-1d' filters last 24 hours.
  2. Step 2: Aggregate by service name keyword

    Terms aggregation on 'service.name.keyword' groups data by service.
  3. Step 3: Calculate average transaction duration per service

    Nested avg aggregation on 'transaction.duration.us' computes average duration per service bucket.
  4. Final Answer:

    Aggregation by service keyword with avg duration and time range filter -> Option B
  5. Quick Check:

    Terms + avg + time range = dashboard data [OK]
Quick Trick: Use terms agg on .keyword fields for grouping [OK]
Common Mistakes:
MISTAKES
  • Using non-keyword fields for terms aggregation
  • Filtering duration instead of timestamp for time range
  • Setting size > 0 when aggregation only needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes