# Get date histogram from start to finish date?

**URL:** <https://discuss.elastic.co/t/get-date-histogram-from-start-to-finish-date/17386>\
**Category:** Elasticsearch\
**Created:** [May 7, 2014, 9:30am UTC](https://discuss.elastic.co/t/get-date-histogram-from-start-to-finish-date/17386 "2014-05-07T09:30:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ha\_Lan\_Quyen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ha_lan_quyen/32/1585_2.png) [@Ha\_Lan\_Quyen](https://discuss.elastic.co/u/Ha_Lan_Quyen)\
**Post date:** [May 7, 2014, 9:30am UTC](https://discuss.elastic.co/t/get-date-histogram-from-start-to-finish-date/17386/1 "2014-05-07T09:30:42Z")

</div>

Hi

I need to get date histogram with interval is day, but I want to limit from  
a start date to finish date. So how can I do it in java? Here is my source  
code but it seem doesn't work correctly

RangeFilterBuilder dateRangeFilter = FilterBuilders.rangeFilter("date");  
dateRangeFilter.gte(start.getTime()).lte(finish.getTime());

SearchResponse response = client.prepareSearch(indices)  
.setTypes("html")  
.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)

.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),  
dateRangeFilter))

.addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.DAY))  
.execute()  
.actionGet();

Thanks

--  
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/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [May 7, 2014, 12:04pm UTC](https://discuss.elastic.co/t/get-date-histogram-from-start-to-finish-date/17386/2 "2014-05-07T12:04:23Z")

</div>

Your code looks good. What makes you think that it doesn't work?

On Wed, May 7, 2014 at 11:30 AM, Ha Lan Quyen [dangokuson@gmail.com](mailto:dangokuson@gmail.com) wrote:

> Hi
> 
> I need to get date histogram with interval is day, but I want to limit  
> from a start date to finish date. So how can I do it in java? Here is my  
> source code but it seem doesn't work correctly
> 
> RangeFilterBuilder dateRangeFilter = FilterBuilders.rangeFilter("date");  
> dateRangeFilter.gte(start.getTime()).lte(finish.getTime());
> 
> SearchResponse response = client.prepareSearch(indices)  
> .setTypes("html")  
> .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)
> 
> .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),  
> dateRangeFilter))
> 
> .addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.DAY))  
> .execute()  
> .actionGet();
> 
> Thanks
> 
> --  
> 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/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j4pyONTYuc9\_GFEVES8kQ5Kig4%3D1OOEA8jg6iindGBoeg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4pyONTYuc9_GFEVES8kQ5Kig4%3D1OOEA8jg6iindGBoeg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ha\_Lan\_Quyen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ha_lan_quyen/32/1585_2.png) [@Ha\_Lan\_Quyen](https://discuss.elastic.co/u/Ha_Lan_Quyen)\
**Post date:** [May 7, 2014, 1:54pm UTC](https://discuss.elastic.co/t/get-date-histogram-from-start-to-finish-date/17386/3 "2014-05-07T13:54:32Z")

</div>

Thanks Adrien,

I'm using elasticsearch for report, when have a request to a page on my  
website then I will index that request with some information like url,  
requestDate, hostname, ... by using elasticsearch. After that i used  
elasticsearch to get date histogram by interval is DAY. The problem is the  
doc\_count is not change for a

DateHistogram.Bucket even that request has been indexed many times.

E.g: Have a request URL to a page  
is [http://localhost:8080/test-es/en/elasticsearch/](http://localhost:8080/test-es/en/elasticsearch/), this request is called  
5 times that means it has been indexed 5 times. But elasticsearch  
aggregation response just returned doc\_count is 1. So I think it's wrong.

Do you know why?

Thanks

On Wednesday, May 7, 2014 7:04:23 PM UTC+7, Adrien Grand wrote:

> Your code looks good. What makes you think that it doesn't work?
> 
> On Wed, May 7, 2014 at 11:30 AM, Ha Lan Quyen \<[dango...@gmail.com](mailto:dango...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi
> > 
> > I need to get date histogram with interval is day, but I want to limit  
> > from a start date to finish date. So how can I do it in java? Here is my  
> > source code but it seem doesn't work correctly
> > 
> > RangeFilterBuilder dateRangeFilter = FilterBuilders.rangeFilter("date");  
> > dateRangeFilter.gte(start.getTime()).lte(finish.getTime());
> > 
> > SearchResponse response = client.prepareSearch(indices)  
> > .setTypes("html")  
> > .setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)
> > 
> > .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),  
> > dateRangeFilter))
> > 
> > .addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.DAY))  
> > .execute()  
> > .actionGet();
> > 
> > Thanks
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand

--  
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/933630bc-5c9b-4b65-a3b3-30a6c0222646%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/933630bc-5c9b-4b65-a3b3-30a6c0222646%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, 1:31am UTC](https://discuss.elastic.co/t/get-date-histogram-from-start-to-finish-date/17386/4 "2017-07-06T01:31:05Z")

</div>


