Java Code Examples for org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval#SECOND

The following examples show how to use org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval#SECOND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EsEventPersistence.java    From logsniffer with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected DateHistogramInterval getInterval(final long timeRange, final int maxSlotsCount,
		final EventsCountHistogram histogram) {
	// year, quarter, month, week, day, hour, minute, second
	long dif = timeRange / maxSlotsCount / 1000;
	if (dif <= 0) {
		histogram.setInterval(HistogramInterval.SECOND);
		return DateHistogramInterval.SECOND;
	} else if (dif < 60) {
		histogram.setInterval(HistogramInterval.MINUTE);
		return DateHistogramInterval.MINUTE;
	} else if ((dif = dif / 60) < 60) {
		histogram.setInterval(HistogramInterval.HOUR);
		return DateHistogramInterval.HOUR;
	} else if ((dif = dif / 60) < 24) {
		histogram.setInterval(HistogramInterval.DAY);
		return DateHistogramInterval.DAY;
	} else if ((dif = dif / 24) < 7) {
		histogram.setInterval(HistogramInterval.WEEK);
		return DateHistogramInterval.WEEK;
	} else if ((dif = dif / 7) < 4) {
		histogram.setInterval(HistogramInterval.MONTH);
		return DateHistogramInterval.MONTH;
	}
	histogram.setInterval(HistogramInterval.YEAR);
	return DateHistogramInterval.YEAR;
}
 
Example 2
Source File: Utils.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
public static DateHistogramInterval getHistogramInterval(Period period) {
    DateHistogramInterval interval;
    switch (period) {
        case seconds:
            interval = DateHistogramInterval.SECOND;
            break;
        case minutes:
            interval = DateHistogramInterval.MINUTE;
            break;
        case hours:
            interval = DateHistogramInterval.HOUR;
            break;
        case days:
            interval = DateHistogramInterval.DAY;
            break;
        default:
            interval = DateHistogramInterval.HOUR;
            break;
    }
    return interval;
}