# Using Nest, queries returning with 0 hits

**URL:** <https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037>\
**Category:** Elasticsearch\
**Created:** [March 12, 2021, 5:38am UTC](https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037 "2021-03-12T05:38:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![asimsek99](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@asimsek99](https://discuss.elastic.co/u/asimsek99)\
**Post date:** [March 12, 2021, 5:38am UTC](https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037/1 "2021-03-12T05:38:42Z")

</div>

Hey hey,

Env: .net Core, Nest, Elasticsearch

I had my queries running with using Logstash and Elastic with AWS. Decided to not use logstash and move to [cloud.elastic.co](http://cloud.elastic.co).

Trying to migrate the current queries to [cloud.elastic.co](http://cloud.elastic.co) but facing problem.

Simply;  
Queries do not bring the correct result (returns 0 hits when it has hits in it if i check from kibana)

Creating ElasticClient as;

```auto
public static ElasticClient CreateClient(string index, ElasticsearchSettings elasticsearchSettings, IConfiguration configuration)
        {
            var node = new Uri(elasticsearchSettings.Uri);
            var pool = new SingleNodeConnectionPool(node);

            var config = new ConnectionSettings(pool);
            config.BasicAuthentication(elasticsearchSettings.Username, elasticsearchSettings.Password);
            config.DefaultIndex(index);
            var client = new ElasticClient(config);

            return client;
        }

```

Doing search as;

```auto
    var result = new MODEL();
    var index = $"{StringsConsts.Elasticsearch.BaseIndexName}*";
    var client = ElasticsearchClientFactory.CreateClient(index, settings.Value.ElasticsearchSettings, configuration);
    var aggaResponse = client.Search<JourneyStepModel>(a => a
                        .Index(index)
                        //.Size(0)
                        .Query(query => query
                                        .DateRange(date => date
                                        .Field(p => p.CreatedDate)
                                        .GreaterThanOrEquals(start)
                                        .LessThanOrEquals(end)
                                        .TimeZone(timeZoneOffset)))

                        .Aggregations(c => c.Cardinality(Aggregation, x => x.Field(f => f.ReferenceNumber))

                   ));
    if (aggaResponse.IsValid)
                {
                    result.Value = Convert.ToInt64(aggaResponse.Aggregations.Cardinality(Aggregation).Value);
                }
                return result;

```

Strangely;  
If i hit **aggaResponse.ApiCall.Uri** with postman, i get the correct result.

In Kibana i have the query written as;

```auto
    GET analytics-*/_search
    {
      "query": {
        "range": {
          "createddate": {
            "gte": "2020-06-08",
            "lte": "2021-10-08",
            "time_zone": "+03:00"
          }
        }
      },
      "aggs": {
        "cardinality": {
          "terms": {
            "field": "referencenumber"
          }
        }
      }
    }

```

which brings the correct data.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 12, 2021, 8:23am UTC](https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037/2 "2021-03-12T08:23:22Z")

</div>

Welcome!

I'm not sure about the service you are using, what it is exactly and how it works behind the scene.

Did you look at [Cloud by Elastic](https://www.elastic.co/cloud), also available if needed from [AWS Marketplace](https://aws.amazon.com/marketplace/pp/Elasticsearch-Inc-Elasticsearch-Service-on-Elastic/B01N6YCISK), [Azure Marketplace](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/elastic.ec-azure?tab=Overview) and [Google Cloud Marketplace](https://console.cloud.google.com/marketplace/details/endpoints/elasticsearch-service.gcpmarketplace.elastic.co)?

Cloud by elastic is one way to have access to **all features** , all managed by us. Think about what is there yet like Security, Monitoring, Reporting, SQL, Canvas, Maps UI, Alerting and built-in solutions named [Observability](https://www.elastic.co/observability), [Security](https://www.elastic.co/security), [Enterprise Search](https://www.elastic.co/enterprise-search) and what is coming next 🙂 ...

And cherry on the cake, we can support it 😉

---

<div class="post-metadata">

**Author:** ![asimsek99](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@asimsek99](https://discuss.elastic.co/u/asimsek99)\
**Post date:** [March 12, 2021, 8:38am UTC](https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037/3 "2021-03-12T08:38:03Z")

</div>

Sorry for typo,  
the service i was using AWS and now trying to move to [elastic.co](http://elastic.co).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 12, 2021, 9:01am UTC](https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037/4 "2021-03-12T09:01:55Z")

</div>

Is there a way to debug what is exactly sent to Elasticsearch? (Sorry, not a dotnet dev here 😉 )

---

<div class="post-metadata">

**Author:** ![asimsek99](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@asimsek99](https://discuss.elastic.co/u/asimsek99)\
**Post date:** [March 21, 2021, 9:22am UTC](https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037/5 "2021-03-21T09:22:30Z")

</div>

I managed to solve my problem, it was because of date-time conversion on runtime.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 18, 2021, 9:23am UTC](https://discuss.elastic.co/t/using-nest-queries-returning-with-0-hits/267037/6 "2021-04-18T09:23:04Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
