# Elasticsearch.Net 7.17.X unable to connect Elasticsearch 8.13.4 version

**URL:** <https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [August 1, 2024, 5:44am UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184 "2024-08-01T05:44:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathish12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathish12/32/143619_2.png) [@sathish12](https://discuss.elastic.co/u/sathish12)\
**Post date:** [August 1, 2024, 5:44am UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184/1 "2024-08-01T05:44:41Z")

</div>

I have upgraded from elasticsearch 2.3.2 to 8.13.4. I have created a multi node cluster and I am trying to connect to elasticsearch through my .NET. I have heard that elastic.client.elasticsearch library is not providing all the functionalities so the this blog [Connecting to Elasticsearch v8.x using the v7.17.x client | Elasticsearch .NET Clients [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.17/connecting-to-elasticsearch-v8.html) is asking to connect to 8.X using 7.17.X clients to access the data and indices. Below is my code:

```auto
var pool = new SingleNodeConnectionPool(new Uri(ConfigurationManager.AppSettings["ElasticSearchUrl"]));
     
        var setting = new Nest.ConnectionSettings(pool)
                          .CertificateFingerprint("adsfa.asdfasdfasfasdfasdfasdfasdfasdfasdfasdfasdfasfasdfasdfasf")
                          .RequestTimeout(TimeSpan.FromMinutes(2))
                          .BasicAuthentication(ConfigurationManager.AppSettings["elasticUser"], ConfigurationManager.AppSettings["elasticPwd"])
                          .EnableApiVersioningHeader();
        var client = new Nest.ElasticClient(setting);
        var lowlevelClient = client.LowLevel;
        string es_query = @"{
          ""query"": {
          ""_source"": [""Index""]
          ""query"": {
                        ""match_all"": {}
                    }
        }";

        Debug.WriteLine(es_query);
        try
        {

            
            var searchResponse = lowlevelClient.Search<BytesResponse>("demoindexfortest", PostData.String(es_query));
            var responseBytes = searchResponse.Body;
}

```

However, I am getting the below error while executing the search function:  
{Unsuccessful () low level call on POST: /demoindexfortest/\_search}

Could someone help so that I can get out of this issue?

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [August 1, 2024, 7:16am UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184/2 "2024-08-01T07:16:40Z")

</div>

Hi @sathish12,

> [@sathish12](#):
>
> I have heard that elastic.client.elasticsearch library is not providing all the functionalities

I would strongly recommend trying out the 8.14.x version of `Elastic.Clients.Elasticsearch`. There have been a lot of improvements over the past months and nearly all functionality is supported now. Besides that, NEST is deprecated and will be end of life at the end of this year. Newer functionality of ES 8 is exclusively implemented in `Elastic.Clients.Elasticsearch` already.

> However, I am getting the below error while executing the search function:  
> {Unsuccessful () low level call on POST: /demoindexfortest/\_search}

Without the complete error response, it's hard to tell what's going on. From a first glance it seems like your JSON payload is invalid (you got 2 times `query` and at least one closing `}` is missing).

> Below is my code

Is there any specific reason for using the low-level client and a hand-crafted JSON request? If you don't explicitly want to do this, the new `Elastic.Client.Elasticsearch` client can be used to execute the desired query:

```csharp
var response = await client.SearchAsync<Person>(r => r
	.Index("demoindexfortest")
	.Query(q => q
		.MatchAll(ma => { })
	)
);

foreach (var document in response.Documents)
{
	Console.WriteLine(document.Id);
}

```

---

<div class="post-metadata">

**Author:** ![sathish12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathish12/32/143619_2.png) [@sathish12](https://discuss.elastic.co/u/sathish12)\
**Post date:** [August 1, 2024, 4:05pm UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184/3 "2024-08-01T16:05:11Z")

</div>

> [@flobernd](#):
>
> I would strongly recommend trying out the 8.14.x version of `Elastic.Clients.Elasticsearch`. There have been a lot of improvements over the past months and nearly all functionality is supported now. Besides that, NEST is deprecated and will be end of life at the end of this year. Newer functionality of ES 8 is exclusively implemented in `Elastic.Clients.Elasticsearch` already.

Hi flobernd,  
Thanks for the the response. We have setup a multinode and multiple master eligible cluster. However, it took lot of time to setup this up in our machines. I am not sure how much time it would take to setup the cluster from the scratch with 8.14.x the latest. The problem is it was taking lot of time to resolve issue of split brain situation. Later I learnt that I have to delete the data, config/certs folders and change the elasticsearch.yml every time I add a new machine to the cluster. However, I am ready to migrate to 8.14.X if there is any easy way where I dont have to setup from the scratch and do not lose the data which is present right now.

> [@flobernd](#):
>
> Without the complete error response, it's hard to tell what's going on. From a first glance it seems like your JSON payload is invalid (you got 2 times `query` and at least one closing `}` is missing).

I am extremely sorry as the above json provided is a typo. Below is the proper one which I have tried and getting the error:

> [@sathish12](#):
>
> ```auto
> var pool = new SingleNodeConnectionPool(new Uri(ConfigurationManager.AppSettings["ElasticSearchUrl"]));
>      
> var setting = new Nest.ConnectionSettings(pool)
> .CertificateFingerprint("adsfa.asdfasdfasfasdfasdfasdfasdfasdfasdfasdfasdfasfasdfasdfasf")
> .RequestTimeout(TimeSpan.FromMinutes(2))
> .BasicAuthentication(ConfigurationManager.AppSettings["elasticUser"], ConfigurationManager.AppSettings["elasticPwd"])
> .EnableApiVersioningHeader();
> var client = new Nest.ElasticClient(setting);
> var lowlevelClient = client.LowLevel;
> string es_query = @"{
> ""_source"": [""Index""],
> ""query"": {
> ""match_all"": { }
> }
> }";
> 
> Debug.WriteLine(es_query);
> try
> {
> 
>             
> var searchResponse = lowlevelClient.Search<BytesResponse>("demoindexfortest", PostData.String(es_query));
> var responseBytes = searchResponse.Body;
> }
> 
> ```

However The response is the same

> [@flobernd](#):
>
> Is there any specific reason for using the low-level client and a hand-crafted JSON request? If you don't explicitly want to do this, the new `Elastic.Client.Elasticsearch` client can be used to execute the desired query:

As I said flobernd, we are upgrading from 2.3.2 to 8.13.4. So our .NET code was using string based query at one point. and we are trying to use the same without changing. Here we have only provided basic string query. But we are using a big json query which has aggregations, filters on the date and fields.

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [August 2, 2024, 7:49am UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184/4 "2024-08-02T07:49:31Z")

</div>

> [@sathish12](#):
>
> We have setup a multinode and multiple master eligible cluster. However, it took lot of time to setup this up in our machines. I am not sure how much time it would take to setup the cluster from the scratch with 8.14.x the latest.

You don't have to update the cluster in order to use `Elastic.Clients.Elasticsearch` 8.14.x over `NEST`. Only the client package must be changed.

> [@sathish12](#):
>
> Below is the proper one which I have tried and getting the error

Any chance you could post the complete error message / debug information? The error message you've provided is too generic to find out the root cause of this.

> [@sathish12](#):
>
> So our .NET code was using string based query at one point. and we are trying to use the same without changing.

While using the low level client is of course an option, I would still recommend you to interatively update pieces of your code to use the high level API instead. It provides many quality of life improvements, type-safety and minimizes the overall risk of writing bad queries.

---

<div class="post-metadata">

**Author:** ![sathish12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathish12/32/143619_2.png) [@sathish12](https://discuss.elastic.co/u/sathish12)\
**Post date:** [August 6, 2024, 6:13am UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184/5 "2024-08-06T06:13:09Z")

</div>

> [@flobernd](#):
>
> You don't have to update the cluster in order to use `Elastic.Clients.Elasticsearch` 8.14.x over `NEST`. Only the client package must be changed

Sure we will update the clientband try it out. But any documentation on this elastic.client.elasticsearch would be really helpful

---

<div class="post-metadata">

**Author:** ![sathish12](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sathish12/32/143619_2.png) [@sathish12](https://discuss.elastic.co/u/sathish12)\
**Post date:** [September 4, 2024, 7:25am UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184/6 "2024-09-04T07:25:03Z")

</div>

Hi @flobernd ,  
We have upgraded our elastic.client.elasticsearch library to new 8.15.5 and we have a requirement to query one of the indices that we should get the data between a specific datetime range. Below is the json query which we have prepared while testing through curl

```auto
{
    "query": {
        "bool": {
            "must": [
            {
                "query_string": {
                "analyze_wildcard": true,
                "query": "*"
                }
            },
            {
                "range": {
                    "@timestamp": {
                        "gte": 1724602611000,
                        "lte": 1724607616000,
                        "format": "epoch_millis"
                    }
                }
            }
            ],
            "must_not": []
        }
        },
        "size": 0,
        "aggs": {
        "timev": {
            "date_histogram": {
            "field": "@timestamp",
            "fixed_interval": "1m", 
            "min_doc_count": 1,
            "extended_bounds": {
                "min": 1724602611000,
                "max": 1724607616000
            }
            },
            "aggs": {
            "avv": {
                "avg": {
                "field": "demo_field_name"
                }
            }
            }
        }
        }
} 

```

and we are getting our data with the above json query. However, we are not able to convert this query to .NET client code. we are seeing multiple method not found errors while trying to write the code. Is there any way where we can pass the raw json or write the code with ease. Because we are new to this and I dont find the proper documentation also on the code base

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [September 5, 2024, 7:59am UTC](https://discuss.elastic.co/t/elasticsearch-net-7-17-x-unable-to-connect-elasticsearch-8-13-4-version/364184/7 "2024-09-05T07:59:23Z")

</div>

Hi @sathish12,

the DSL of the new client maps pretty closely to the JSON structure and should allow for a nearly 1:1 translation.

Which methods are missing for you?

Edit: I took the time to translate the query for you, hoping that this will get you started. As you can see, besides of the C# specific things, the DSL pretty closely matches the structure of the JSON request.

```csharp
var re = await client.SearchAsync<MyDocument>(s => s
    .Query(q => q
        .Bool(b => b
            .Must(
            [
                q => q.QueryString(qs => qs
                    .AnalyzeWildcard(true)
                    .Query("*")
                ),
                q => q.Range(rq => rq
                    .DateRange(dr => dr
                        .Field("@timestamp"!)
                        .Gte(DateMath.Anchored(DateTimeOffset.FromUnixTimeMilliseconds(1724602611000).DateTime))
                        .Lte(DateMath.Anchored(DateTimeOffset.FromUnixTimeMilliseconds(1724607616000).DateTime))
                        .Format("epoch_millis")
                    )
                )
            ])
            .MustNot(new Query[] { })
        )
    )
    .Size(0)
    .Aggregations(aggs => aggs
        .Add("timev", agg => agg
            .DateHistogram(dh => dh
                .Field("@timestamp"!)
                .FixedInterval(TimeSpan.FromMinutes(1))
                .MinDocCount(1)
                .ExtendedBounds(bnd => bnd
                    .Min(new FieldDateMath(1724602611000))
                    .Max(new FieldDateMath(1724607616000))
                )
            )
            .Aggregations(sub => sub
                .Add("avv", agg => agg
                    .Avg(aa => aa
                        .Field("demo_field_name")
                    )
                )
            )
        )
    )
);

```
