My Elastic Search .Net Client is not working?

Code

using Elastic.Clients.Elasticsearch;
using Elastic.Transport;
using System;
using System.Threading.Tasks;

namespace ESTest
{
    internal class Program
    {
        static void Main(string[] args)
        {

            var respo = CreateIndex();

          //  Console.ReadKey();
        }


        public static async Task CreateIndex()
        {
            var settings = new ElasticsearchClientSettings(new Uri("http://192.168.1.53:9200/"))
             .Authentication(new BasicAuthentication("elastic", "vPM5UsWCwR-oI2ZsFe0k"));
            var client = new ElasticsearchClient(settings);
           var resopn=  await client.Indices.CreateAsync("7778");
        
        }


    }

   
}

Error

# FailureReason: Unrecoverable/Unexpected BadRequest while attempting PUT on http://192.168.1.53:9200/7778
 - [1] BadRequest: Node: http://192.168.1.53:9200/ Exception: NullReferenceException Took: 00:00:00.0882637
# Audit exception in step 1 BadRequest:
System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 Elastic.Transport.HttpWebRequestInvoker.SetAuthenticationIfNeeded(Endpoint endpoint, RequestData requestData, HttpWebRequest request) 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 424
   在 Elastic.Transport.HttpWebRequestInvoker.CreateHttpWebRequest(Endpoint endpoint, RequestData requestData, PostData postData, Boolean isAsync) 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 264
   在 Elastic.Transport.HttpWebRequestInvoker.<RequestCoreAsync>d__13`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 88
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Elastic.Transport.RequestPipeline.<CallProductEndpointCoreAsync>d__43`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/Pipeline/RequestPipeline.cs:行号 198
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   在 Elastic.Transport.DistributedTransport`1.<RequestCoreAsync>d__16`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DistributedTransport.cs:行号 161
# Inner Exception: 未将对象引用设置到对象的实例。
System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 Elastic.Transport.HttpWebRequestInvoker.SetAuthenticationIfNeeded(Endpoint endpoint, RequestData requestData, HttpWebRequest request) 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 424
   在 Elastic.Transport.HttpWebRequestInvoker.CreateHttpWebRequest(Endpoint endpoint, RequestData requestData, PostData postData, Boolean isAsync) 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 264
   在 Elastic.Transport.HttpWebRequestInvoker.<RequestCoreAsync>d__13`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 88
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Elastic.Transport.RequestPipeline.<CallProductEndpointCoreAsync>d__43`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/Pipeline/RequestPipeline.cs:行号 198
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   在 Elastic.Transport.DistributedTransport`1.<RequestCoreAsync>d__16`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DistributedTransport.cs:行号 161
# Exception:
Elastic.Transport.UnexpectedTransportException: 未将对象引用设置到对象的实例。 ---> System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 Elastic.Transport.HttpWebRequestInvoker.SetAuthenticationIfNeeded(Endpoint endpoint, RequestData requestData, HttpWebRequest request) 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 424
   在 Elastic.Transport.HttpWebRequestInvoker.CreateHttpWebRequest(Endpoint endpoint, RequestData requestData, PostData postData, Boolean isAsync) 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 264
   在 Elastic.Transport.HttpWebRequestInvoker.<RequestCoreAsync>d__13`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/TransportClient/HttpWebRequestInvoker.cs:行号 88
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Elastic.Transport.RequestPipeline.<CallProductEndpointCoreAsync>d__43`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/Components/Pipeline/RequestPipeline.cs:行号 198
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   在 Elastic.Transport.DistributedTransport`1.<RequestCoreAsync>d__16`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DistributedTransport.cs:行号 161
   --- 内部异常堆栈跟踪的结尾 ---
   在 Elastic.Transport.DistributedTransport`1.ThrowUnexpectedTransportException[TResponse](Exception killerException, List`1 seenExceptions, Endpoint endpoint, TResponse response, IReadOnlyCollection`1 auditTrail) 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DistributedTransport.cs:行号 283
   在 Elastic.Transport.DistributedTransport`1.<RequestCoreAsync>d__16`1.MoveNext() 位置 /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DistributedTransport.cs:行号 176
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   在 Elastic.Clients.Elasticsearch.ElasticsearchClient.<>c__DisplayClass865_0`3.<<DoRequestCoreAsync>g__SendRequestWithProductCheckCore|2>d.MoveNext() 位置 /_/src/Elastic.Clients.Elasticsearch/_Shared/Client/ElasticsearchClient.cs:行号 220
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Threading.Tasks.ValueTask`1.get_Result()
   在 System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   在 Elastic.Clients.Elasticsearch.ElasticsearchClient.<>c__DisplayClass865_0`3.<<DoRequestCoreAsync>g__SendRequestWithProductCheck|1>d.MoveNext() 位置 /_/src/Elastic.Clients.Elasticsearch/_Shared/Client/ElasticsearchClient.cs:行号 190
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   在 ESTest.Program.<CreateIndex>d__1.MoveNext() 位置 C:\Users\Admin\source\repos\ESTest\ESTest\Program.cs:行号 27

elasticsearch.yml

# ======================== Elasticsearch Configuration =========================


cluster.name: aicss

node.name: node-1


path.data: /var/lib/elasticsearch

path.logs: /var/log/elasticsearch

network.host: 0.0.0.0



xpack.security.enabled: true

xpack.security.enrollment.enabled: true


xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12


xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12

cluster.initial_master_nodes: ["ES01"]
http.host: 0.0.0.0

Hi @naiqiu.zhao, May I know what is the Elastic and Elasticsearch .NET client version you're using?

I'm unable to reproduce this with the latest version of the client.

From looking at your Elasticsearch config, it seems like you have security and SSL enabled, but in your .NET code you are using a http:// url. Could you please try to use https instead or alternatively run the local Elasticsearch instance without SSL?

Elastic Version 8.16;.net farmwork 4.7.2;nuget version 8.16.

I found the cause of this problem.

I use .net 8 is working fine.I use .net faremwork4.7.2 is not working.

var settings = new ElasticsearchClientSettings(new Uri(App.GetConfig("Elasticsearch:Uri")))
.Authentication(new BasicAuthentication(App.GetConfig("Elasticsearch:UserName"), App.GetConfig("Elasticsearch:Password")))
.ServerCertificateValidationCallback(CertificateValidations.AllowAll)
.CertificateFingerprint(App.GetConfig("Elasticsearch:Fingerprint"));