{"record":{"id":"83ac226da97948fd","repo":"jaegertracing/jaeger","slug":"failed-to-check-if-index-exists-w","errorCode":null,"errorMessage":"failed to check if index exists: %w","messagePattern":"failed to check if index exists: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/elasticsearch/esclient/index_client.go","lineNumber":243,"sourceCode":"\t\treturn false, fmt.Errorf(\"failed to check if alias exists: %w\", err)\n\t}\n\treturn true, nil\n}\n\n// IndexExists check whether an index exists or not\nfunc (i *IndicesClient) IndexExists(ctx context.Context, index string) (bool, error) {\n\t_, err := i.request(ctx, elasticRequest{\n\t\tendpoint: index,\n\t\tmethod:   http.MethodHead,\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.StatusNotFound {\n\t\t\t\treturn false, nil\n\t\t\t}\n\t\t}\n\t\treturn false, fmt.Errorf(\"failed to check if index exists: %w\", err)\n\t}\n\treturn true, nil\n}\n\nfunc (*IndicesClient) aliasesString(aliases []Alias) string {\n\tvar builder strings.Builder\n\tfor _, alias := range aliases {\n\t\tfmt.Fprintf(&builder, \"[index: %s, alias: %s],\", alias.Index, alias.Name)\n\t}\n\tconcatAliases := builder.String()\n\treturn strings.Trim(concatAliases, \",\")\n}\n\nfunc (i *IndicesClient) aliasAction(ctx context.Context, action string, aliases []Alias) error {\n\tactions := []map[string]any{}\n\n\tfor _, alias := range aliases {\n\t\toptions := map[string]any{","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/storage/elasticsearch/esclient/index_client.go#L225-L261","documentation":"Returned by IndicesClient.IndexExists when the HEAD request against an index fails with anything other than a 404 ResponseError. 404 maps to (false, nil) — index absent. Any other failure becomes this wrapped error, meaning the existence probe itself could not be completed.","triggerScenarios":"HEAD /<index> fails without a 404 ResponseError: network outage, timeout, canceled context, or non-404 HTTP errors (401 unauthorized, 503 unavailable) not wrapped as ResponseError.","commonSituations":"Bad ES credentials during first-time setup; ES down while Jaeger decides whether to bootstrap indices; proxy returning HTML error pages that defeat ResponseError parsing.","solutions":["Verify connectivity and credentials (curl -I the index URL); 401/403 point at auth config","Treat as 'probe failed' — do not assume the index is missing; retry before creating it","Check cluster health and load-balancer behavior for 5xx responses","Unwrap the %w chain to identify the transport cause"],"exampleFix":"// before\nok, err := client.IndexExists(ctx, \"jaeger-span-000001\")\nif err != nil { return err }\n// after\nok, err := client.IndexExists(ctx, \"jaeger-span-000001\")\nif err != nil {\n    return fmt.Errorf(\"cannot determine index existence, not bootstrapping: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight auth + connectivity\nresp, err := http.Get(esURL + \"/_cluster/health\")\nif err != nil || resp.StatusCode != 200 {\n    return fmt.Errorf(\"ES not reachable\")\n}","typeGuard":"var respErr esclient.ResponseError\nisAuthProblem := func(err error) bool {\n    var re esclient.ResponseError\n    return errors.As(err, &re) && (re.StatusCode == 401 || re.StatusCode == 403)\n}","tryCatchPattern":"ok, err := client.IndexExists(ctx, index)\nif err != nil {\n    var respErr esclient.ResponseError\n    if errors.As(err, &respErr) {\n        return fmt.Errorf(\"index probe rejected, status=%d\", respErr.StatusCode)\n    }\n    return retryable(err) // never bootstrap indices on a failed probe\n}","preventionTips":["Only create an index when IndexExists returns (false, nil); an error must abort bootstrap","Check auth config if you see this at first deployment","Retry the probe rather than assuming the index is missing"],"tags":["elasticsearch","network","index-management"],"backgroundTag":"elasticsearch-request-failed","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}