{"record":{"id":"ae17a8dfe00656cd","repo":"jaegertracing/jaeger","slug":"s-aggregation-not-found","errorCode":null,"errorMessage":"%s aggregation not found","messagePattern":"(.+?) aggregation not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/metricstore/elasticsearch/to_domain.go","lineNumber":70,"sourceCode":"\tlabels := buildServiceLabels(m.ServiceNames)\n\n\tif !m.GroupByOperation {\n\t\tbuckets, err := extractBuckets(result)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn []*metrics.Metric{\n\t\t\t{\n\t\t\t\tLabels:       labels,\n\t\t\t\tMetricPoints: toDomainMetricPoints(t.bucketsToPointsFunc(buckets)),\n\t\t\t},\n\t\t}, nil\n\t}\n\n\t// Handle grouped results when groupByOp is true\n\tagg, found := result.Aggregations.Terms(aggName)\n\tif !found {\n\t\treturn nil, fmt.Errorf(\"%s aggregation not found\", aggName)\n\t}\n\n\tvar metricsData []*metrics.Metric\n\tfor _, bucket := range agg.Buckets {\n\t\tmetric, err := t.processOperationBucket(bucket, labels)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to process bucket: %w\", err)\n\t\t}\n\t\tmetricsData = append(metricsData, metric)\n\t}\n\n\treturn metricsData, nil\n}\n\nfunc buildServiceLabels(serviceNames []string) []*metrics.Label {\n\tlabels := make([]*metrics.Label, len(serviceNames))\n\tfor i, name := range serviceNames {\n\t\tlabels[i] = &metrics.Label{Name: \"service_name\", Value: name}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/metricstore/elasticsearch/to_domain.go#L52-L88","documentation":"When GroupByOperation is enabled, toDomainMetrics expects a terms aggregation keyed by aggName in the SearchResponse. If result.Aggregations.Terms(aggName) reports not-found — the aggregation is absent because the response has no such terms aggregation — the translator cannot build per-operation metrics and returns this error naming the expected aggregation.","triggerScenarios":"ToDomainMetricsFamily with GroupByOperation=true on a response whose aggregations lack the operation terms aggregation (empty result set, wrong index, or query built without the terms agg).","commonSituations":"Querying a time range with no spans so ES returns an empty/absent aggregation; ES version differences that omit empty aggregations; mismatch between the query builder's aggregation name and the translator's expected aggName constant.","solutions":["Verify the query time range actually contains span data for the requested service.","Ensure the queryBuilder builds the terms aggregation (operation grouping) whenever GroupByOperation is true.","Check that aggName constant matches the name the query builder registers."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if _, found := result.Aggregations.Terms(aggName); !found {\n  return metrics.EmptyFamily(params) // no data in range\n}","typeGuard":"func hasTermsAgg(resp *esclient.SearchResponse, name string) bool {\n  _, found := resp.Aggregations.Terms(name)\n  return found\n}","tryCatchPattern":"fam, err := translator.ToDomainMetricsFamily(params, result)\nif err != nil && strings.HasSuffix(err.Error(), \"aggregation not found\") {\n  return &metrics.MetricFamily{}, nil // empty result, not an error\n}","preventionTips":["Only enable GroupByOperation when the query builder adds the terms aggregation.","Confirm data exists in the queried window before treating absence as an error.","Keep aggName constant shared between query builder and translator."],"tags":["elasticsearch","metrics","aggregation"],"backgroundTag":"aggregation-not-found","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}