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
  • Constructor Details

    • DateIntervalWrapper

      public DateIntervalWrapper()
    • DateIntervalWrapper

      public DateIntervalWrapper​(StreamInput in) throws java.io.IOException
      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

      public DateIntervalWrapper.IntervalTypeEnum 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)
      Set the interval on this builder, and return the builder so that calls can be chained. If both interval() and dateHistogramInterval() are set, then the dateHistogramInterval() wins.
      Since:
      7.2.0
    • dateHistogramInterval

      @Deprecated public DateHistogramInterval dateHistogramInterval()
      Deprecated.
      Get the current date interval that is set on this builder.
    • dateHistogramInterval

      @Deprecated public void dateHistogramInterval​(DateHistogramInterval dateHistogramInterval)
      Set the interval on this builder, and return the builder so that calls can be chained. If both interval() and dateHistogramInterval() are set, then the dateHistogramInterval() wins.
      Since:
      7.2.0
    • getAsCalendarInterval

      public DateHistogramInterval getAsCalendarInterval()
      Returns the interval as a calendar interval. Throws an exception if the value cannot be converted into a calendar interval
    • calendarInterval

      public void calendarInterval​(DateHistogramInterval interval)
      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 with fixedInterval(DateHistogramInterval)
      Parameters:
      interval - The fixed interval to use
    • getAsFixedInterval

      public DateHistogramInterval getAsFixedInterval()
      Returns the interval as a Fixed interval. Throws an exception if the value cannot be converted into a fixed interval
    • fixedInterval

      public void fixedInterval​(DateHistogramInterval interval)
      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 with calendarInterval(DateHistogramInterval)
      Parameters:
      interval - The fixed interval to use
    • createRounding

      public Rounding createRounding​(java.time.ZoneId timeZone, long offset)
    • isEmpty

      public boolean isEmpty()
    • writeTo

      public void writeTo​(StreamOutput out) throws java.io.IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      java.io.IOException
    • 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 interface org.elasticsearch.common.xcontent.ToXContent
      Throws:
      java.io.IOException
    • equals

      public boolean equals​(java.lang.Object other)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object