{"record":{"id":"4a904e9a4fd2f70d","repo":"googleapis/mcp-toolbox","slug":"elasticsearch-connection-failed-status-d","errorCode":null,"errorMessage":"elasticsearch connection failed: status %d","messagePattern":"elasticsearch connection failed: status (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/elasticsearch/elasticsearch.go","lineNumber":132,"sourceCode":"\t}\n\n\tclient, err := elasticsearch.NewBaseClient(cfg)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Test connection\n\tres, err := esapi.InfoRequest{\n\t\tInstrument: client.InstrumentationEnabled(),\n\t}.Do(ctx, client)\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer res.Body.Close()\n\n\tif res.IsError() {\n\t\treturn nil, fmt.Errorf(\"elasticsearch connection failed: status %d\", res.StatusCode)\n\t}\n\n\ts := &Source{\n\t\tConfig: c,\n\t\tClient: client,\n\t}\n\treturn s, nil\n}\n\n// SourceType returns the resourceType string for this source.\nfunc (s *Source) IsReadOnly() bool {\n\treturn false\n}\n\nfunc (s *Source) SourceType() string {\n\treturn SourceType\n}\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/elasticsearch/elasticsearch.go#L114-L150","documentation":"Thrown in Config.Initialize after the client sends an ES _info request to test connectivity: the server responded with an HTTP error status (res.IsError()), so the source is marked failed with the numeric status code. It means the cluster was reachable at the network level but rejected the request.","triggerScenarios":"Elasticsearch returns 401 when credentials are wrong or the API key is invalid; 403 when the user lacks permissions; 404/400 when the address points at a wrong path, a proxy, or a non-Elasticsearch service; 503 when the cluster is starting up or unavailable.","commonSituations":"Wrong password after a rotation; expired or revoked API key; pointing at Kibana (5601) instead of Elasticsearch (9200); cluster still booting in Kubernetes before readiness; security plugin returning 401 for anonymous requests.","solutions":["Read the status code: 401/403 means fix credentials or API key permissions","Verify the address is the Elasticsearch HTTP port (9200), not Kibana or a proxy","Confirm the cluster is healthy: `curl -u user:pass http://host:9200/_cluster/health`","If 503, wait for the cluster to become ready and retry"],"exampleFix":"// before (tools.yaml)\n    addresses: [http://localhost:5600]\n// after\n    addresses: [http://localhost:9200]","handlingStrategy":"retry","validationCode":"// preflight: cluster must answer _cluster/health with 200\ncurl -u \"$ES_USER:$ES_PASS\" http://localhost:9200/_cluster/health","typeGuard":null,"tryCatchPattern":"// Go\nsrc, err := cfg.Initialize(ctx, tracer)\nif err != nil && strings.Contains(err.Error(), \"connection failed: status\") {\n    // inspect status code, fix credentials/address, then retry with backoff\n    return retryWithBackoff(ctx, func() error { _, err := cfg.Initialize(ctx, tracer); return err })\n}","preventionTips":["Verify the address points at Elasticsearch's port (9200), not Kibana","Rotate API keys before they expire and update secrets","Wait for cluster readiness before initializing sources (init containers/readiness probes)","Test credentials with curl against /_cluster/health before deploy"],"tags":["network","elasticsearch","http-status","authentication"],"backgroundTag":"http-error-response","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}