title: ElasticSearch DateHistogram Aggregation Fill Missing Data
body: <p>I'm trying to use ElasticSearch spring data for some aggregations</p>
  
  <p>Here Is my query</p>
  
  <pre><code>final FilteredQueryBuilder filteredQuery = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
        FilterBuilders.andFilter(FilterBuilders.termFilter("gender", "F"),
        FilterBuilders.termFilter("place", "Arizona"),
        FilterBuilders.rangeFilter("dob").from(from).to(to)));
  
  final MetricsAggregationBuilder&lt;?&gt; aggregateArtifactcount = AggregationBuilders.sum("delivery")
              .field("birth");
  
      final AggregationBuilder&lt;?&gt; dailyDateHistogarm =
         AggregationBuilders.dateHistogram(AggregationConstants.DAILY).field("dob")
          .interval(DateHistogram.Interval.DAY).subAggregation(aggregateArtifactcount);
  
      final SearchQuery query = new NativeSearchQueryBuilder().withIndices(index).withTypes(type)
          .withQuery(filteredQuery).addAggregation(dailyDateHistogarm).build();
  
      return elasticsearchTemplate.query(query, new DailyDeliveryAggregation());
  </code></pre>
  
  <p>Also this is my Aggregation</p>
  
  <pre><code>        public class DailyDeliveryAggregation implements ResultsExtractor&lt;List&lt;DailyDeliverySum&gt;&gt; {
  
  @SuppressWarnings("unchecked")
  @Override
  public List&lt;DailyDeliverySum&gt; extract(final SearchResponse response) {
      final List&lt;DailyDeliverySum&gt; dailyDeliverySum = new ArrayList&lt;DailyDeliverySum&gt;();
      final Aggregations aggregations = response.getAggregations();
      final DateHistogram daily = aggregations.get(AggregationConstants.DAILY);
      final List&lt;DateHistogram.Bucket&gt; buckets = (List&lt;DateHistogram.Bucket&gt;) daily.getBuckets();
      for (final DateHistogram.Bucket bucket : buckets) {
          final Sum sum = (Sum) bucket.getAggregations().getAsMap().get("delivery");
          final int deliverySum = (int) sum.getValue();
          final int delivery = (int) bucket.getDocCount();
          final String dateString = bucket.getKeyAsText().string();
          dailyDeliverySum.add(new DailyDeliverySum(deliverySum, delivery, dateString));
      }
      return dailyDeliverySum;
  }
  }
  </code></pre>
  
  <p>It gives me the correct data , But It doesn't satisfy all my needs 
  Suppose if I query for  time range of 10 days , If there is no data for  a date in the given time range It miss that date in Date histogram buckets ,But I want to set 0 as default value for aggregation and doc count if there is no data available</p>
  
  <p>Is there any way to do it ??</p>