Implementing date histogram facets with ElasticSearch and NEST

My pet project stores every error in Elasticsearch and the search GUI contains a perfect example for doing faceted search: the errors graph in top of the search result.


At the moment the code for this sucker isn’t the stuff I’m most proud of. I simply extract every error created during the last 14 days and doing some LINQ to Objects magic on top of that. Not really optimal. What I really want to do, is letting Elasticsearch create a date histogram containing a dictionary of values where the date is key and the amount of errors created on that date as value. The query turned out to be really simple, once I got a hang on faceted search using NEST (the excellent .NET client for Elasticsearch):

Thanks to Martijn Laarman for the help on StackOverflow.