Using Nest, queries returning with 0 hits

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.

Trying to migrate the current queries to 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;

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;

    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;

    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.

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, also available if needed from AWS Marketplace, Azure Marketplace and Google Cloud Marketplace?

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, Security, Enterprise Search and what is coming next :slight_smile: ...

And cherry on the cake, we can support it :wink:

Sorry for typo,
the service i was using AWS and now trying to move to elastic.co.

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

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

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