Reputation: 153
Using Nest client 7.2.1 to connect to Elastic db internal loadbalancer in Azure.
Error:
Exception: Failed to create DB Index for Alarm Event.Invalid NEST response built from a unsuccessful (401) low level call on HEAD: /
# Audit trail of this API call: - [1]
BadResponse: Node: http://192.168.0.4:9200/
Exception: PipelineException Took: 00:00:00.0506796
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration..
Call: Status code 401 from: HEAD /
---> Elasticsearch.Net.PipelineException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration.
at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response)
at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
--- End of inner exception stack trace ---
# Audit exception in step 1 BadResponse: Elasticsearch.Net.PipelineException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration.
at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response)
at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
# Request: <Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response: <Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.> Unsuccessful (401) low level call on PUT: /asx-sleepquality
# Audit trail of this API call: - [1]
BadResponse: Node: http://192.168.0.4:9200/
Exception: PipelineException
Took: 00:00:00.4294201
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration..
Call: Status code 401 from: PUT /asx-sleepquality.
ServerError: Type: security_exception
Reason: "missing authentication credentials for REST request [/asx-sleepquality]"
---> Elasticsearch.Net.PipelineException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration.
at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response)
at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
--- End of inner exception stack trace ---
# Audit exception in step 1 BadResponse: Elasticsearch.Net.PipelineException: Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration.
at Elasticsearch.Net.RequestPipeline.ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response) at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
# Request: <Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response: <Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
using the following code:
const string Url = "http://192.168.0.4:9200";
var settings = new ConnectionSettings(new Uri(Url));
ElasticSearchClient = new ElasticClient(settings);
var indexes = GetAsxIndexes();
var response = ElasticSearchClient.Ping().DebugInformation;
Upvotes: -1
Views: 7892
Reputation: 249
The following code fixed my issue:
// Reading the configuration from appsettings.json
var elasticConfig = hostContext.Configuration.GetSection("ElasticSearch");
// 1. Register NEST ElasticClient
var settings = new ConnectionSettings(new Uri(elasticConfig["Uri"]))
.BasicAuthentication(elasticConfig["UserName"], elasticConfig["Password"])
.DefaultIndex(elasticConfig["DefaultIndex"]);
settings.PrettyJson();
var client = new ElasticClient(settings);
Upvotes: 3
Reputation: 121
I had Error 401 when I enabled Fine-grained access control. Signing the request using AwsSigV4HttpConnection worked for me. Reference: https://opensearch.org/blog/aws-sigv4-support-for-clients/
using OpenSearch.Client;
using OpenSearch.Net.Auth.AwsSigV4;
namespace Application
{
class Program
{
static void Main(string[] args)
{
var endpoint = new Uri("https://search-xxx.region.es.amazonaws.com");
var connection = new AwsSigV4HttpConnection();
var config = new ConnectionSettings(endpoint, connection);
var client = new OpenSearchClient(config);
Console.WriteLine($"{client.RootNodeInfo().Version.Distribution}: {client.RootNodeInfo().Version.Number}");
}
}
}
Upvotes: 0
Reputation: 125528
You're trying to make a request to an Elasticsearch cluster that has security enabled, based on the error message
Could not authenticate with the specified node. Try verifying your credentials or check your Shield configuration.. Call: Status code 401 from: HEAD /
You need to supply the authentication credentials in the ConnectionSettings
for the client to use
var pool = new SingleNodeConnectionPool(new Uri("http://192.168.0.4:9200"));
var settings = new ConnectionSettings(pool)
// configure the client with authentication credentials
.BasicAuthentication("user", "password");
var client = new ElasticClient(settings);
Upvotes: 2