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 java.lang.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 Modifier and Type Class Description static class
DateIntervalWrapper.IntervalTypeEnum
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
Constructors Constructor Description DateIntervalWrapper()
DateIntervalWrapper(StreamInput in)
-
Method Summary
Modifier and Type Method Description void
calendarInterval(DateHistogramInterval interval)
Sets the interval of the DateHistogram using calendar units (`1d`, `1w`, `1M`, etc).Rounding
createRounding(java.time.ZoneId timeZone, long offset)
DateHistogramInterval
dateHistogramInterval()
Deprecated.void
dateHistogramInterval(DateHistogramInterval dateHistogramInterval)
Deprecated.static <T extends DateIntervalConsumer>
voiddeclareIntervalFields(org.elasticsearch.common.xcontent.ObjectParser<T,java.lang.String> parser)
boolean
equals(java.lang.Object other)
void
fixedInterval(DateHistogramInterval interval)
Sets the interval of the DateHistogram using fixed units (`1ms`, `1s`, `10m`, `4h`, etc).DateHistogramInterval
getAsCalendarInterval()
Returns the interval as a calendar interval.DateHistogramInterval
getAsFixedInterval()
Returns the interval as a Fixed interval.DateIntervalWrapper.IntervalTypeEnum
getIntervalType()
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:
java.io.IOException
-
-
Method Details
-
declareIntervalFields
public static <T extends DateIntervalConsumer> void declareIntervalFields(org.elasticsearch.common.xcontent.ObjectParser<T,java.lang.String> parser) -
getIntervalType
-
interval
@Deprecated public long interval()Deprecated.Get the current interval in milliseconds that is set on this builder. -
interval
@Deprecated public void interval(long 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. -
toXContent
public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException- Specified by:
toXContent
in interfaceorg.elasticsearch.common.xcontent.ToXContent
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
fixedInterval(DateHistogramInterval)
orcalendarInterval(DateHistogramInterval)
instead