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.