Get date histogram from start to finish date?


(Ha Lan Quyen) #1

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Adrien Grand) #2

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 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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.comhttps://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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4pyONTYuc9_GFEVES8kQ5Kig4%3D1OOEA8jg6iindGBoeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(Ha Lan Quyen) #3

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/, 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<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 <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/72bb3c10-8c47-4601-b7a5-36d23e927fb1%40googlegroups.comhttps://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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/933630bc-5c9b-4b65-a3b3-30a6c0222646%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4