Class DateIntervalWrapper
java.lang.Object
org.elasticsearch.search.aggregations.bucket.histogram.DateIntervalWrapper
- All Implemented Interfaces:
Writeable
,org.elasticsearch.common.xcontent.ToXContent
,org.elasticsearch.common.xcontent.ToXContentFragment
public class DateIntervalWrapper
extends Object
implements org.elasticsearch.common.xcontent.ToXContentFragment, Writeable
A class that handles all the parsing, bwc and deprecations surrounding date histogram intervals.
- Provides parser helpers for the deprecated interval/dateHistogramInterval parameters.
- Provides parser helpers for the new calendar/fixed interval parameters
- Can read old intervals from a stream and convert to new intervals
- Can write new intervals to old format when streaming out
- Provides a variety of helper methods to interpret the intervals as different types, depending on caller's need
After the deprecated parameters are removed, this class can be simplified greatly. The legacy options
will be removed, and the mutual-exclusion checks can be done in the setters directly removing the need
for the enum and the complicated "state machine" logic
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
calendarInterval(DateHistogramInterval interval)
Sets the interval of the DateHistogram using calendar units (`1d`, `1w`, `1M`, etc).createRounding(ZoneId timeZone, long offset)
Deprecated.void
dateHistogramInterval(DateHistogramInterval dateHistogramInterval)
Deprecated.static <T extends DateIntervalConsumer>
voiddeclareIntervalFields(org.elasticsearch.common.xcontent.ObjectParser<T,String> parser)
boolean
void
fixedInterval(DateHistogramInterval interval)
Sets the interval of the DateHistogram using fixed units (`1ms`, `1s`, `10m`, `4h`, etc).Returns the interval as a calendar interval.Returns the interval as a Fixed interval.int
hashCode()
long
interval()
Deprecated.void
interval(long interval)
boolean
isEmpty()
org.elasticsearch.common.xcontent.XContentBuilder
toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
void
writeTo(StreamOutput out)
Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment
-
Constructor Details
-
DateIntervalWrapper
public DateIntervalWrapper() -
DateIntervalWrapper
- Throws:
IOException
-
-
Method Details
-
declareIntervalFields
public static <T extends DateIntervalConsumer> void declareIntervalFields(org.elasticsearch.common.xcontent.ObjectParser<T,String> parser) -
getIntervalType
-
interval
Deprecated.Get the current interval in milliseconds that is set on this builder. -
interval
Deprecated.Set the interval on this builder, and return the builder so that calls can be chained. If bothinterval()
anddateHistogramInterval()
are set, then thedateHistogramInterval()
wins.- Since:
- 7.2.0
-
dateHistogramInterval
Deprecated.Get the current date interval that is set on this builder. -
dateHistogramInterval
Deprecated.Set the interval on this builder, and return the builder so that calls can be chained. If bothinterval()
anddateHistogramInterval()
are set, then thedateHistogramInterval()
wins.- Since:
- 7.2.0
-
getAsCalendarInterval
Returns the interval as a calendar interval. Throws an exception if the value cannot be converted into a calendar interval -
calendarInterval
Sets the interval of the DateHistogram using calendar units (`1d`, `1w`, `1M`, etc). These units are calendar-aware, meaning they respect leap additions, variable days per month, etc. This is mutually exclusive withfixedInterval(DateHistogramInterval)
- Parameters:
interval
- The fixed interval to use
-
getAsFixedInterval
Returns the interval as a Fixed interval. Throws an exception if the value cannot be converted into a fixed interval -
fixedInterval
Sets the interval of the DateHistogram using fixed units (`1ms`, `1s`, `10m`, `4h`, etc). These are not calendar aware and are simply multiples of fixed, SI units. This is mutually exclusive withcalendarInterval(DateHistogramInterval)
- Parameters:
interval
- The fixed interval to use
-
createRounding
-
isEmpty
public boolean isEmpty() -
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput.- Specified by:
writeTo
in interfaceWriteable
- Throws:
IOException
-
toXContent
public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException- Specified by:
toXContent
in interfaceorg.elasticsearch.common.xcontent.ToXContent
- Throws:
IOException
-
equals
-
hashCode
public int hashCode()
-
fixedInterval(DateHistogramInterval)
orcalendarInterval(DateHistogramInterval)
instead