{"record":{"id":"81526146d15ea6ce","repo":"jaegertracing/jaeger","slug":"failed-to-create-template-w","errorCode":null,"errorMessage":"failed to create template: %w","messagePattern":"failed to create template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/elasticsearch/esclient/index_client.go","lineNumber":311,"sourceCode":"// callers express pure Jaeger intent and never hold a BackendVersion.\nfunc (i IndicesClient) CreateTemplate(ctx context.Context, name string, mappingType MappingType) error {\n\ttemplate, err := RenderIndexTemplate(mappingType, i.Indices, i.UseILM, i.ILMPolicyName, i.version)\n\tif err != nil {\n\t\treturn err\n\t}\n\t_, err = i.request(ctx, elasticRequest{\n\t\tendpoint: i.templateEndpoint(name),\n\t\tmethod:   http.MethodPut,\n\t\tbody:     []byte(template),\n\t})\n\tif err != nil {\n\t\tvar responseError ResponseError\n\t\tif errors.As(err, &responseError) {\n\t\t\tif responseError.StatusCode != http.StatusOK {\n\t\t\t\treturn responseError.prefixMessage(\"failed to create template: \" + name)\n\t\t\t}\n\t\t}\n\t\treturn fmt.Errorf(\"failed to create template: %w\", err)\n\t}\n\treturn nil\n}\n\n// Rollover create a rollover for certain index/alias\nfunc (i IndicesClient) Rollover(ctx context.Context, rolloverTarget string, conditions map[string]any) error {\n\tesReq := elasticRequest{\n\t\tendpoint: rolloverTarget + \"/_rollover/\",\n\t\tmethod:   http.MethodPost,\n\t}\n\tif len(conditions) > 0 {\n\t\tbody := map[string]any{\n\t\t\t\"conditions\": conditions,\n\t\t}\n\t\tbodyBytes, err := json.Marshal(body)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/elasticsearch/esclient/index_client.go#L293-L329","documentation":"Returned by IndicesClient.CreateTemplate when the PUT to _index_template/<name> (v8) or _template/<name> (legacy) fails with a non-ResponseError cause. The template body is rendered internally (RenderIndexTemplate) before the request; if rendering fails, a different error is returned. Structured ES rejections become a prefixMessage variant naming the template.","triggerScenarios":"PUT of the rendered index template fails at the transport layer: connection refused/reset, timeout, canceled context, or an error body that cannot be wrapped as ResponseError.","commonSituations":"ES restarting while Jaeger initializes its index templates; network misconfiguration on first deployment; extremely short client timeouts on slow clusters; version-dependent test paths (see TestCreateTemplateRenderError) failing before the request.","solutions":["Verify ES reachability and fix address/TLS/credentials","Retry CreateTemplate — re-PUT of the same template is idempotent","Confirm the jaeger version matches the backend (ES7 vs ES8/OpenSearch) since the endpoint differs","Unwrap the error to distinguish transport failure from an ES-side rejection"],"exampleFix":"// before\nif err := client.CreateTemplate(ctx, \"jaeger-span\", esclient.SpanMapping); err != nil {\n    return err\n}\n// after\nif err := client.CreateTemplate(ctx, \"jaeger-span\", esclient.SpanMapping); err != nil {\n    var respErr esclient.ResponseError\n    if !errors.As(err, &respErr) {\n        return retryAfterHealthCheck(err) // transport failure: idempotent retry\n    }\n    return err\n}","handlingStrategy":"retry","validationCode":"// pre-flight: cluster health and version compatibility\nresp, err := http.Get(esURL + \"/_cluster/state/version?filter_path=version.number\")\nif err != nil || resp.StatusCode != 200 {\n    return fmt.Errorf(\"ES unavailable before template install\")\n}","typeGuard":"var respErr esclient.ResponseError\nisTransportFailure := !errors.As(err, &respErr)","tryCatchPattern":"if err := client.CreateTemplate(ctx, name, mappingType); err != nil {\n    var respErr esclient.ResponseError\n    if errors.As(err, &respErr) {\n        return fmt.Errorf(\"ES rejected template %s (status %d): %w\", name, respErr.StatusCode, err)\n    }\n    return retryWithBackoff(err) // template PUT is idempotent\n}","preventionTips":["Ensure backend version detection is correct — v8 uses _index_template, older uses _template","Wait for the ES container/cluster to be healthy before initializing templates","Retry transport failures; re-PUT of the same template is safe"],"tags":["elasticsearch","index-template","network"],"backgroundTag":"elasticsearch-request-failed","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}