Tencent/WeKnora · error
create elasticsearch v7 client: %w
Error message
create elasticsearch v7 client: %w
What it means
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.
Source
Thrown at internal/container/engine_factory.go:224
repo := elasticsearchRepoV8.NewElasticsearchEngineRepository(client, cfg, &store.IndexConfig)
return retriever.NewKVHybridRetrieveEngine(repo, types.ElasticsearchRetrieverEngineType), nil
}
func createElasticsearchV7Engine(store types.VectorStore, cfg *config.Config) (interfaces.RetrieveEngineService, error) {
cc := store.ConnectionConfig
if err := utils.ValidateURLForSSRF(cc.Addr); err != nil {
return nil, fmt.Errorf("elasticsearch address failed SSRF validation: %w", err)
}
client, err := esv7.NewClient(esv7.Config{
Addresses: []string{cc.Addr},
Username: cc.Username,
Password: cc.Password,
Transport: &utils.SSRFValidatingRoundTripper{
Base: utils.NewSSRFSafeTransport(utils.DefaultSSRFSafeHTTPClientConfig()),
},
})
if err != nil {
return nil, fmt.Errorf("create elasticsearch v7 client: %w", err)
}
repo := elasticsearchRepoV7.NewElasticsearchEngineRepository(client, cfg, &store.IndexConfig)
return retriever.NewKVHybridRetrieveEngine(repo, types.ElasticsearchRetrieverEngineType), nil
}
func createQdrantEngine(store types.VectorStore) (interfaces.RetrieveEngineService, error) {
cc := store.ConnectionConfig
port := cc.Port
if port == 0 {
port = 6334
}
client, err := qdrant.NewClient(&qdrant.Config{
Host: cc.Host,
Port: port,
APIKey: cc.APIKey,
UseTLS: cc.UseTLS,
GrpcOptions: []grpc.DialOption{grpc.WithContextDialer(utils.SSRFSafeGRPCDialer)},View on GitHub (pinned to 988cbb0330)
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
Example fix
// before cc.Addr = "es-cluster:9200" // after cc.Addr = "http://es-cluster:9200"
Defensive patterns
Strategy: validation
Validate before calling
if _, err := url.Parse(cc.Addr); err != nil || cc.Addr == "" {
return fmt.Errorf("invalid elasticsearch address %q: %w", cc.Addr, err)
} Type guard
func validAddr(cc types.ConnectionConfig) bool { _, err := url.Parse(cc.Addr); return err == nil && cc.Addr != "" } Try / catch
engine, err := createElasticsearchEngine(store)
if err != nil {
if strings.Contains(err.Error(), "create elasticsearch v7 client") {
return fmt.Errorf("bad ES v7 config (check addr scheme/credentials): %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to do bulk: %w
- failed to delete by query: %w
- create milvus client: %w
- rerank call failed: %w
- invalid search result format
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/6a7f7a765aa1d8f3.
Report an issue: GitHub.