# Java API "extended\_bounds" Not Working?

**URL:** <https://discuss.elastic.co/t/java-api-extended-bounds-not-working/20189>\
**Category:** Elasticsearch\
**Created:** [October 10, 2014, 6:09pm UTC](https://discuss.elastic.co/t/java-api-extended-bounds-not-working/20189 "2014-10-10T18:09:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael\_4](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@michael\_4](https://discuss.elastic.co/u/michael_4)\
**Post date:** [October 10, 2014, 6:09pm UTC](https://discuss.elastic.co/t/java-api-extended-bounds-not-working/20189/1 "2014-10-10T18:09:57Z")

</div>

Hi Guys,

I'm trying to run a Date Histogram aggregation, with extended\_bounds that  
cover (now-7d) -\> now, and return 0 doc-count buckets. This works perfectly  
in Sense, but when running in Java, the response does not include  
my extended bounds. Strange part is, debugging the program reveals that  
Java API sends the correct request (in JSON format), but receives a  
different response than the one I'm getting in Sense.

Request sent (as seen in Java debug):  
{  
"size" : 0,  
"query" : {  
"filtered" : {  
"query" : {  
"range" : {  
"created\_at" : {  
"from" : "now-7d",  
"to" : null,  
"include\_lower" : true,  
"include\_upper" : true  
}  
}  
},  
"filter" : {  
"term" : {  
"id" : "12345678"  
}  
}  
}  
},  
"fields" : [],  
"aggregations" : {  
"interactions\_per\_day" : {  
"date\_histogram" : {  
"field" : "created\_at",  
"interval" : "1d",  
"min\_doc\_count" : 0,  
"format" : "MM-dd-yyyy",  
"extended\_bounds" : {  
"min" : "now-7d",  
"max" : "now"  
}  
}  
}  
}  
}

Response received in Sense:  
{  
"took": 8,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 30,  
"max\_score": 0,  
"hits": []  
},  
"aggregations": {  
"interactions\_per\_day": {  
"buckets": [  
{  
"key\_as\_string": "10-03-2014",  
"key": 1412294400000,  
"doc\_count": 0  
},  
{  
"key\_as\_string": "10-04-2014",  
"key": 1412380800000,  
"doc\_count": 0  
},  
{  
"key\_as\_string": "10-05-2014",  
"key": 1412467200000,  
"doc\_count": 9  
},  
{  
"key\_as\_string": "10-06-2014",  
"key": 1412553600000,  
"doc\_count": 0  
},  
{  
"key\_as\_string": "10-07-2014",  
"key": 1412640000000,  
"doc\_count": 7  
},  
{  
"key\_as\_string": "10-08-2014",  
"key": 1412726400000,  
"doc\_count": 13  
},  
{  
"key\_as\_string": "10-09-2014",  
"key": 1412812800000,  
"doc\_count": 1  
},  
{  
"key\_as\_string": "10-10-2014",  
"key": 1412899200000,  
"doc\_count": 0  
}  
]  
}  
}  
}

Response in Java:  
{  
"took" : 6,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 54,  
"successful" : 54,  
"failed" : 0  
},  
"hits" : {  
"total" : 30,  
"max\_score" : 0.0,  
"hits" : []  
},  
"aggregations" : {  
"interactions\_per\_day" : {  
"buckets" : [ {  
"key\_as\_string" : "10-05-2014",  
"key" : 1412467200000,  
"doc\_count" : 9  
}, {  
"key\_as\_string" : "10-06-2014",  
"key" : 1412553600000,  
"doc\_count" : 0  
}, {  
"key\_as\_string" : "10-07-2014",  
"key" : 1412640000000,  
"doc\_count" : 7  
}, {  
"key\_as\_string" : "10-08-2014",  
"key" : 1412726400000,  
"doc\_count" : 13  
}, {  
"key\_as\_string" : "10-09-2014",  
"key" : 1412812800000,  
"doc\_count" : 1  
} ]  
}  
}  
}

What am I missing? Here's my Java code:  
FilterBuilder filter = FilterBuilders.termFilter("id", id);  
QueryBuilder query =  
QueryBuilders.rangeQuery("created\_at").gte("now-7d");

```
    AggregationBuilder aggs = AggregationBuilders
            .dateHistogram("interactions_per_day")
            .field("created_at")
            .format("MM-dd-yyyy")
            .minDocCount(0l)
            .extendedBounds("now-7d", "now")
            .interval(DateHistogram.Interval.DAY);

    SearchRequestBuilder request = elasticsearchPool.prepareSearch()
            .setQuery(QueryBuilders.filteredQuery(query, filter))
            .addAggregation(aggs)
            .setNoFields()
            .setSize(0);

    SearchResponse search = request
            .execute()
            .actionGet();

```

Any help or insight would be greatly appreciated...

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3a553804-702d-4038-88cd-2cb0efef0995%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3a553804-702d-4038-88cd-2cb0efef0995%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:56am UTC](https://discuss.elastic.co/t/java-api-extended-bounds-not-working/20189/2 "2017-07-06T00:56:57Z")

</div>


