public async Task <ElasticResponse <T> > SearchLogsAggregateByCountryId(GraphCriteria searchCriteria) { SearchDescriptor <T> queryCommand = new SearchDescriptor <T>() .Query(q => q .Bool(bl => bl .Must( fq => { QueryContainer query = null; query &= fq.Term(t => t .Field("countryId").Value(searchCriteria.CountryId) ); return(query); } ) .Filter( ft => new DateRangeQuery { Field = "dateTimeLogged", GreaterThanOrEqualTo = searchCriteria.StartDateTimeLogged, LessThanOrEqualTo = searchCriteria.EndDateTimeLogged }) ) ); queryCommand.Aggregations(AggregateCommand().Result); var result = await BasicQuery(queryCommand); var response = await _logElasticMappers.MapElasticResults(result); if (!result.IsValid) { throw new InvalidOperationException(result.DebugInformation); } return(response); }
public async Task <ElasticResponse <T> > SearchAggregate(GraphCriteria criteria) { SearchDescriptor <T> queryCommand = new SearchDescriptor <T>() .Query(q => q .Bool(bl => bl .Must( fq => { QueryContainer query = null; query &= fq.Term(t => t .Field("countryId").Value(criteria.CountryId) ); return(query); } ) .Filter( ft => new DateRangeQuery { Field = "startDate", //GreaterThanOrEqualTo = criteria.StartDate, LessThanOrEqualTo = criteria.EndDateTimeLogged }) ) ) .Aggregations(ag => { AggregationContainerDescriptor <T> query = null; query &= ag.DateHistogram("my_date_histogram", h => h .Field("startDate") .Interval((DateInterval)Int32.Parse(criteria.TypeAggregation)) .Order(HistogramOrder.KeyDescending) .Aggregations(aa => aa .Sum("order-count", m => m.Field("orderCount")) .Sum("order-value", mm => mm.Field("orderValue")) .Sum("error-count", mm => mm.Field("errorCount")) ) ); return(query); } ) .Sort(q => { return(q .Field(p => p .Field("startDate") .Order(SortOrder.Ascending) )); } ) .From(0) .Size(criteria.NumberOfResults); var result = await BasicQuery(queryCommand); var response = await _dashboardElasticMappers.MapElasticAggregateResults(result, criteria.NumberOfResults); if (!result.IsValid) { throw new InvalidOperationException(result.DebugInformation); } return(response); }