{"record":{"id":"6a7f7a765aa1d8f3","repo":"Tencent/WeKnora","slug":"create-elasticsearch-v7-client-w","errorCode":null,"errorMessage":"create elasticsearch v7 client: %w","messagePattern":"create elasticsearch v7 client: %w","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/container/engine_factory.go","lineNumber":224,"sourceCode":"\trepo := elasticsearchRepoV8.NewElasticsearchEngineRepository(client, cfg, &store.IndexConfig)\n\treturn retriever.NewKVHybridRetrieveEngine(repo, types.ElasticsearchRetrieverEngineType), nil\n}\n\nfunc createElasticsearchV7Engine(store types.VectorStore, cfg *config.Config) (interfaces.RetrieveEngineService, error) {\n\tcc := store.ConnectionConfig\n\tif err := utils.ValidateURLForSSRF(cc.Addr); err != nil {\n\t\treturn nil, fmt.Errorf(\"elasticsearch address failed SSRF validation: %w\", err)\n\t}\n\tclient, err := esv7.NewClient(esv7.Config{\n\t\tAddresses: []string{cc.Addr},\n\t\tUsername:  cc.Username,\n\t\tPassword:  cc.Password,\n\t\tTransport: &utils.SSRFValidatingRoundTripper{\n\t\t\tBase: utils.NewSSRFSafeTransport(utils.DefaultSSRFSafeHTTPClientConfig()),\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create elasticsearch v7 client: %w\", err)\n\t}\n\trepo := elasticsearchRepoV7.NewElasticsearchEngineRepository(client, cfg, &store.IndexConfig)\n\treturn retriever.NewKVHybridRetrieveEngine(repo, types.ElasticsearchRetrieverEngineType), nil\n}\n\nfunc createQdrantEngine(store types.VectorStore) (interfaces.RetrieveEngineService, error) {\n\tcc := store.ConnectionConfig\n\tport := cc.Port\n\tif port == 0 {\n\t\tport = 6334\n\t}\n\n\tclient, err := qdrant.NewClient(&qdrant.Config{\n\t\tHost:        cc.Host,\n\t\tPort:        port,\n\t\tAPIKey:      cc.APIKey,\n\t\tUseTLS:      cc.UseTLS,\n\t\tGrpcOptions: []grpc.DialOption{grpc.WithContextDialer(utils.SSRFSafeGRPCDialer)},","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/container/engine_factory.go#L206-L242","documentation":"This wraps a failure from esv7.NewClient when constructing the Elasticsearch v7 Go client. Client construction validates the address list and options; it fails before any request is sent, typically because the address URL cannot be parsed or an option is invalid. It occurs only after the SSRF check has already passed.","triggerScenarios":"Calling createElasticsearchEngine with an Elasticsearch v7 store whose cc.Addr is malformed (unparseable URL, missing scheme after validation allows it) or whose client options (username/password/transport) are rejected by the olivere/official v7 client constructor.","commonSituations":"Addresses like 'es:9200' with no scheme slipping through; upgrading the ES Go client version and constructor option incompatibilities; invalid characters in credentials; config populated from env vars with stray whitespace or quotes.","solutions":["Check cc.Addr parses as a valid URL: run url.Parse on it before deployment","Add an explicit http:// or https:// scheme to the address","Trim whitespace/quotes from username, password, and address values loaded from env/config","Pin and review the esv7 client version; update options to match its API"],"exampleFix":"// before\ncc.Addr = \"es-cluster:9200\"\n// after\ncc.Addr = \"http://es-cluster:9200\"","handlingStrategy":"validation","validationCode":"if _, err := url.Parse(cc.Addr); err != nil || cc.Addr == \"\" {\n    return fmt.Errorf(\"invalid elasticsearch address %q: %w\", cc.Addr, err)\n}","typeGuard":"func validAddr(cc types.ConnectionConfig) bool { _, err := url.Parse(cc.Addr); return err == nil && cc.Addr != \"\" }","tryCatchPattern":"engine, err := createElasticsearchEngine(store)\nif err != nil {\n    if strings.Contains(err.Error(), \"create elasticsearch v7 client\") {\n        return fmt.Errorf(\"bad ES v7 config (check addr scheme/credentials): %w\", err)\n    }\n    return err\n}","preventionTips":["Include scheme in every Elasticsearch address (http:// or https://)","Trim env-var values before assigning them to Addr/Username/Password","Smoke-test client creation in a startup health check so misconfig fails fast","Pin the esv7 SDK version and read its changelog before upgrading"],"tags":["elasticsearch","client-init","url-parse","network"],"backgroundTag":"client-construction-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}