{"record":{"id":"8c3ff9071a40b428","repo":"jaegertracing/jaeger","slug":"error-creating-elasticsearch-client-w","errorCode":null,"errorMessage":"error creating Elasticsearch client: %w","messagePattern":"error creating Elasticsearch client: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/es-index-cleaner/main.go","lineNumber":72,"sourceCode":"\t\tShort: \"Jaeger es-index-cleaner removes Jaeger indices\",\n\t\tLong:  \"Jaeger es-index-cleaner removes Jaeger indices\",\n\t\tRunE: func(_ *cobra.Command, args []string) error {\n\t\t\tif len(args) != 2 {\n\t\t\t\treturn errors.New(\"wrong number of arguments\")\n\t\t\t}\n\t\t\tnumOfDays, err := strconv.Atoi(args[0])\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"could not parse NUM_OF_DAYS argument: %w\", err)\n\t\t\t}\n\n\t\t\tif err := cfg.InitFromViper(v); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to initialize config: %w\", err)\n\t\t\t}\n\n\t\t\tctx := context.Background()\n\t\t\tesClient, err := app.NewESClient(ctx, args[1], cfg, logger)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating Elasticsearch client: %w\", err)\n\t\t\t}\n\t\t\ti := esclient.IndicesClient{\n\t\t\t\tClient:                 esClient,\n\t\t\t\tMasterTimeoutSeconds:   cfg.MasterNodeTimeoutSeconds,\n\t\t\t\tIgnoreUnavailableIndex: true,\n\t\t\t}\n\n\t\t\tindices, err := i.GetJaegerIndices(ctx, cfg.IndexPrefix)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tdeleteIndicesBefore := app.CalculateDeletionCutoff(time.Now().UTC(), numOfDays, relativeIndexCleaner.IsEnabled())\n\t\t\tlogger.Info(\"Indices before this date will be deleted\", zap.String(\"date\", deleteIndicesBefore.Format(time.RFC3339)))\n\n\t\t\tfilter := &app.IndexFilter{\n\t\t\t\tIndexPrefix:          cfg.IndexPrefix,\n\t\t\t\tIndexDateSeparator:   cfg.IndexDateSeparator,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/cmd/es-index-cleaner/main.go#L54-L90","documentation":"This error is returned by the es-index-cleaner command when app.NewESClient fails to construct the Elasticsearch client after the config has loaded successfully. It wraps the underlying cause (%w), so the real reason (unreachable host, bad credentials, unsupported scheme) is appended to this message. It is a fatal startup error: the cleaner cannot do any work without a client.","triggerScenarios":"Running es-index-cleaner with an Elasticsearch address argument that is unreachable, malformed, or requires auth/TLS that is not configured; NewESClient fails during ping/version discovery (e.g. trying to detect ES version via the root endpoint).","commonSituations":"Elasticsearch not yet up when a Kubernetes init-container/cronjob runs the cleaner; wrong ES URL or port; missing TLS/credential flags for a secured cluster; ES behind a proxy that blocks the version probe.","solutions":["Read the wrapped cause at the end of the message and fix that underlying issue (connection refused, 401, x509, etc.).","Verify the Elasticsearch address argument is reachable: curl the URL from the same host/pod.","Add the correct TLS/credential flags (ca, token, username/password) for a secured cluster.","Ensure Elasticsearch is ready before the cleaner runs (init-container readiness check or retry logic)."],"exampleFix":"// before\nesClient, err := app.NewESClient(ctx, \"http://es:9200\", cfg, logger)\n// after — pass flags-derived config with auth/TLS set and verify URL first\nif err := verifyESURL(esURL); err != nil { ... }\nesClient, err := app.NewESClient(ctx, esURL, cfg, logger)","handlingStrategy":"validation","validationCode":"esURL := args[1]\nu, err := url.Parse(esURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid ES URL %q\", esURL)\n}\nresp, err := http.Get(esURL)\nif err != nil { return fmt.Errorf(\"ES unreachable: %w\", err) }\nresp.Body.Close()","typeGuard":null,"tryCatchPattern":"if err := run(); err != nil {\n    var esErr *app.ESClientError\n    if errors.As(err, &esErr) { /* inspect wrapped cause */ }\n    log.Fatal(err)\n}","preventionTips":["Curl the ES URL from the same pod/host before deploying the cleaner.","Use readiness-gated init containers so ES is up first.","Always pass TLS/auth flags when the cluster has security enabled.","Check the wrapped cause, not just the wrapper message."],"tags":["elasticsearch","startup","client-init"],"backgroundTag":"elasticsearch-client-init-failed","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}