The method i’m using:
<code>func getESClient() (*elasticsearch.Client, error) {
cfg := config.LoadEnv()
cloudId := cfg.ElasticCloudId
apiKey := cfg.ElasticSearchApiKey
log.Println("Using CloudID:", cloudId)
client, err := elasticsearch.NewClient(elasticsearch.Config{
CloudID: string(cloudId),
APIKey: apiKey,
})
if err != nil {
log.Fatal("Failed to connect to the Elasticsearch client:", err)
return nil, err
}
log.Println(client.Info())
log.Println("Client info")
return client, nil
}
</code>
<code>func getESClient() (*elasticsearch.Client, error) {
cfg := config.LoadEnv()
cloudId := cfg.ElasticCloudId
apiKey := cfg.ElasticSearchApiKey
log.Println("Using CloudID:", cloudId)
client, err := elasticsearch.NewClient(elasticsearch.Config{
CloudID: string(cloudId),
APIKey: apiKey,
})
if err != nil {
log.Fatal("Failed to connect to the Elasticsearch client:", err)
return nil, err
}
log.Println(client.Info())
log.Println("Client info")
return client, nil
}
</code>
func getESClient() (*elasticsearch.Client, error) {
cfg := config.LoadEnv()
cloudId := cfg.ElasticCloudId
apiKey := cfg.ElasticSearchApiKey
log.Println("Using CloudID:", cloudId)
client, err := elasticsearch.NewClient(elasticsearch.Config{
CloudID: string(cloudId),
APIKey: apiKey,
})
if err != nil {
log.Fatal("Failed to connect to the Elasticsearch client:", err)
return nil, err
}
log.Println(client.Info())
log.Println("Client info")
return client, nil
}
The error i’m getting:
<code>2024/06/14 20:04:16 [401 Unauthorized] {"error":{"root_cause":[{"type":"security_exception","reason":"unable to authenticate with provided credentials and anonymous access is not allowed for this request","additional_unsuccessful_credentials":"API key: Illegal base64 character 3a","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","Bearer realm="security"","ApiKey"]}}],"type":"security_exception","reason":"unable to authenticate with provided credentials and anonymous access is not allowed for this request","additional_unsuccessful_credentials":"API key: Illegal base64 character 3a","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","Bearer realm="security"","ApiKey"]}}
</code>
<code>2024/06/14 20:04:16 [401 Unauthorized] {"error":{"root_cause":[{"type":"security_exception","reason":"unable to authenticate with provided credentials and anonymous access is not allowed for this request","additional_unsuccessful_credentials":"API key: Illegal base64 character 3a","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","Bearer realm="security"","ApiKey"]}}],"type":"security_exception","reason":"unable to authenticate with provided credentials and anonymous access is not allowed for this request","additional_unsuccessful_credentials":"API key: Illegal base64 character 3a","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","Bearer realm="security"","ApiKey"]}}
</code>
2024/06/14 20:04:16 [401 Unauthorized] {"error":{"root_cause":[{"type":"security_exception","reason":"unable to authenticate with provided credentials and anonymous access is not allowed for this request","additional_unsuccessful_credentials":"API key: Illegal base64 character 3a","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","Bearer realm="security"","ApiKey"]}}],"type":"security_exception","reason":"unable to authenticate with provided credentials and anonymous access is not allowed for this request","additional_unsuccessful_credentials":"API key: Illegal base64 character 3a","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","Bearer realm="security"","ApiKey"]}}
ELASTICSEARCH_API_KEY=https://id.westus2.azure.elastic-cloud.com:443
ELASTICSEARCH_CLOUD_ID=elasticsearch:id==
Using "github.com/elastic/go-elasticsearch/v8"
I don’t have access direct to the elasticsearch node, it gets more complicated. Anyone have a hint over it?