Last active
August 29, 2015 14:06
-
-
Save ThomasArdal/edb530911d051dae8ceb to your computer and use it in GitHub Desktop.
Example of doing aggregated search using Elasticsearch and NEST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = elasticClient.Search<ErrorDocument>(search => search | |
.SearchType(SearchType.Count) | |
.Query(q => q | |
.Range(range => range | |
.OnField(field => field.Time) | |
.GreaterOrEquals(DateTime.UtcNow.AddHours(-24)) | |
.LowerOrEquals(DateTime.UtcNow) | |
) | |
) | |
.Aggregations(a => a | |
.DateHistogram("histogram", s => s | |
.Field(field => field.Time) | |
.Interval("hour") | |
.MinimumDocumentCount(0) | |
) | |
) | |
); | |
var dateHistogram = result.Aggs.DateHistogram("histogram"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment