Browse Source

Remove deprecated date histo interval (#75000)

Date histogram interval parameter was deprecated in 7.2, in favor of the more specific fixed_interval and calendar_interval parameters.  The old logic used some poorly understood guessing to decide if it should operate in fixed or calendar mode.  The new logic requires a specific choice by the user, which is more explicit.  In 7.x REST compatibility mode, we will parse the interval as calendar if possible, and otherwise interpret it as fixed.
Mark Tozzi 4 years ago
parent
commit
7af39dbc35
33 changed files with 242 additions and 1247 deletions
  1. 0 20
      docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc
  2. 19 0
      docs/reference/migration/migrate_8_0/aggregations.asciidoc
  3. 1 1
      rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/10_histogram.yml
  4. 0 66
      rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/230_composite.yml
  5. 0 30
      rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/250_moving_fn.yml
  6. 2 2
      server/src/internalClusterTest/java/org/elasticsearch/indices/IndicesRequestCacheIT.java
  7. 44 57
      server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java
  8. 3 3
      server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java
  9. 2 2
      server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/MinDocCountIT.java
  10. 16 16
      server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/ShardReduceIT.java
  11. 6 5
      server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/pipeline/BucketSortIT.java
  12. 9 9
      server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/pipeline/DateDerivativeIT.java
  13. 1 1
      server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/pipeline/MaxBucketIT.java
  14. 0 40
      server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java
  15. 0 38
      server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java
  16. 0 9
      server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalConsumer.java
  17. 59 167
      server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalWrapper.java
  18. 8 15
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java
  19. 0 144
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/LegacyIntervalCompositeAggBuilderTests.java
  20. 29 451
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java
  21. 1 2
      server/src/test/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumAggregatorTests.java
  22. 1 20
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/extractor/ExtractorUtils.java
  23. 3 27
      x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfig.java
  24. 0 15
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java
  25. 15 11
      x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java
  26. 0 41
      x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java
  27. 0 7
      x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java
  28. 1 1
      x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupIndexer.java
  29. 4 38
      x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupRequestTranslationTests.java
  30. 6 2
      x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java
  31. 6 1
      x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java
  32. 4 4
      x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/rollup/rollup_search.yml
  33. 2 2
      x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/condition/CompareConditionSearchTests.java

+ 0 - 20
docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc

@@ -35,26 +35,6 @@ be tacked onto a particular year.
 Fixed intervals are, by contrast, always multiples of SI units and do not change
 based on calendaring context.
 
-[NOTE]
-.Combined `interval` field is deprecated
-==================================
-deprecated[7.2, `interval` field is deprecated] Historically both calendar and fixed
-intervals were configured in a single `interval` field, which led to confusing
-semantics. Specifying `1d` would be assumed as a calendar-aware time,
-whereas `2d` would be interpreted as fixed time. To get "one day" of fixed time,
-the user would need to specify the next smaller unit (in this case, `24h`).
-
-This combined behavior was often unknown to users, and even when knowledgeable about
-the behavior it was difficult to use and confusing.
-
-This behavior has been deprecated in favor of two new, explicit fields: `calendar_interval`
-and `fixed_interval`.
-
-By forcing a choice between calendar and intervals up front, the semantics of the interval
-are clear to the user immediately and there is no ambiguity. The old `interval` field
-will be removed in the future.
-==================================
-
 [[calendar_intervals]]
 ==== Calendar intervals
 

+ 19 - 0
docs/reference/migration/migrate_8_0/aggregations.asciidoc

@@ -20,4 +20,23 @@ Use unique values in the `percents` parameter of the `percentiles` aggregation.
 Requests containing duplicate values in the `percents` parameter will return
 an error.
 ====
+[[date-histogram-interval]]
+.The `date_histogram` aggregation's `interval` parameter is no longer valid.
+[%collapsible]
+====
+*Details* +
+It is now an error to specify the `interval` parameter to the
+{ref}/search-aggregations-bucket-datehistogram-aggregation.html[`date_histogram`
+aggregation] or the
+{ref}/search-aggregations-bucket-composite-aggregation.html#_date_histogram[`composite
+date_histogram` source.  Instead, please use either `calendar_interval` or
+`fixed_interval` as appropriate.
+
+*Impact* +
+Uses of the `interval` parameter in either the `date_histogram` aggregation or
+the `date_histogram` composite source will now generate an error.  Instead
+please use the more specific `fixed_interval` or `calendar_interval`
+parameters.
+====
+
 // end::notable-breaking-changes[]

+ 1 - 1
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/10_histogram.yml

@@ -937,4 +937,4 @@ setup:
             histo:
               date_histogram:
                 field: date
-                interval: second
+                fixed_interval: 1s

+ 0 - 66
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/230_composite.yml

@@ -362,72 +362,6 @@ setup:
                       }
                     ]
 
----
-"Composite aggregation with format":
-  - skip:
-      version: " - 7.1.99"
-      reason:  calendar_interval introduced in 7.2.0
-      features: warnings
-
-  - do:
-      warnings:
-        - '[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.'
-      search:
-        rest_total_hits_as_int: true
-        index: test
-        body:
-          aggregations:
-            test:
-              composite:
-                sources: [
-                  {
-                    "date": {
-                      "date_histogram": {
-                        "field": "date",
-                        "interval": "1d",
-                        "format": "yyyy-MM-dd"
-                      }
-                    }
-                  }
-                ]
-
-  - match: {hits.total: 6}
-  - length: { aggregations.test.buckets: 2 }
-  - match: { aggregations.test.buckets.0.key.date: "2017-10-20" }
-  - match: { aggregations.test.buckets.0.doc_count: 1 }
-  - match: { aggregations.test.buckets.1.key.date: "2017-10-21" }
-  - match: { aggregations.test.buckets.1.doc_count: 1 }
-
-  - do:
-        warnings:
-          - '[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.'
-        search:
-          rest_total_hits_as_int: true
-          index: test
-          body:
-            aggregations:
-              test:
-                composite:
-                  after: {
-                    date: "2017-10-20"
-                  }
-                  sources: [
-                    {
-                      "date": {
-                        "date_histogram": {
-                          "field": "date",
-                          "interval": "1d",
-                          "format": "yyyy-MM-dd"
-                        }
-                      }
-                    }
-                  ]
-
-  - match: {hits.total: 6}
-  - length: { aggregations.test.buckets: 1 }
-  - match: { aggregations.test.buckets.0.key.date: "2017-10-21" }
-  - match: { aggregations.test.buckets.0.doc_count: 1 }
-
 ---
 "Composite aggregation with format and calendar_interval":
   - skip:

+ 0 - 30
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/250_moving_fn.yml

@@ -27,36 +27,6 @@
                     script: "MovingFunctions.windowMax(values)"
 
 ---
-"Bad window deprecated interval":
-
-  - skip:
-      version: " - 7.1.99"
-      reason:  "interval deprecation added in 7.2"
-      features: "warnings"
-
-  - do:
-      catch: /\[window\] must be a positive, non-zero integer\./
-      warnings:
-        - "[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future."
-      search:
-        rest_total_hits_as_int: true
-        body:
-          size: 0
-          aggs:
-            the_histo:
-              date_histogram:
-                field: "date"
-                interval: "1d"
-              aggs:
-                the_avg:
-                  avg:
-                    field: "value_field"
-                the_mov_fn:
-                  moving_fn:
-                    buckets_path: "the_avg"
-                    window: -1
-                    script: "MovingFunctions.windowMax(values)"
----
 "Not under date_histo":
 
   - do:

+ 2 - 2
server/src/internalClusterTest/java/org/elasticsearch/indices/IndicesRequestCacheIT.java

@@ -58,7 +58,7 @@ public class IndicesRequestCacheIT extends ESIntegTestCase {
         // see #9500
         final SearchResponse r1 = client.prepareSearch("index").setSize(0).setSearchType(SearchType.QUERY_THEN_FETCH)
                 .addAggregation(dateHistogram("histo").field("f").timeZone(ZoneId.of("+01:00")).minDocCount(0)
-                        .dateHistogramInterval(DateHistogramInterval.MONTH))
+                        .calendarInterval(DateHistogramInterval.MONTH))
                 .get();
         assertSearchResponse(r1);
 
@@ -69,7 +69,7 @@ public class IndicesRequestCacheIT extends ESIntegTestCase {
         for (int i = 0; i < 10; ++i) {
             final SearchResponse r2 = client.prepareSearch("index").setSize(0)
                     .setSearchType(SearchType.QUERY_THEN_FETCH).addAggregation(dateHistogram("histo").field("f")
-                            .timeZone(ZoneId.of("+01:00")).minDocCount(0).dateHistogramInterval(DateHistogramInterval.MONTH))
+                            .timeZone(ZoneId.of("+01:00")).minDocCount(0).calendarInterval(DateHistogramInterval.MONTH))
                     .get();
             assertSearchResponse(r2);
             Histogram h1 = r1.getAggregations().get("histo");

+ 44 - 57
server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java

@@ -11,7 +11,6 @@ import org.elasticsearch.ElasticsearchException;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.search.SearchPhaseExecutionException;
 import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.jdk.JavaVersion;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.time.DateFormatter;
@@ -20,6 +19,7 @@ import org.elasticsearch.common.time.DateMathParser;
 import org.elasticsearch.index.mapper.DateFieldMapper;
 import org.elasticsearch.index.query.MatchNoneQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.jdk.JavaVersion;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.script.Script;
 import org.elasticsearch.script.ScriptType;
@@ -52,7 +52,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
 
 import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
@@ -65,7 +64,6 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.sum;
 import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
 import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
 import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
-import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.core.IsNull.notNullValue;
@@ -196,7 +194,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
     public void testSingleValuedField() throws Exception {
         SearchResponse response = client().prepareSearch("idx")
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH))
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH))
                 .get();
 
         assertSearchResponse(response);
@@ -231,7 +229,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
     public void testSingleValuedFieldWithTimeZone() throws Exception {
         SearchResponse response = client().prepareSearch("idx")
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(1)
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.DAY).minDocCount(1)
                     .timeZone(ZoneId.of("+01:00"))).execute()
                 .actionGet();
         ZoneId tz = ZoneId.of("+01:00");
@@ -295,7 +293,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         ZoneId tz = ZoneId.of("+01:00");
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo").field("date")
-                        .dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(1)
+                        .calendarInterval(DateHistogramInterval.DAY).minDocCount(1)
                         .timeZone(tz).format(format))
                 .get();
         assertSearchResponse(response);
@@ -333,7 +331,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.key(true)))
                 .get();
 
@@ -356,7 +354,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.key(false)))
                 .get();
 
@@ -378,7 +376,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.count(true)))
                 .get();
 
@@ -400,7 +398,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.count(false)))
                 .get();
 
@@ -420,7 +418,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
     public void testSingleValuedFieldWithSubAggregation() throws Exception {
         SearchResponse response = client().prepareSearch("idx")
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH)
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH)
                         .subAggregation(sum("sum").field("value")))
                 .get();
 
@@ -480,7 +478,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.aggregation("sum", true))
                         .subAggregation(max("sum").field("value")))
                 .get();
@@ -503,7 +501,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.aggregation("sum", false))
                         .subAggregation(max("sum").field("value")))
                 .get();
@@ -526,7 +524,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.aggregation("stats", "sum", false))
                         .subAggregation(stats("stats").field("value")))
                 .get();
@@ -549,7 +547,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
             .addAggregation(dateHistogram("histo")
                 .field("date")
-                .dateHistogramInterval(DateHistogramInterval.MONTH)
+                .calendarInterval(DateHistogramInterval.MONTH)
                 .order(BucketOrder.aggregation("max_constant", randomBoolean()))
                 .subAggregation(max("max_constant").field("constant")))
             .get();
@@ -575,10 +573,10 @@ public class DateHistogramIT extends ESIntegTestCase {
                 .prepareSearch("idx")
                 .addAggregation(
                     dateHistogram("histo").field("date")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.aggregation("inner_histo>avg", asc))
                         .subAggregation(dateHistogram("inner_histo")
-                            .dateHistogramInterval(DateHistogramInterval.MONTH)
+                            .calendarInterval(DateHistogramInterval.MONTH)
                             .field("dates")
                             .subAggregation(avg("avg").field("value"))))
                 .get();
@@ -606,7 +604,7 @@ public class DateHistogramIT extends ESIntegTestCase {
                 .addAggregation(dateHistogram("histo")
                         .field("date")
                         .script(new Script(ScriptType.INLINE, "mockscript", DateScriptMocksPlugin.LONG_PLUS_ONE_MONTH, params))
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)).get();
+                        .calendarInterval(DateHistogramInterval.MONTH)).get();
 
         assertSearchResponse(response);
 
@@ -650,7 +648,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
     public void testMultiValuedField() throws Exception {
         SearchResponse response = client().prepareSearch("idx")
-                .addAggregation(dateHistogram("histo").field("dates").dateHistogramInterval(DateHistogramInterval.MONTH))
+                .addAggregation(dateHistogram("histo").field("dates").calendarInterval(DateHistogramInterval.MONTH))
                 .get();
 
         assertSearchResponse(response);
@@ -694,7 +692,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo")
                         .field("dates")
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)
+                        .calendarInterval(DateHistogramInterval.MONTH)
                         .order(BucketOrder.count(false)))
                 .get();
 
@@ -745,7 +743,7 @@ public class DateHistogramIT extends ESIntegTestCase {
                 .addAggregation(dateHistogram("histo")
                         .field("dates")
                         .script(new Script(ScriptType.INLINE, "mockscript", DateScriptMocksPlugin.LONG_PLUS_ONE_MONTH, params))
-                        .dateHistogramInterval(DateHistogramInterval.MONTH)).get();
+                        .calendarInterval(DateHistogramInterval.MONTH)).get();
 
         assertSearchResponse(response);
 
@@ -798,7 +796,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo").script(
                     new Script(ScriptType.INLINE, "mockscript", DateScriptMocksPlugin.EXTRACT_FIELD, params))
-                    .dateHistogramInterval(DateHistogramInterval.MONTH))
+                    .calendarInterval(DateHistogramInterval.MONTH))
                 .get();
 
         assertSearchResponse(response);
@@ -837,7 +835,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo").script(
                     new Script(ScriptType.INLINE, "mockscript", DateScriptMocksPlugin.EXTRACT_FIELD, params))
-                    .dateHistogramInterval(DateHistogramInterval.MONTH))
+                    .calendarInterval(DateHistogramInterval.MONTH))
                 .get();
 
         assertSearchResponse(response);
@@ -890,7 +888,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
     public void testUnmapped() throws Exception {
         SearchResponse response = client().prepareSearch("idx_unmapped")
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH))
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH))
                 .get();
 
         assertSearchResponse(response);
@@ -903,7 +901,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
     public void testPartiallyUnmapped() throws Exception {
         SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH))
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH))
                 .get();
 
         assertSearchResponse(response);
@@ -940,7 +938,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
                 .setQuery(matchAllQuery())
                 .addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0)
-                        .subAggregation(dateHistogram("date_histo").field("value").interval(1)))
+                        .subAggregation(dateHistogram("date_histo").field("value").fixedInterval(DateHistogramInterval.HOUR)))
                 .get();
 
         assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
@@ -976,7 +974,7 @@ public class DateHistogramIT extends ESIntegTestCase {
                 .addAggregation(dateHistogram("date_histo")
                         .field("date")
                         .timeZone(ZoneId.of("-02:00"))
-                        .dateHistogramInterval(DateHistogramInterval.DAY)
+                        .calendarInterval(DateHistogramInterval.DAY)
                         .format("yyyy-MM-dd:HH-mm-ssZZZZZ"))
                 .get();
 
@@ -1070,7 +1068,7 @@ public class DateHistogramIT extends ESIntegTestCase {
             response = client().prepareSearch("idx2")
                     .addAggregation(dateHistogram("histo")
                             .field("date")
-                            .dateHistogramInterval(DateHistogramInterval.days(interval))
+                            .fixedInterval(DateHistogramInterval.days(interval))
                             .minDocCount(0)
                                     // when explicitly specifying a format, the extended bounds should be defined by the same format
                             .extendedBounds(new LongBounds(format(boundsMin, pattern), format(boundsMax, pattern)))
@@ -1140,7 +1138,7 @@ public class DateHistogramIT extends ESIntegTestCase {
                 .setQuery(QueryBuilders.rangeQuery("date")
                     .from("now/d").to("now/d").includeLower(true).includeUpper(true).timeZone(timezone.getId()))
                 .addAggregation(
-                        dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.hours(1))
+                        dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.hours(1))
                                 .timeZone(timezone).minDocCount(0).extendedBounds(new LongBounds("now/d", "now/d+23h"))
                 ).get();
         assertSearchResponse(response);
@@ -1192,7 +1190,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         response = client()
                 .prepareSearch(index)
                 .addAggregation(
-                        dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.days(1))
+                        dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.days(1))
                                 .offset("+6h").minDocCount(0)
                                 .extendedBounds(new LongBounds("2016-01-01T06:00:00Z", "2016-01-08T08:00:00Z"))
                 ).get();
@@ -1241,7 +1239,7 @@ public class DateHistogramIT extends ESIntegTestCase {
                 .setQuery(matchAllQuery())
                 .addAggregation(dateHistogram("date_histo")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.DAY))
+                        .calendarInterval(DateHistogramInterval.DAY))
                 .get();
 
         assertSearchHits(response, "0", "1", "2", "3", "4");
@@ -1261,7 +1259,7 @@ public class DateHistogramIT extends ESIntegTestCase {
     public void testIssue6965() {
         SearchResponse response = client().prepareSearch("idx")
                 .addAggregation(dateHistogram("histo").field("date").timeZone(ZoneId.of("+01:00"))
-                    .dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0))
+                    .calendarInterval(DateHistogramInterval.MONTH).minDocCount(0))
                 .get();
 
         assertSearchResponse(response);
@@ -1302,7 +1300,7 @@ public class DateHistogramIT extends ESIntegTestCase {
                 client().prepareIndex("test9491").setSource("d", "2014-11-08T13:00:00Z"));
         ensureSearchable("test9491");
         SearchResponse response = client().prepareSearch("test9491")
-                .addAggregation(dateHistogram("histo").field("d").dateHistogramInterval(DateHistogramInterval.YEAR)
+                .addAggregation(dateHistogram("histo").field("d").calendarInterval(DateHistogramInterval.YEAR)
                     .timeZone(ZoneId.of("Asia/Jerusalem")).format("yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"))
                 .get();
         assertSearchResponse(response);
@@ -1320,7 +1318,7 @@ public class DateHistogramIT extends ESIntegTestCase {
                 client().prepareIndex("test8209").setSource("d", "2014-04-30T00:00:00Z"));
         ensureSearchable("test8209");
         SearchResponse response = client().prepareSearch("test8209")
-                .addAggregation(dateHistogram("histo").field("d").dateHistogramInterval(DateHistogramInterval.MONTH)
+                .addAggregation(dateHistogram("histo").field("d").calendarInterval(DateHistogramInterval.MONTH)
                     .format("yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX")
                     .timeZone(ZoneId.of("CET")).minDocCount(0))
                 .get();
@@ -1338,18 +1336,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         internalCluster().wipeIndices("test8209");
     }
 
-    /**
-     * see issue #9634, negative dateHistogramInterval in date_histogram should raise exception
-     */
-    public void testExceptionOnNegativeInterval() {
-        try {
-            client().prepareSearch("idx")
-                    .addAggregation(dateHistogram("histo").field("date").interval(-TimeUnit.DAYS.toMillis(1)).minDocCount(0)).get();
-            fail();
-        } catch (IllegalArgumentException e) {
-            assertThat(e.toString(), containsString("[interval] must be 1 or greater for aggregation [date_histogram]"));
-        }
-    }
+    // TODO: add some tests for negative fixed and calendar intervals
 
     /**
      * https://github.com/elastic/elasticsearch/issues/31760 shows an edge case where an unmapped "date" field in two indices
@@ -1365,7 +1352,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
         SearchResponse response = client().prepareSearch(indexDateUnmapped)
                 .addAggregation(
-                        dateHistogram("histo").field("dateField").dateHistogramInterval(DateHistogramInterval.MONTH).format("yyyy-MM")
+                        dateHistogram("histo").field("dateField").calendarInterval(DateHistogramInterval.MONTH).format("yyyy-MM")
                                 .minDocCount(0).extendedBounds(new LongBounds("2018-01", "2018-01")))
                 .get();
         assertSearchResponse(response);
@@ -1387,7 +1374,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         indexRandom(true, client().prepareIndex(index).setSource("d", "1477954800000"));
         ensureSearchable(index);
         SearchResponse response = client().prepareSearch(index).addAggregation(dateHistogram("histo").field("d")
-                .dateHistogramInterval(DateHistogramInterval.MONTH).timeZone(ZoneId.of("Europe/Berlin"))).get();
+                .calendarInterval(DateHistogramInterval.MONTH).timeZone(ZoneId.of("Europe/Berlin"))).get();
         assertSearchResponse(response);
         Histogram histo = response.getAggregations().get("histo");
         assertThat(histo.getBuckets().size(), equalTo(1));
@@ -1399,7 +1386,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         assertThat(histo.getBuckets().get(0).getDocCount(), equalTo(1L));
 
         response = client().prepareSearch(index).addAggregation(dateHistogram("histo").field("d")
-                .dateHistogramInterval(DateHistogramInterval.MONTH).timeZone(ZoneId.of("Europe/Berlin")).format("yyyy-MM-dd"))
+                .calendarInterval(DateHistogramInterval.MONTH).timeZone(ZoneId.of("Europe/Berlin")).format("yyyy-MM-dd"))
                 .get();
         assertSearchResponse(response);
         histo = response.getAggregations().get("histo");
@@ -1438,7 +1425,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         response = client().prepareSearch("idx")
             .setQuery(new MatchNoneQueryBuilder())
             .addAggregation(dateHistogram("histo").field("date").timeZone(ZoneId.of("Europe/Oslo"))
-                .dateHistogramInterval(DateHistogramInterval.HOUR).minDocCount(0).extendedBounds(
+                .calendarInterval(DateHistogramInterval.HOUR).minDocCount(0).extendedBounds(
                     new LongBounds("2015-10-25T02:00:00.000+02:00", "2015-10-25T04:00:00.000+01:00")))
             .get();
 
@@ -1477,7 +1464,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         params.put("fieldname", "d");
         SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(dateHistogram("histo").field("d")
             .script(new Script(ScriptType.INLINE, "mockscript", DateScriptMocksPlugin.CURRENT_DATE, params))
-            .dateHistogramInterval(DateHistogramInterval.MONTH)).get();
+            .calendarInterval(DateHistogramInterval.MONTH)).get();
         assertSearchResponse(r);
 
         assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
@@ -1488,7 +1475,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         // Test that a request using a deterministic script gets cached
         r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(dateHistogram("histo").field("d")
                 .script(new Script(ScriptType.INLINE, "mockscript", DateScriptMocksPlugin.LONG_PLUS_ONE_MONTH, params))
-                .dateHistogramInterval(DateHistogramInterval.MONTH)).get();
+                .calendarInterval(DateHistogramInterval.MONTH)).get();
         assertSearchResponse(r);
 
         assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
@@ -1498,7 +1485,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
         // Ensure that non-scripted requests are cached as normal
         r = client().prepareSearch("cache_test_idx").setSize(0)
-                .addAggregation(dateHistogram("histo").field("d").dateHistogramInterval(DateHistogramInterval.MONTH)).get();
+                .addAggregation(dateHistogram("histo").field("d").calendarInterval(DateHistogramInterval.MONTH)).get();
         assertSearchResponse(r);
 
         assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
@@ -1548,7 +1535,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client()
             .prepareSearch("sort_idx")
             .addAggregation(
-                dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).order(BucketOrder.compound(order))
+                dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.DAY).order(BucketOrder.compound(order))
                     .subAggregation(avg("avg_l").field("l")).subAggregation(sum("sum_d").field("d"))).get();
 
         assertSearchResponse(response);
@@ -1591,7 +1578,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         //Search interval 24 hours
         SearchResponse r = client().prepareSearch("nanos")
             .addAggregation(dateHistogram("histo").field("date").
-                interval(1000 * 60 * 60 * 24).timeZone(ZoneId.of("Europe/Berlin")))
+                fixedInterval(DateHistogramInterval.seconds(60 * 60 * 24)).timeZone(ZoneId.of("Europe/Berlin")))
             .addDocValueField("date")
             .get();
         assertSearchResponse(r);
@@ -1606,7 +1593,7 @@ public class DateHistogramIT extends ESIntegTestCase {
 
         r = client().prepareSearch("nanos")
             .addAggregation(dateHistogram("histo").field("date")
-                .interval(1000 * 60 * 60 * 24).timeZone(ZoneId.of("UTC")))
+                .fixedInterval(DateHistogramInterval.seconds(60 * 60 * 24)).timeZone(ZoneId.of("UTC")))
             .addDocValueField("date")
             .get();
         assertSearchResponse(r);
@@ -1624,7 +1611,7 @@ public class DateHistogramIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                                           .addAggregation(dateHistogram("histo")
                                               .field("date")
-                                              .dateHistogramInterval(DateHistogramInterval.MONTH)
+                                              .calendarInterval(DateHistogramInterval.MONTH)
                                               .timeZone(ZoneId.of("America/Edmonton")))
                                           .get();
 

+ 3 - 3
server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java

@@ -77,7 +77,7 @@ public class DateHistogramOffsetIT extends ESIntegTestCase {
                         .field("date")
                         .offset("2h")
                         .format(DATE_FORMAT)
-                        .dateHistogramInterval(DateHistogramInterval.DAY))
+                        .fixedInterval(DateHistogramInterval.DAY))
                 .get();
 
         assertThat(response.getHits().getTotalHits().value, equalTo(5L));
@@ -99,7 +99,7 @@ public class DateHistogramOffsetIT extends ESIntegTestCase {
                         .field("date")
                         .offset("-2h")
                         .format(DATE_FORMAT)
-                        .dateHistogramInterval(DateHistogramInterval.DAY))
+                        .fixedInterval(DateHistogramInterval.DAY))
                 .get();
 
         assertThat(response.getHits().getTotalHits().value, equalTo(5L));
@@ -126,7 +126,7 @@ public class DateHistogramOffsetIT extends ESIntegTestCase {
                         .offset("6h")
                         .minDocCount(0)
                         .format(DATE_FORMAT)
-                        .dateHistogramInterval(DateHistogramInterval.DAY))
+                        .fixedInterval(DateHistogramInterval.DAY))
                 .get();
 
         assertThat(response.getHits().getTotalHits().value, equalTo(24L));

+ 2 - 2
server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/MinDocCountIT.java

@@ -391,7 +391,7 @@ public class MinDocCountIT extends AbstractTermsTestCase {
                 .addAggregation(
                         dateHistogram("histo")
                                 .field("date")
-                                .dateHistogramInterval(DateHistogramInterval.DAY)
+                                .fixedInterval(DateHistogramInterval.DAY)
                                 .order(order)
                                 .minDocCount(0))
                 .get();
@@ -405,7 +405,7 @@ public class MinDocCountIT extends AbstractTermsTestCase {
                     .addAggregation(
                             dateHistogram("histo")
                                     .field("date")
-                                    .dateHistogramInterval(DateHistogramInterval.DAY)
+                                    .fixedInterval(DateHistogramInterval.DAY)
                                     .order(order)
                                     .minDocCount(minDocCount))
                     .get();

+ 16 - 16
server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/ShardReduceIT.java

@@ -82,7 +82,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(global("global")
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -97,7 +97,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(filter("filter", QueryBuilders.matchAllQuery())
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -112,7 +112,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(missing("missing").field("foobar")
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -130,7 +130,7 @@ public class ShardReduceIT extends ESIntegTestCase {
                         .subAggregation(filter("filter", QueryBuilders.matchAllQuery())
                                 .subAggregation(missing("missing").field("foobar")
                                         .subAggregation(dateHistogram("histo").field("date")
-                                                .dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0)))))
+                                                .fixedInterval(DateHistogramInterval.DAY).minDocCount(0)))))
                 .get();
 
         assertSearchResponse(response);
@@ -146,7 +146,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(nested("nested", "nested")
-                        .subAggregation(dateHistogram("histo").field("nested.date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("nested.date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -162,7 +162,7 @@ public class ShardReduceIT extends ESIntegTestCase {
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(terms("terms").field("term-s")
                         .collectMode(randomFrom(SubAggCollectionMode.values()))
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -178,7 +178,7 @@ public class ShardReduceIT extends ESIntegTestCase {
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(terms("terms").field("term-l")
                         .collectMode(randomFrom(SubAggCollectionMode.values()))
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -194,7 +194,7 @@ public class ShardReduceIT extends ESIntegTestCase {
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(terms("terms").field("term-d")
                         .collectMode(randomFrom(SubAggCollectionMode.values()))
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -209,7 +209,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(range("range").field("value").addRange("r1", 0, 10)
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -224,7 +224,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(dateRange("range").field("date").addRange("r1", "2014-01-01", "2014-01-10")
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -239,7 +239,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(ipRange("range").field("ip").addRange("r1", "10.0.0.1", "10.0.0.10")
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -254,7 +254,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(histogram("topHisto").field("value").interval(5)
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -268,8 +268,8 @@ public class ShardReduceIT extends ESIntegTestCase {
     public void testDateHistogram() throws Exception {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
-                .addAggregation(dateHistogram("topHisto").field("date").dateHistogramInterval(DateHistogramInterval.MONTH)
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                .addAggregation(dateHistogram("topHisto").field("date").calendarInterval(DateHistogramInterval.MONTH)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -285,7 +285,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(geohashGrid("grid").field("location")
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 
@@ -300,7 +300,7 @@ public class ShardReduceIT extends ESIntegTestCase {
         SearchResponse response = client().prepareSearch("idx")
                 .setQuery(QueryBuilders.matchAllQuery())
                 .addAggregation(geotileGrid("grid").field("location")
-                        .subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                        .subAggregation(dateHistogram("histo").field("date").fixedInterval(DateHistogramInterval.DAY)
                                 .minDocCount(0)))
                 .get();
 

+ 6 - 5
server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/pipeline/BucketSortIT.java

@@ -14,6 +14,7 @@ import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
 import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
 import org.elasticsearch.search.aggregations.metrics.Avg;
@@ -111,7 +112,7 @@ public class BucketSortIT extends ESIntegTestCase {
     public void testEmptyBucketSort() {
         SearchResponse response = client().prepareSearch(INDEX)
                 .setSize(0)
-                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).interval(TimeValue.timeValueHours(1).millis()))
+                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).fixedInterval(DateHistogramInterval.HOUR))
                 .get();
 
         assertSearchResponse(response);
@@ -129,7 +130,7 @@ public class BucketSortIT extends ESIntegTestCase {
         // Now let's test using size
         response = client().prepareSearch(INDEX)
                 .setSize(0)
-                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).interval(TimeValue.timeValueHours(1).millis())
+                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).fixedInterval(DateHistogramInterval.HOUR)
                         .subAggregation(bucketSort("bucketSort", Collections.emptyList()).size(3)))
                 .get();
 
@@ -146,7 +147,7 @@ public class BucketSortIT extends ESIntegTestCase {
         // Finally, let's test using size + from
         response = client().prepareSearch(INDEX)
                 .setSize(0)
-                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).interval(TimeValue.timeValueHours(1).millis())
+                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).fixedInterval(DateHistogramInterval.HOUR)
                         .subAggregation(bucketSort("bucketSort", Collections.emptyList()).size(3).from(2)))
                 .get();
 
@@ -294,7 +295,7 @@ public class BucketSortIT extends ESIntegTestCase {
 
     public void testSortDateHistogramDescending() {
         SearchResponse response = client().prepareSearch(INDEX)
-                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).interval(TimeValue.timeValueHours(1).millis()))
+                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).fixedInterval(DateHistogramInterval.HOUR))
                 .get();
 
         assertSearchResponse(response);
@@ -305,7 +306,7 @@ public class BucketSortIT extends ESIntegTestCase {
         List<? extends Histogram.Bucket> ascendingTimeBuckets = histo.getBuckets();
 
         response = client().prepareSearch(INDEX)
-                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).interval(TimeValue.timeValueHours(1).millis())
+                .addAggregation(dateHistogram("time_buckets").field(TIME_FIELD).fixedInterval(DateHistogramInterval.HOUR)
                         .subAggregation(bucketSort("bucketSort", Arrays.asList(
                                 new FieldSortBuilder("_key").order(SortOrder.DESC)))))
                 .get();

+ 9 - 9
server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/pipeline/DateDerivativeIT.java

@@ -97,7 +97,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
         SearchResponse response = client()
                 .prepareSearch("idx")
                 .addAggregation(
-                        dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0)
+                        dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH).minDocCount(0)
                                 .subAggregation(derivative("deriv", "_count"))).get();
 
         assertSearchResponse(response);
@@ -139,7 +139,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
         SearchResponse response = client()
                 .prepareSearch("idx")
                 .addAggregation(
-                        dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0)
+                        dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH).minDocCount(0)
                                 .subAggregation(derivative("deriv", "_count").unit(DateHistogramInterval.DAY))).get();
 
         assertSearchResponse(response);
@@ -199,7 +199,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
 
         SearchResponse response = client()
                 .prepareSearch(IDX_DST_START)
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.DAY)
                         .timeZone(timezone).minDocCount(0)
                         .subAggregation(derivative("deriv", "_count").unit(DateHistogramInterval.HOUR)))
                 .get();
@@ -250,7 +250,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
 
         SearchResponse response = client()
                 .prepareSearch(IDX_DST_END)
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.DAY)
                         .timeZone(timezone).minDocCount(0)
                         .subAggregation(derivative("deriv", "_count").unit(DateHistogramInterval.HOUR)))
                 .get();
@@ -303,7 +303,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
 
         SearchResponse response = client()
                 .prepareSearch(IDX_DST_KATHMANDU)
-                .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.HOUR)
+                .addAggregation(dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.HOUR)
                         .timeZone(timezone).minDocCount(0)
                         .subAggregation(derivative("deriv", "_count").unit(DateHistogramInterval.MINUTE)))
                 .get();
@@ -359,7 +359,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
         SearchResponse response = client()
                 .prepareSearch("idx")
                 .addAggregation(
-                        dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0)
+                        dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH).minDocCount(0)
                             .subAggregation(sum("sum").field("value")).subAggregation(derivative("deriv", "sum")))
                 .get();
 
@@ -430,7 +430,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
         SearchResponse response = client()
                 .prepareSearch("idx")
                 .addAggregation(
-                        dateHistogram("histo").field("dates").dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0)
+                        dateHistogram("histo").field("dates").calendarInterval(DateHistogramInterval.MONTH).minDocCount(0)
                                 .subAggregation(derivative("deriv", "_count"))).get();
 
         assertSearchResponse(response);
@@ -485,7 +485,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
         SearchResponse response = client()
                 .prepareSearch("idx_unmapped")
                 .addAggregation(
-                        dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0)
+                        dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH).minDocCount(0)
                                 .subAggregation(derivative("deriv", "_count"))).get();
 
         assertSearchResponse(response);
@@ -500,7 +500,7 @@ public class DateDerivativeIT extends ESIntegTestCase {
         SearchResponse response = client()
                 .prepareSearch("idx", "idx_unmapped")
                 .addAggregation(
-                        dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.MONTH).minDocCount(0)
+                        dateHistogram("histo").field("date").calendarInterval(DateHistogramInterval.MONTH).minDocCount(0)
                                 .subAggregation(derivative("deriv", "_count"))).get();
 
         assertSearchResponse(response);

+ 1 - 1
server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/pipeline/MaxBucketIT.java

@@ -517,7 +517,7 @@ public class MaxBucketIT extends ESIntegTestCase {
             PipelineAggregatorBuilders.maxBucket("peak", "licenses_per_day>total_licenses");
         SumAggregationBuilder sumAggBuilder = AggregationBuilders.sum("total_licenses").field("license.count");
         DateHistogramAggregationBuilder licensePerDayBuilder =
-            AggregationBuilders.dateHistogram("licenses_per_day").field("@timestamp").dateHistogramInterval(DateHistogramInterval.DAY);
+            AggregationBuilders.dateHistogram("licenses_per_day").field("@timestamp").fixedInterval(DateHistogramInterval.DAY);
         licensePerDayBuilder.subAggregation(sumAggBuilder);
         groupByLicenseAgg.subAggregation(licensePerDayBuilder);
         groupByLicenseAgg.subAggregation(peakPipelineAggBuilder);

+ 0 - 40
server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/DateHistogramValuesSourceBuilder.java

@@ -142,46 +142,6 @@ public class DateHistogramValuesSourceBuilder
         return TYPE;
     }
 
-    /**
-     * Returns the interval in milliseconds that is set on this source
-     **/
-    @Deprecated
-    public long interval() {
-        return dateHistogramInterval.interval();
-    }
-
-    /**
-     * Sets the interval on this source.
-     * If both {@link #interval()} and {@link #dateHistogramInterval()} are set,
-     * then the {@link #dateHistogramInterval()} wins.
-     *
-     * @deprecated Use {@link #calendarInterval(DateHistogramInterval)} or {@link #fixedInterval(DateHistogramInterval)} instead
-     * @since 7.2.0
-     **/
-    @Deprecated
-    public DateHistogramValuesSourceBuilder interval(long interval) {
-        dateHistogramInterval.interval(interval);
-        return this;
-    }
-
-    /**
-     * Returns the date interval that is set on this source
-     **/
-    @Deprecated
-    public DateHistogramInterval dateHistogramInterval() {
-        return dateHistogramInterval.dateHistogramInterval();
-    }
-
-    /**
-     * @deprecated Use {@link #calendarInterval(DateHistogramInterval)} or {@link #fixedInterval(DateHistogramInterval)} instead
-     * @since 7.2.0
-     */
-    @Deprecated
-    public DateHistogramValuesSourceBuilder dateHistogramInterval(DateHistogramInterval interval) {
-        dateHistogramInterval.dateHistogramInterval(interval);
-        return this;
-    }
-
     /**
      * 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.

+ 0 - 38
server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java

@@ -161,44 +161,6 @@ public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuil
         }
     }
 
-    /** Get the current interval in milliseconds that is set on this builder. */
-    @Deprecated
-    public long interval() {
-        return dateHistogramInterval.interval();
-    }
-
-    /** Set the interval on this builder, and return the builder so that calls can be chained.
-     *  If both {@link #interval()} and {@link #dateHistogramInterval()} are set, then the
-     *  {@link #dateHistogramInterval()} wins.
-     *
-     *  @deprecated use {@link #fixedInterval(DateHistogramInterval)} or {@link #calendarInterval(DateHistogramInterval)} instead
-     *  @since 7.2.0
-     */
-    @Deprecated
-    public DateHistogramAggregationBuilder interval(long interval) {
-        dateHistogramInterval.interval(interval);
-        return this;
-    }
-
-    /** Get the current date interval that is set on this builder. */
-    @Deprecated
-    public DateHistogramInterval dateHistogramInterval() {
-       return dateHistogramInterval.dateHistogramInterval();
-    }
-
-    /** Set the interval on this builder, and return the builder so that calls can be chained.
-     *  If both {@link #interval()} and {@link #dateHistogramInterval()} are set, then the
-     *  {@link #dateHistogramInterval()} wins.
-     *
-     *  @deprecated use {@link #fixedInterval(DateHistogramInterval)} or {@link #calendarInterval(DateHistogramInterval)} instead
-     *  @since 7.2.0
-     */
-    @Deprecated
-    public DateHistogramAggregationBuilder dateHistogramInterval(DateHistogramInterval interval) {
-        dateHistogramInterval.dateHistogramInterval(interval);
-        return this;
-    }
-
     /**
      * 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.

+ 0 - 9
server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalConsumer.java

@@ -15,15 +15,6 @@ package org.elasticsearch.search.aggregations.bucket.histogram;
  * defintions for the old interval/dateHisto interval parameters
  */
 public interface DateIntervalConsumer<T> {
-    @Deprecated
-    T interval(long interval);
-    @Deprecated
-    T dateHistogramInterval(DateHistogramInterval dateHistogramInterval);
     T calendarInterval(DateHistogramInterval interval);
     T fixedInterval(DateHistogramInterval interval);
-
-    @Deprecated
-    long interval();
-    @Deprecated
-    DateHistogramInterval dateHistogramInterval();
 }

+ 59 - 167
server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateIntervalWrapper.java

@@ -8,8 +8,6 @@
 
 package org.elasticsearch.search.aggregations.bucket.histogram;
 
-import org.elasticsearch.Version;
-import org.elasticsearch.common.xcontent.ParseField;
 import org.elasticsearch.common.Rounding;
 import org.elasticsearch.common.Rounding.DateTimeUnit;
 import org.elasticsearch.common.Strings;
@@ -18,40 +16,48 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Writeable;
 import org.elasticsearch.common.logging.DeprecationCategory;
 import org.elasticsearch.common.logging.DeprecationLogger;
-import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.common.xcontent.ObjectParser;
+import org.elasticsearch.common.xcontent.ParseField;
 import org.elasticsearch.common.xcontent.ToXContentFragment;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.core.RestApiVersion;
+import org.elasticsearch.core.TimeValue;
 
 import java.io.IOException;
 import java.time.ZoneId;
 import java.util.Locale;
 import java.util.Objects;
 
+import static org.elasticsearch.core.RestApiVersion.equalTo;
+
 /**
  * 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
  */
 public class DateIntervalWrapper implements ToXContentFragment, Writeable {
     private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(DateHistogramAggregationBuilder.class);
     private static final String DEPRECATION_TEXT = "[interval] on [date_histogram] is deprecated, use [fixed_interval] or " +
         "[calendar_interval] in the future.";
-
     private static final ParseField FIXED_INTERVAL_FIELD = new ParseField("fixed_interval");
     private static final ParseField CALENDAR_INTERVAL_FIELD = new ParseField("calendar_interval");
 
     public enum IntervalTypeEnum implements Writeable {
-        NONE, FIXED, CALENDAR, LEGACY_INTERVAL, LEGACY_DATE_HISTO;
+        /*
+         LEGACY_INTERVAL and LEGACY_DATE_HISTO are no longer used, but since this is a writeable enum, I'm leaving them
+         to hold the ordinal places for now.
+         */
+
+        NONE("none"),
+        FIXED(FIXED_INTERVAL_FIELD.getPreferredName()),
+        CALENDAR(CALENDAR_INTERVAL_FIELD.getPreferredName()),
+        @Deprecated
+        LEGACY_INTERVAL(null),
+        @Deprecated
+        LEGACY_DATE_HISTO(null);
 
         public static IntervalTypeEnum fromString(String name) {
             return valueOf(name.trim().toUpperCase(Locale.ROOT));
@@ -69,19 +75,43 @@ public class DateIntervalWrapper implements ToXContentFragment, Writeable {
         public String value() {
             return name().toLowerCase(Locale.ROOT);
         }
+
+        public boolean isValid() {
+            // I'm being a little cheeky here and just reusing the name for signaling invlaid choices too
+            return this.preferredName != null;
+        }
+
+        public String getPreferredName() {
+            if (preferredName == null) {
+                throw new IllegalStateException("Invalid use of legacy date histogram interval");
+            }
+            return preferredName;
+        }
+
+        private String preferredName;
+        IntervalTypeEnum(String preferredName) {
+            this.preferredName = preferredName;
+        }
     }
 
     private DateHistogramInterval dateHistogramInterval;
     private IntervalTypeEnum intervalType = IntervalTypeEnum.NONE;
 
     public static <T extends DateIntervalConsumer> void declareIntervalFields(ObjectParser<T, String> parser) {
-
-        // NOTE: this field is deprecated and will be removed
+        /*
+         REST version compatibility.  When in V_7 compatibility mode, continue to parse the old style interval parameter,
+         but immediately adapt it into either fixed or calendar interval.
+         */
         parser.declareField((wrapper, interval) -> {
+            DEPRECATION_LOGGER.deprecate(DeprecationCategory.AGGREGATIONS, "date-interval-getter", DEPRECATION_TEXT);
             if (interval instanceof Long) {
-                wrapper.interval((long) interval);
+                wrapper.fixedInterval(new DateHistogramInterval(interval + "ms"));
             } else {
-                wrapper.dateHistogramInterval((DateHistogramInterval) interval);
+                if (interval != null && DateHistogramAggregationBuilder.DATE_FIELD_UNITS.containsKey(interval.toString())) {
+                    wrapper.calendarInterval((DateHistogramInterval) interval);
+                } else {
+                    wrapper.fixedInterval((DateHistogramInterval) interval);
+                }
             }
         }, p -> {
             if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) {
@@ -89,7 +119,7 @@ public class DateIntervalWrapper implements ToXContentFragment, Writeable {
             } else {
                 return new DateHistogramInterval(p.text());
             }
-        }, Histogram.INTERVAL_FIELD, ObjectParser.ValueType.LONG);
+        }, Histogram.INTERVAL_FIELD.forRestApiVersion(equalTo(RestApiVersion.V_7)), ObjectParser.ValueType.LONG);
 
         parser.declareField(DateIntervalConsumer::calendarInterval,
             p -> new DateHistogramInterval(p.text()), CALENDAR_INTERVAL_FIELD, ObjectParser.ValueType.STRING);
@@ -101,89 +131,20 @@ public class DateIntervalWrapper implements ToXContentFragment, Writeable {
     public DateIntervalWrapper() {}
 
     public DateIntervalWrapper(StreamInput in) throws IOException {
-        if (in.getVersion().before(Version.V_7_2_0)) {
-            long interval = in.readLong();
-            DateHistogramInterval histoInterval = in.readOptionalWriteable(DateHistogramInterval::new);
-
-            if (histoInterval != null) {
-                dateHistogramInterval = histoInterval;
-                intervalType = IntervalTypeEnum.LEGACY_DATE_HISTO;
-            } else {
-                dateHistogramInterval = new DateHistogramInterval(interval + "ms");
-                intervalType = IntervalTypeEnum.LEGACY_INTERVAL;
-            }
-        } else {
-            dateHistogramInterval = in.readOptionalWriteable(DateHistogramInterval::new);
-            intervalType = IntervalTypeEnum.fromStream(in);
-        }
+        dateHistogramInterval = in.readOptionalWriteable(DateHistogramInterval::new);
+        intervalType = IntervalTypeEnum.fromStream(in);
     }
 
     public IntervalTypeEnum getIntervalType() {
         return intervalType;
     }
 
-    /** Get the current interval in milliseconds that is set on this builder. */
-    @Deprecated
-    public long interval() {
-        DEPRECATION_LOGGER.deprecate(DeprecationCategory.AGGREGATIONS, "date-interval-getter", DEPRECATION_TEXT);
-        if (intervalType.equals(IntervalTypeEnum.LEGACY_INTERVAL)) {
-            return TimeValue.parseTimeValue(dateHistogramInterval.toString(), "interval").getMillis();
-        }
-        return 0;
-    }
-
-    /** Set the interval on this builder, and return the builder so that calls can be chained.
-     *  If both {@link #interval()} and {@link #dateHistogramInterval()} are set, then the
-     *  {@link #dateHistogramInterval()} wins.
-     *
-     *  @deprecated use {@link DateHistogramAggregationBuilder#fixedInterval(DateHistogramInterval)}
-     *              or {@link DateHistogramAggregationBuilder#calendarInterval(DateHistogramInterval)} instead
-     *  @since 7.2.0
-     */
-    @Deprecated
-    public void interval(long interval) {
-        if (interval < 1) {
-            throw new IllegalArgumentException("[interval] must be 1 or greater for aggregation [date_histogram]");
-        }
-        setIntervalType(IntervalTypeEnum.LEGACY_INTERVAL);
-        DEPRECATION_LOGGER.deprecate(DeprecationCategory.AGGREGATIONS, "date-interval-setter", DEPRECATION_TEXT);
-        this.dateHistogramInterval = new DateHistogramInterval(interval + "ms");
-    }
-
-    /** Get the current date interval that is set on this builder. */
-    @Deprecated
-    public DateHistogramInterval dateHistogramInterval() {
-        DEPRECATION_LOGGER.deprecate(DeprecationCategory.AGGREGATIONS, "date-histogram-interval-getter", DEPRECATION_TEXT);
-        if (intervalType.equals(IntervalTypeEnum.LEGACY_DATE_HISTO)) {
-            return dateHistogramInterval;
-        }
-        return null;
-    }
-
-    /** Set the interval on this builder, and return the builder so that calls can be chained.
-     *  If both {@link #interval()} and {@link #dateHistogramInterval()} are set, then the
-     *  {@link #dateHistogramInterval()} wins.
-     *
-     *  @deprecated use {@link DateIntervalWrapper#fixedInterval(DateHistogramInterval)}
-     *              or {@link DateIntervalWrapper#calendarInterval(DateHistogramInterval)} instead
-     *  @since 7.2.0
-     */
-    @Deprecated
-    public void dateHistogramInterval(DateHistogramInterval dateHistogramInterval) {
-        if (dateHistogramInterval == null || Strings.isNullOrEmpty(dateHistogramInterval.toString())) {
-            throw new IllegalArgumentException("[dateHistogramInterval] must not be null: [date_histogram]");
-        }
-        setIntervalType(IntervalTypeEnum.LEGACY_DATE_HISTO);
-        DEPRECATION_LOGGER.deprecate(DeprecationCategory.AGGREGATIONS, "date-histogram-interval-setter", DEPRECATION_TEXT);
-        this.dateHistogramInterval = dateHistogramInterval;
-    }
-
     /**
      * Returns the interval as a calendar interval.  Throws an exception if the value cannot be converted
      * into a calendar interval
      */
     public DateHistogramInterval getAsCalendarInterval() {
-        if (intervalType.equals(IntervalTypeEnum.CALENDAR) || tryIntervalAsCalendarUnit() != null) {
+        if (intervalType.equals(IntervalTypeEnum.CALENDAR)) {
             return dateHistogramInterval;
         }
         throw new IllegalStateException("Cannot convert [" + intervalType.toString() + "] interval type into calendar interval");
@@ -242,7 +203,7 @@ public class DateIntervalWrapper implements ToXContentFragment, Writeable {
      *  {@code null} then it means that the interval is expressed as a fixed
      *  {@link TimeValue} and may be accessed via {@link #tryIntervalAsFixedUnit()}. */
     DateTimeUnit tryIntervalAsCalendarUnit() {
-        if (intervalType.equals(IntervalTypeEnum.CALENDAR) || intervalType.equals(IntervalTypeEnum.LEGACY_DATE_HISTO)) {
+        if (intervalType.equals(IntervalTypeEnum.CALENDAR)) {
             return DateHistogramAggregationBuilder.DATE_FIELD_UNITS.get(dateHistogramInterval.toString());
         }
         return null;
@@ -274,18 +235,8 @@ public class DateIntervalWrapper implements ToXContentFragment, Writeable {
         } else if (intervalType.equals(DateIntervalWrapper.IntervalTypeEnum.CALENDAR)) {
             tzRoundingBuilder = Rounding.builder(tryIntervalAsCalendarUnit());
         } else {
-            // We're not sure what the interval was originally (legacy) so use old behavior of assuming
-            // calendar first, then fixed.  Required because fixed/cal overlap in places ("1h")
-            DateTimeUnit calInterval = tryIntervalAsCalendarUnit();
-            TimeValue fixedInterval = tryIntervalAsFixedUnit();
-            if (calInterval != null) {
-                tzRoundingBuilder = Rounding.builder(calInterval);
-            } else if (fixedInterval != null) {
-                tzRoundingBuilder = Rounding.builder(fixedInterval);
-            } else {
-                // If we get here we have exhausted our options and are not able to parse this interval
-                throw new IllegalArgumentException("Unable to parse interval [" + dateHistogramInterval + "]");
-            }
+            // If we get here we have exhausted our options and are not able to parse this interval
+            throw new IllegalArgumentException("Unable to parse interval [" + dateHistogramInterval + "]");
         }
         if (timeZone != null) {
             tzRoundingBuilder.timeZone(timeZone);
@@ -300,58 +251,11 @@ public class DateIntervalWrapper implements ToXContentFragment, Writeable {
             intervalType = type;
             return;
         }
-
-        // interval() method
-        switch (type) {
-            case LEGACY_INTERVAL:
-                if (intervalType.equals(IntervalTypeEnum.CALENDAR) || intervalType.equals(IntervalTypeEnum.FIXED)) {
-                    throw new IllegalArgumentException("Cannot use [interval] with [fixed_interval] or [calendar_interval] " +
-                        "configuration options.");
-                }
-
-                // dateHistogramInterval() takes precedence over interval()
-                if (intervalType.equals(IntervalTypeEnum.LEGACY_DATE_HISTO) == false) {
-                    intervalType = IntervalTypeEnum.LEGACY_INTERVAL;
-                }
-                break;
-
-            case LEGACY_DATE_HISTO:
-                if (intervalType.equals(IntervalTypeEnum.CALENDAR) || intervalType.equals(IntervalTypeEnum.FIXED)) {
-                    throw new IllegalArgumentException("Cannot use [interval] with [fixed_interval] or [calendar_interval] " +
-                        "configuration options.");
-                }
-
-                // dateHistogramInterval() takes precedence over interval()
-                intervalType = IntervalTypeEnum.LEGACY_DATE_HISTO;
-                break;
-
-            case FIXED:
-                if (intervalType.equals(IntervalTypeEnum.LEGACY_INTERVAL) || intervalType.equals(IntervalTypeEnum.LEGACY_DATE_HISTO)) {
-                    throw new IllegalArgumentException("Cannot use [fixed_interval] with [interval] " +
-                        "configuration option.");
-                }
-                if (intervalType.equals(IntervalTypeEnum.CALENDAR)) {
-                    throw new IllegalArgumentException("Cannot use [fixed_interval] with [calendar_interval] " +
-                        "configuration option.");
-                }
-                intervalType = IntervalTypeEnum.FIXED;
-                break;
-
-            case CALENDAR:
-                if (intervalType.equals(IntervalTypeEnum.LEGACY_INTERVAL) || intervalType.equals(IntervalTypeEnum.LEGACY_DATE_HISTO)) {
-                    throw new IllegalArgumentException("Cannot use [calendar_interval] with [interval] " +
-                        "configuration option.");
-                }
-                if (intervalType.equals(IntervalTypeEnum.FIXED)) {
-                    throw new IllegalArgumentException("Cannot use [calendar_interval] with [fixed_interval] " +
-                        "configuration option.");
-                }
-                intervalType = IntervalTypeEnum.CALENDAR;
-                break;
-
-            default:
-                throw new IllegalStateException("Unknown interval type.");
+        if (type.isValid() == false || intervalType.isValid() == false) {
+            throw new IllegalArgumentException("Unknown interval type.");
         }
+        throw new IllegalArgumentException("Cannot use [" + type.getPreferredName() + "] with [" + intervalType.getPreferredName() +
+            "] configuration option.");
     }
 
     public boolean isEmpty() {
@@ -363,25 +267,13 @@ public class DateIntervalWrapper implements ToXContentFragment, Writeable {
 
     @Override
     public void writeTo(StreamOutput out) throws IOException {
-        if (out.getVersion().before(Version.V_7_2_0)) {
-            if (intervalType.equals(IntervalTypeEnum.LEGACY_INTERVAL)) {
-                out.writeLong(TimeValue.parseTimeValue(dateHistogramInterval.toString(),
-                    DateHistogramAggregationBuilder.NAME + ".innerWriteTo").getMillis());
-            } else {
-                out.writeLong(0L);
-            }
-            out.writeOptionalWriteable(dateHistogramInterval);
-        } else {
-            out.writeOptionalWriteable(dateHistogramInterval);
-            intervalType.writeTo(out);
-        }
+        out.writeOptionalWriteable(dateHistogramInterval);
+        intervalType.writeTo(out);
     }
 
     @Override
     public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
-        if (intervalType.equals(IntervalTypeEnum.LEGACY_DATE_HISTO) || intervalType.equals(IntervalTypeEnum.LEGACY_INTERVAL)) {
-            builder.field(Histogram.INTERVAL_FIELD.getPreferredName(), dateHistogramInterval.toString());
-        } else if (intervalType.equals(IntervalTypeEnum.FIXED)){
+        if (intervalType.equals(IntervalTypeEnum.FIXED)){
             builder.field(FIXED_INTERVAL_FIELD.getPreferredName(), dateHistogramInterval.toString());
         } else if (intervalType.equals(IntervalTypeEnum.CALENDAR)) {
             builder.field(CALENDAR_INTERVAL_FIELD.getPreferredName(), dateHistogramInterval.toString());

+ 8 - 15
server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregatorTests.java

@@ -1695,7 +1695,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
             () -> {
                 DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date")
                     .field("date")
-                    .dateHistogramInterval(DateHistogramInterval.days(1))
+                    .fixedInterval(DateHistogramInterval.days(1))
                     .format("yyyy-MM-dd");
                 return new CompositeAggregationBuilder("name", Collections.singletonList(histo));
             },
@@ -1715,7 +1715,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
             () -> {
                 DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date")
                     .field("date")
-                    .dateHistogramInterval(DateHistogramInterval.days(1))
+                    .fixedInterval(DateHistogramInterval.days(1))
                     .format("yyyy-MM-dd");
                 return new CompositeAggregationBuilder("name", Collections.singletonList(histo))
                     .aggregateAfter(createAfterKey("date", "2016-09-20"));
@@ -1729,8 +1729,6 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                 assertEquals(2L, result.getBuckets().get(1).getDocCount());
             }
         );
-
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
     }
 
     public void testThatDateHistogramFailsFormatAfter() throws IOException {
@@ -1739,7 +1737,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                 () -> {
                     DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.days(1))
+                        .fixedInterval(DateHistogramInterval.days(1))
                         .format("yyyy-MM-dd");
                     return new CompositeAggregationBuilder("name", Collections.singletonList(histo))
                         .aggregateAfter(createAfterKey("date", "now"));
@@ -1755,7 +1753,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                 () -> {
                     DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date")
                         .field("date")
-                        .dateHistogramInterval(DateHistogramInterval.days(1))
+                        .fixedInterval(DateHistogramInterval.days(1))
                         .format("yyyy-MM-dd");
                     return new CompositeAggregationBuilder("name", Collections.singletonList(histo))
                         .aggregateAfter(createAfterKey("date", "1474329600000"));
@@ -1764,7 +1762,6 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                 }
             ));
         assertThat(exc.getMessage(), containsString("failed to parse date field [1474329600000]"));
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
     }
 
     public void testWithDateHistogramAndKeyword() throws IOException {
@@ -1790,7 +1787,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                     Arrays.asList(
                         new DateHistogramValuesSourceBuilder("date")
                             .field("date")
-                            .dateHistogramInterval(DateHistogramInterval.days(1)),
+                            .fixedInterval(DateHistogramInterval.days(1)),
                         new TermsValuesSourceBuilder("keyword")
                             .field("keyword")
                     )
@@ -1826,7 +1823,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                     Arrays.asList(
                         new DateHistogramValuesSourceBuilder("date")
                             .field("date")
-                            .dateHistogramInterval(DateHistogramInterval.days(1)),
+                            .fixedInterval(DateHistogramInterval.days(1)),
                         new TermsValuesSourceBuilder("keyword")
                             .field("keyword")
                     )
@@ -1842,8 +1839,6 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                 assertEquals(1L, result.getBuckets().get(2).getDocCount());
             }
         );
-
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
     }
 
     public void testWithKeywordAndHistogram() throws IOException {
@@ -1995,7 +1990,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                     Arrays.asList(
                         new TermsValuesSourceBuilder("keyword").field("keyword"),
                         new DateHistogramValuesSourceBuilder("date_histo").field("date")
-                            .dateHistogramInterval(DateHistogramInterval.days(1))
+                            .fixedInterval(DateHistogramInterval.days(1))
                     )
                 )
             , (result) -> {
@@ -2024,7 +2019,7 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                     Arrays.asList(
                         new TermsValuesSourceBuilder("keyword").field("keyword"),
                         new DateHistogramValuesSourceBuilder("date_histo").field("date")
-                            .dateHistogramInterval(DateHistogramInterval.days(1))
+                            .fixedInterval(DateHistogramInterval.days(1))
                     )
                 ).aggregateAfter(createAfterKey("keyword", "c", "date_histo", 1474329600000L))
             , (result) -> {
@@ -2040,8 +2035,6 @@ public class CompositeAggregatorTests  extends AggregatorTestCase {
                 assertEquals(1L, result.getBuckets().get(3).getDocCount());
             }
         );
-
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
     }
 
     public void testWithKeywordAndTopHits() throws Exception {

+ 0 - 144
server/src/test/java/org/elasticsearch/search/aggregations/bucket/composite/LegacyIntervalCompositeAggBuilderTests.java

@@ -1,144 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
- * in compliance with, at your election, the Elastic License 2.0 or the Server
- * Side Public License, v 1.
- */
-
-package org.elasticsearch.search.aggregations.bucket.composite;
-
-import org.elasticsearch.script.Script;
-import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
-import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
-import org.elasticsearch.search.sort.SortOrder;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Duplicates the tests from {@link CompositeAggregationBuilderTests}, except using the deprecated
- * interval on date histo.  Separated to make testing the warnings easier.
- *
- * Can be removed in when the legacy interval options are gone
- */
-public class LegacyIntervalCompositeAggBuilderTests extends BaseAggregationTestCase<CompositeAggregationBuilder> {
-
-    private DateHistogramValuesSourceBuilder randomDateHistogramSourceBuilder() {
-        DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10));
-        if (randomBoolean()) {
-            histo.field(randomAlphaOfLengthBetween(1, 20));
-        } else {
-            histo.script(new Script(randomAlphaOfLengthBetween(10, 20)));
-        }
-        if (randomBoolean()) {
-            histo.dateHistogramInterval(randomFrom(DateHistogramInterval.days(1),
-                DateHistogramInterval.minutes(1), DateHistogramInterval.weeks(1)));
-        } else {
-            histo.interval(randomNonNegativeLong());
-        }
-        if (randomBoolean()) {
-            histo.timeZone(randomZone());
-        }
-        if (randomBoolean()) {
-            histo.missingBucket(true);
-        }
-        return histo;
-    }
-
-    private TermsValuesSourceBuilder randomTermsSourceBuilder() {
-        TermsValuesSourceBuilder terms = new TermsValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10));
-        if (randomBoolean()) {
-            terms.field(randomAlphaOfLengthBetween(1, 20));
-        } else {
-            terms.script(new Script(randomAlphaOfLengthBetween(10, 20)));
-        }
-        terms.order(randomFrom(SortOrder.values()));
-        if (randomBoolean()) {
-            terms.missingBucket(true);
-        }
-        return terms;
-    }
-
-    private HistogramValuesSourceBuilder randomHistogramSourceBuilder() {
-        HistogramValuesSourceBuilder histo = new HistogramValuesSourceBuilder(randomAlphaOfLengthBetween(5, 10));
-        if (randomBoolean()) {
-            histo.field(randomAlphaOfLengthBetween(1, 20));
-        } else {
-            histo.script(new Script(randomAlphaOfLengthBetween(10, 20)));
-        }
-        if (randomBoolean()) {
-            histo.missingBucket(true);
-        }
-        histo.interval(randomDoubleBetween(Math.nextUp(0), Double.MAX_VALUE, false));
-        return histo;
-    }
-
-    @Override
-    protected CompositeAggregationBuilder createTestAggregatorBuilder() {
-        int numSources = randomIntBetween(1, 10);
-        List<CompositeValuesSourceBuilder<?>> sources = new ArrayList<>();
-        // ensure we add at least one date histo
-        sources.add(randomDateHistogramSourceBuilder());
-        for (int i = 0; i < numSources; i++) {
-            int type = randomIntBetween(0, 2);
-            switch (type) {
-                case 0:
-                    sources.add(randomTermsSourceBuilder());
-                    break;
-                case 1:
-                    sources.add(randomDateHistogramSourceBuilder());
-                    break;
-                case 2:
-                    sources.add(randomHistogramSourceBuilder());
-                    break;
-                default:
-                    throw new AssertionError("wrong branch");
-            }
-        }
-        return new CompositeAggregationBuilder(randomAlphaOfLength(10), sources);
-    }
-
-    @Override
-    public void testFromXContent() throws IOException {
-        super.testFromXContent();
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
-    @Override
-    public void testFromXContentMulti() throws IOException {
-        super.testFromXContentMulti();
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
-    @Override
-    public void testSerializationMulti() throws IOException {
-        super.testSerializationMulti();
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
-    @Override
-    public void testToString() throws IOException {
-        super.testToString();
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
-    @Override
-    public void testSerialization() throws IOException {
-        super.testSerialization();
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
-    @Override
-    public void testEqualsAndHashcode() throws IOException {
-        super.testEqualsAndHashcode();
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
-    @Override
-    public void testShallowCopy() {
-        super.testShallowCopy();
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-}

+ 29 - 451
server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorTests.java

@@ -35,7 +35,6 @@ import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
 import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.PipelineTree;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
-import org.elasticsearch.search.aggregations.support.AggregationInspectionHelper;
 import org.hamcrest.Matcher;
 
 import java.io.IOException;
@@ -75,17 +74,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
             "2016-03-04T17:09:50",
             "2017-12-12T22:55:46");
 
-    public void testMatchNoDocsDeprecatedInterval() throws IOException {
-        testSearchCase(new MatchNoDocsQuery(), DATASET,
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(AGGREGABLE_DATE),
-                histogram -> {
-                    assertEquals(0, histogram.getBuckets().size());
-                    assertFalse(AggregationInspectionHelper.hasValue(histogram));
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testBooleanFieldDeprecated() throws IOException {
         final String fieldName = "bogusBoolean";
         testCase(
@@ -113,26 +101,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testMatchAllDocsDeprecatedInterval() throws IOException {
-        Query query = new MatchAllDocsQuery();
-
-        testSearchCase(query, DATASET,
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(AGGREGABLE_DATE),
-                histogram -> {
-                    assertEquals(8, histogram.getBuckets().size());
-                    assertTrue(AggregationInspectionHelper.hasValue(histogram));
-                }, false
-        );
-        testSearchCase(query, DATASET,
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(AGGREGABLE_DATE).minDocCount(1L),
-                histogram -> {
-                    assertEquals(6, histogram.getBuckets().size());
-                    assertTrue(AggregationInspectionHelper.hasValue(histogram));
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testMatchAllDocs() throws IOException {
         Query query = new MatchAllDocsQuery();
 
@@ -206,23 +174,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         });
     }
 
-    public void testNoDocsDeprecatedInterval() throws IOException {
-        Query query = new MatchNoDocsQuery();
-        List<String> dates = Collections.emptyList();
-        Consumer<DateHistogramAggregationBuilder> aggregation =
-            agg -> agg.dateHistogramInterval(DateHistogramInterval.YEAR).field(AGGREGABLE_DATE);
-
-        testSearchCase(query, dates, aggregation, histogram -> {
-            assertEquals(0, histogram.getBuckets().size());
-            assertFalse(AggregationInspectionHelper.hasValue(histogram));
-        }, false);
-        testSearchCase(query, dates, aggregation, histogram -> {
-            assertEquals(0, histogram.getBuckets().size());
-            assertFalse(AggregationInspectionHelper.hasValue(histogram));
-        }, false);
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testNoDocs() throws IOException {
         Query query = new MatchNoDocsQuery();
         List<String> dates = Collections.emptyList();
@@ -245,17 +196,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testAggregateWrongFieldDeprecated() throws IOException {
-        testSearchCase(new MatchAllDocsQuery(), DATASET,
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field("wrong_field"),
-                histogram -> {
-                    assertEquals(0, histogram.getBuckets().size());
-                    assertFalse(AggregationInspectionHelper.hasValue(histogram));
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testAggregateWrongField() throws IOException {
         testSearchCase(new MatchAllDocsQuery(), DATASET,
             aggregation -> aggregation.calendarInterval(DateHistogramInterval.YEAR).field("wrong_field"),
@@ -267,29 +207,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testIntervalYearDeprecated() throws IOException {
-        testSearchCase(LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2015-01-01"), asLong("2017-12-31")), DATASET,
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(AGGREGABLE_DATE),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(3, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2015-01-01T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(3, bucket.getDocCount());
-
-                    bucket = buckets.get(1);
-                    assertEquals("2016-01-01T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(2);
-                    assertEquals("2017-01-01T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testIntervalYear() throws IOException {
         testSearchCase(LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2015-01-01"), asLong("2017-12-31")), DATASET,
             aggregation -> aggregation.calendarInterval(DateHistogramInterval.YEAR).field(AGGREGABLE_DATE),
@@ -312,30 +229,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testIntervalMonthDeprecated() throws IOException {
-        testSearchCase(new MatchAllDocsQuery(),
-                Arrays.asList("2017-01-01", "2017-02-02", "2017-02-03", "2017-03-04", "2017-03-05", "2017-03-06"),
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.MONTH).field(AGGREGABLE_DATE),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(3, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2017-01-01T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(1);
-                    assertEquals("2017-02-01T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(2, bucket.getDocCount());
-
-                    bucket = buckets.get(2);
-                    assertEquals("2017-03-01T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(3, bucket.getDocCount());
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testIntervalMonth() throws IOException {
         testSearchCase(new MatchAllDocsQuery(),
             Arrays.asList("2017-01-01", "2017-02-02", "2017-02-03", "2017-03-04", "2017-03-05", "2017-03-06"),
@@ -359,42 +252,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testIntervalDayDeprecated() throws IOException {
-        testSearchCase(new MatchAllDocsQuery(),
-                Arrays.asList(
-                        "2017-02-01",
-                        "2017-02-02",
-                        "2017-02-02",
-                        "2017-02-03",
-                        "2017-02-03",
-                        "2017-02-03",
-                        "2017-02-05"
-                ),
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.DAY).field(AGGREGABLE_DATE).minDocCount(1L),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(4, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2017-02-01T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(1);
-                    assertEquals("2017-02-02T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(2, bucket.getDocCount());
-
-                    bucket = buckets.get(2);
-                    assertEquals("2017-02-03T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(3, bucket.getDocCount());
-
-                    bucket = buckets.get(3);
-                    assertEquals("2017-02-05T00:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testIntervalDay() throws IOException {
         testSearchCase(new MatchAllDocsQuery(),
             Arrays.asList(
@@ -462,53 +319,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testIntervalHourDeprecated() throws IOException {
-        testSearchCase(new MatchAllDocsQuery(),
-                Arrays.asList(
-                        "2017-02-01T09:02:00.000Z",
-                        "2017-02-01T09:35:00.000Z",
-                        "2017-02-01T10:15:00.000Z",
-                        "2017-02-01T13:06:00.000Z",
-                        "2017-02-01T14:04:00.000Z",
-                        "2017-02-01T14:05:00.000Z",
-                        "2017-02-01T15:59:00.000Z",
-                        "2017-02-01T16:06:00.000Z",
-                        "2017-02-01T16:48:00.000Z",
-                        "2017-02-01T16:59:00.000Z"
-                ),
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.HOUR).field(AGGREGABLE_DATE).minDocCount(1L),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(6, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2017-02-01T09:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(2, bucket.getDocCount());
-
-                    bucket = buckets.get(1);
-                    assertEquals("2017-02-01T10:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(2);
-                    assertEquals("2017-02-01T13:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(3);
-                    assertEquals("2017-02-01T14:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(2, bucket.getDocCount());
-
-                    bucket = buckets.get(4);
-                    assertEquals("2017-02-01T15:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(5);
-                    assertEquals("2017-02-01T16:00:00.000Z", bucket.getKeyAsString());
-                    assertEquals(3, bucket.getDocCount());
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testIntervalHour() throws IOException {
         testSearchCase(new MatchAllDocsQuery(),
             Arrays.asList(
@@ -598,36 +408,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testIntervalMinuteDeprecated() throws IOException {
-        testSearchCase(new MatchAllDocsQuery(),
-                Arrays.asList(
-                        "2017-02-01T09:02:35.000Z",
-                        "2017-02-01T09:02:59.000Z",
-                        "2017-02-01T09:15:37.000Z",
-                        "2017-02-01T09:16:04.000Z",
-                        "2017-02-01T09:16:42.000Z"
-                ),
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.MINUTE).field(AGGREGABLE_DATE).minDocCount(1L),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(3, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2017-02-01T09:02:00.000Z", bucket.getKeyAsString());
-                    assertEquals(2, bucket.getDocCount());
-
-                    bucket = buckets.get(1);
-                    assertEquals("2017-02-01T09:15:00.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(2);
-                    assertEquals("2017-02-01T09:16:00.000Z", bucket.getKeyAsString());
-                    assertEquals(2, bucket.getDocCount());
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testIntervalMinute() throws IOException {
         testSearchCase(new MatchAllDocsQuery(),
             Arrays.asList(
@@ -683,37 +463,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testIntervalSecondDeprecated() throws IOException {
-        testSearchCase(new MatchAllDocsQuery(),
-                Arrays.asList(
-                        "2017-02-01T00:00:05.015Z",
-                        "2017-02-01T00:00:11.299Z",
-                        "2017-02-01T00:00:11.074Z",
-                        "2017-02-01T00:00:37.688Z",
-                        "2017-02-01T00:00:37.210Z",
-                        "2017-02-01T00:00:37.380Z"
-                ),
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.SECOND).field(AGGREGABLE_DATE).minDocCount(1L),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(3, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2017-02-01T00:00:05.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(1);
-                    assertEquals("2017-02-01T00:00:11.000Z", bucket.getKeyAsString());
-                    assertEquals(2, bucket.getDocCount());
-
-                    bucket = buckets.get(2);
-                    assertEquals("2017-02-01T00:00:37.000Z", bucket.getKeyAsString());
-                    assertEquals(3, bucket.getDocCount());
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testIntervalSecond() throws IOException {
         testSearchCase(new MatchAllDocsQuery(),
             Arrays.asList(
@@ -828,56 +577,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         );
     }
 
-    public void testMinDocCountDeprecated() throws IOException {
-        Query query = LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2017-02-01T00:00:00.000Z"), asLong("2017-02-01T00:00:30.000Z"));
-        List<String> timestamps = Arrays.asList(
-                "2017-02-01T00:00:05.015Z",
-                "2017-02-01T00:00:11.299Z",
-                "2017-02-01T00:00:11.074Z",
-                "2017-02-01T00:00:13.688Z",
-                "2017-02-01T00:00:21.380Z"
-        );
-
-        // 5 sec interval with minDocCount = 0
-        testSearchCase(query, timestamps,
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.seconds(5)).field(AGGREGABLE_DATE).minDocCount(0L),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(4, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2017-02-01T00:00:05.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-
-                    bucket = buckets.get(1);
-                    assertEquals("2017-02-01T00:00:10.000Z", bucket.getKeyAsString());
-                    assertEquals(3, bucket.getDocCount());
-
-                    bucket = buckets.get(2);
-                    assertEquals("2017-02-01T00:00:15.000Z", bucket.getKeyAsString());
-                    assertEquals(0, bucket.getDocCount());
-
-                    bucket = buckets.get(3);
-                    assertEquals("2017-02-01T00:00:20.000Z", bucket.getKeyAsString());
-                    assertEquals(1, bucket.getDocCount());
-                }, false
-        );
-
-        // 5 sec interval with minDocCount = 3
-        testSearchCase(query, timestamps,
-                aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.seconds(5)).field(AGGREGABLE_DATE).minDocCount(3L),
-                histogram -> {
-                    List<? extends Histogram.Bucket> buckets = histogram.getBuckets();
-                    assertEquals(1, buckets.size());
-
-                    Histogram.Bucket bucket = buckets.get(0);
-                    assertEquals("2017-02-01T00:00:10.000Z", bucket.getKeyAsString());
-                    assertEquals(3, bucket.getDocCount());
-                }, false
-        );
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
     public void testMinDocCount() throws IOException {
         Query query = LongPoint.newRangeQuery(SEARCHABLE_DATE, asLong("2017-02-01T00:00:00.000Z"), asLong("2017-02-01T00:00:30.000Z"));
         List<String> timestamps = Arrays.asList(
@@ -1000,149 +699,6 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
         assertThat(e.getMessage(), equalTo("Cannot use [calendar_interval] with [fixed_interval] configuration option."));
     }
 
-    public void testNewThenLegacy() throws IOException {
-        IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation.fixedInterval(new DateHistogramInterval("2d"))
-                .dateHistogramInterval(DateHistogramInterval.DAY)
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [interval] with [fixed_interval] or [calendar_interval] configuration options."));
-
-        e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY)
-                .dateHistogramInterval(DateHistogramInterval.DAY)
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [interval] with [fixed_interval] or [calendar_interval] configuration options."));
-
-        e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation.fixedInterval(new DateHistogramInterval("2d"))
-                .interval(1000)
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [interval] with [fixed_interval] or [calendar_interval] configuration options."));
-
-        e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation.calendarInterval(DateHistogramInterval.DAY)
-                .interval(1000)
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [interval] with [fixed_interval] or [calendar_interval] configuration options."));
-    }
-
-    public void testLegacyThenNew() throws IOException {
-        IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation .dateHistogramInterval(DateHistogramInterval.DAY)
-                .fixedInterval(new DateHistogramInterval("2d"))
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [fixed_interval] with [interval] configuration option."));
-
-        e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.DAY)
-                .calendarInterval(DateHistogramInterval.DAY)
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [calendar_interval] with [interval] configuration option."));
-
-        e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation.interval(1000)
-                .fixedInterval(new DateHistogramInterval("2d"))
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [fixed_interval] with [interval] configuration option."));
-
-        e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Arrays.asList(
-                "2017-02-01",
-                "2017-02-02",
-                "2017-02-02",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-03",
-                "2017-02-05"
-            ),
-            aggregation -> aggregation.interval(1000)
-                .calendarInterval(DateHistogramInterval.DAY)
-                .field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Cannot use [calendar_interval] with [interval] configuration option."));
-
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
-    }
-
-
     public void testOverlappingBounds() {
         IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
             Arrays.asList(
@@ -1338,13 +894,35 @@ public class DateHistogramAggregatorTests extends DateHistogramAggregatorTestCas
     }
 
     public void testIllegalInterval() throws IOException {
-        IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testSearchCase(new MatchAllDocsQuery(),
-            Collections.emptyList(),
-            aggregation -> aggregation.dateHistogramInterval(new DateHistogramInterval("foobar")).field(AGGREGABLE_DATE),
-            histogram -> {}, false
-        ));
-        assertThat(e.getMessage(), equalTo("Unable to parse interval [foobar]"));
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
+        IllegalArgumentException e = expectThrows(
+            IllegalArgumentException.class,
+            () -> testSearchCase(
+                new MatchAllDocsQuery(),
+                Collections.emptyList(),
+                aggregation -> aggregation.calendarInterval(new DateHistogramInterval("foobar")).field(AGGREGABLE_DATE),
+                histogram -> {},
+                false
+            )
+        );
+        assertThat(e.getMessage(), equalTo("The supplied interval [foobar] could not be parsed as a calendar interval."));
+
+        e = expectThrows(
+            IllegalArgumentException.class,
+            () -> testSearchCase(
+                new MatchAllDocsQuery(),
+                Collections.emptyList(),
+                aggregation -> aggregation.fixedInterval(new DateHistogramInterval("foobar")).field(AGGREGABLE_DATE),
+                histogram -> {},
+                false
+            )
+        );
+        assertThat(
+            e.getMessage(),
+            equalTo(
+                "failed to parse setting [date_histogram.fixedInterval] with value [foobar] as a time value:"
+                    + " unit is missing or unrecognized"
+            )
+        );
     }
 
     public void testBuildEmpty() throws IOException {

+ 1 - 2
server/src/test/java/org/elasticsearch/search/aggregations/pipeline/CumulativeSumAggregatorTests.java

@@ -119,7 +119,7 @@ public class CumulativeSumAggregatorTests extends AggregatorTestCase {
         Query query = new MatchAllDocsQuery();
 
         DateHistogramAggregationBuilder aggBuilder = new DateHistogramAggregationBuilder("histo");
-        aggBuilder.dateHistogramInterval(DateHistogramInterval.DAY).field(HISTO_FIELD);
+        aggBuilder.fixedInterval(DateHistogramInterval.DAY).field(HISTO_FIELD);
         aggBuilder.subAggregation(new CumulativeSumPipelineAggregationBuilder("cusum", "_count"));
 
         executeTestCase(query, aggBuilder, histogram -> {
@@ -132,7 +132,6 @@ public class CumulativeSumAggregatorTests extends AggregatorTestCase {
                 sum += 1.0;
             }
         });
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
     }
 
     public void testDocCount() throws IOException {

+ 1 - 20
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/extractor/ExtractorUtils.java

@@ -139,11 +139,7 @@ public final class ExtractorUtils {
             return validateAndGetCalendarInterval(dateHistogram.getCalendarInterval().toString());
         } else if (dateHistogram.getFixedInterval() != null) {
             return dateHistogram.getFixedInterval().estimateMillis();
-        } else if (dateHistogram.dateHistogramInterval() != null) {
-            return validateAndGetCalendarInterval(dateHistogram.dateHistogramInterval().toString());
-        } else if (dateHistogram.interval() != 0) {
-            return dateHistogram.interval();
-        } else {
+        }  else {
             throw new IllegalArgumentException("Must specify an interval for date_histogram");
         }
     }
@@ -226,20 +222,5 @@ public final class ExtractorUtils {
                 agg.getCalendarInterval() :
                 sourceBuilder.getIntervalAsCalendar();
         }
-
-        @Deprecated
-        private DateHistogramInterval dateHistogramInterval() {
-            return agg != null ?
-                agg.dateHistogramInterval() :
-                sourceBuilder.dateHistogramInterval();
-        }
-
-        @Deprecated
-        private long interval() {
-            return agg != null ?
-                agg.interval() :
-                sourceBuilder.interval();
-        }
     }
-
 }

+ 3 - 27
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfig.java

@@ -48,7 +48,7 @@ import static org.elasticsearch.common.xcontent.ObjectParser.ValueType;
  *     ]
  * }
  */
-public class DateHistogramGroupConfig implements Writeable, ToXContentObject {
+public abstract class DateHistogramGroupConfig implements Writeable, ToXContentObject {
 
     static final String NAME = "date_histogram";
     public static final String INTERVAL = "interval";
@@ -183,19 +183,6 @@ public class DateHistogramGroupConfig implements Writeable, ToXContentObject {
         return fromUnknownTimeUnit(field, interval, delay, timeZone);
     }
 
-    /**
-     * Create a new {@link DateHistogramGroupConfig} using the given field and interval parameters.
-     *
-     * @deprecated Build a DateHistoConfig using {@link DateHistogramGroupConfig.CalendarInterval}
-     * or {@link DateHistogramGroupConfig.FixedInterval} instead
-     *
-     * @since 7.2.0
-     */
-    @Deprecated
-    public DateHistogramGroupConfig(final String field, final DateHistogramInterval interval) {
-        this(field, interval, null, null);
-    }
-
     /**
      * Create a new {@link DateHistogramGroupConfig} using the given configuration parameters.
      * <p>
@@ -209,13 +196,9 @@ public class DateHistogramGroupConfig implements Writeable, ToXContentObject {
      * @param delay the time delay (optional)
      * @param timeZone the id of time zone to use to calculate the date histogram (optional). When {@code null}, the UTC timezone is used.
      *
-     * @deprecated Build a DateHistoConfig using {@link DateHistogramGroupConfig.CalendarInterval}
-     * or {@link DateHistogramGroupConfig.FixedInterval} instead
-     *
      * @since 7.2.0
      */
-    @Deprecated
-    public DateHistogramGroupConfig(final String field,
+    protected DateHistogramGroupConfig(final String field,
                                     final DateHistogramInterval interval,
                                     final @Nullable DateHistogramInterval delay,
                                     final @Nullable String timeZone) {
@@ -239,14 +222,7 @@ public class DateHistogramGroupConfig implements Writeable, ToXContentObject {
         }
     }
 
-    /**
-     * @deprecated Build a DateHistoConfig using {@link DateHistogramGroupConfig.CalendarInterval}
-     * or {@link DateHistogramGroupConfig.FixedInterval} instead
-     *
-     * @since 7.2.0
-     */
-    @Deprecated
-    DateHistogramGroupConfig(final StreamInput in) throws IOException {
+    protected DateHistogramGroupConfig(final StreamInput in) throws IOException {
         interval = new DateHistogramInterval(in);
         field = in.readString();
         delay = in.readOptionalWriteable(DateHistogramInterval::new);

+ 0 - 15
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java

@@ -107,21 +107,6 @@ public class ConfigTestHelpers {
         }
     }
 
-    public static DateHistogramGroupConfig randomLegacyDateHistogramGroupConfig(final Random random) {
-        final String field = randomField(random);
-        final DateHistogramInterval delay = random.nextBoolean() ? randomInterval() : null;
-        final String timezone = random.nextBoolean() ? randomZone().getId() : null;
-        if (random.nextBoolean()) {
-            return new DateHistogramGroupConfig(field, randomInterval(), delay, timezone);
-        } else {
-            int i = random.nextInt(DateHistogramAggregationBuilder.DATE_FIELD_UNITS.size());
-            List<String> units = new ArrayList<>(DateHistogramAggregationBuilder.DATE_FIELD_UNITS.keySet());
-            Collections.shuffle(units, random);
-            return new DateHistogramGroupConfig(field, new DateHistogramInterval(units.get(0)), delay, timezone);
-        }
-    }
-
-
     public static  List<String> getFields() {
         return IntStream.range(0, ESTestCase.randomIntBetween(1, 10))
                 .mapToObj(n -> ESTestCase.randomAlphaOfLengthBetween(5, 10))

+ 15 - 11
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java

@@ -29,9 +29,7 @@ import static org.mockito.Mockito.when;
 
 public class DateHistogramGroupConfigSerializingTests extends AbstractSerializingTestCase<DateHistogramGroupConfig> {
 
-    private enum DateHistoType {
-        LEGACY, FIXED, CALENDAR
-    }
+    private enum DateHistoType { FIXED, CALENDAR }
     private static DateHistoType type;
 
     @Override
@@ -46,7 +44,7 @@ public class DateHistogramGroupConfigSerializingTests extends AbstractSerializin
         } else if (type.equals(DateHistoType.CALENDAR)) {
             return DateHistogramGroupConfig.CalendarInterval::new;
         }
-        return DateHistogramGroupConfig::new;
+        throw new IllegalStateException("Illegal date histogram legacy interval");
     }
 
     @Override
@@ -57,7 +55,7 @@ public class DateHistogramGroupConfigSerializingTests extends AbstractSerializin
         } else if (config.getClass().equals(DateHistogramGroupConfig.CalendarInterval.class)) {
             type = DateHistoType.CALENDAR;
         } else {
-            type = DateHistoType.LEGACY;
+            throw new IllegalStateException("Illegal date histogram legacy interval");
         }
         return config;
     }
@@ -172,7 +170,7 @@ public class DateHistogramGroupConfigSerializingTests extends AbstractSerializin
      */
     public void testBwcSerialization() throws IOException {
         for (int runs = 0; runs < NUMBER_OF_TEST_RUNS; runs++) {
-            final DateHistogramGroupConfig reference = ConfigTestHelpers.randomLegacyDateHistogramGroupConfig(random());
+            final DateHistogramGroupConfig reference = ConfigTestHelpers.randomDateHistogramGroupConfig(random());
 
             final BytesStreamOutput out = new BytesStreamOutput();
             reference.writeTo(out);
@@ -184,7 +182,13 @@ public class DateHistogramGroupConfigSerializingTests extends AbstractSerializin
             DateHistogramInterval delay = in.readOptionalWriteable(DateHistogramInterval::new);
             ZoneId timeZone = in.readZoneId();
 
-            assertEqualInstances(reference, new DateHistogramGroupConfig(field, interval, delay, timeZone.getId()));
+            if (reference instanceof DateHistogramGroupConfig.FixedInterval) {
+                assertEqualInstances(reference, new DateHistogramGroupConfig.FixedInterval(field, interval, delay, timeZone.getId()));
+            } else if (reference instanceof DateHistogramGroupConfig.CalendarInterval) {
+                assertEqualInstances(reference, new DateHistogramGroupConfig.CalendarInterval(field, interval, delay, timeZone.getId()));
+            } else {
+                fail("And you may ask yourself, how did I get here?");
+            }
         }
 
         for (int runs = 0; runs < NUMBER_OF_TEST_RUNS; runs++) {
@@ -201,9 +205,9 @@ public class DateHistogramGroupConfigSerializingTests extends AbstractSerializin
             out.writeZoneId(timezone);
 
             final StreamInput in = out.bytes().streamInput();
-            DateHistogramGroupConfig deserialized = new DateHistogramGroupConfig(in);
+            DateHistogramGroupConfig deserialized = new DateHistogramGroupConfig.FixedInterval(in);
 
-            assertEqualInstances(new DateHistogramGroupConfig(field, interval, delay, timezone.getId()), deserialized);
+            assertEqualInstances(new DateHistogramGroupConfig.FixedInterval(field, interval, delay, timezone.getId()), deserialized);
         }
     }
 
@@ -214,7 +218,7 @@ public class DateHistogramGroupConfigSerializingTests extends AbstractSerializin
     public void testLegacyConfigBWC() throws IOException {
         for (int runs = 0; runs < NUMBER_OF_TEST_RUNS; runs++) {
             // Serialize the old format
-            final DateHistogramGroupConfig reference = ConfigTestHelpers.randomLegacyDateHistogramGroupConfig(random());
+            final DateHistogramGroupConfig reference = ConfigTestHelpers.randomDateHistogramGroupConfig(random());
 
             final BytesStreamOutput out = new BytesStreamOutput();
             reference.writeTo(out);
@@ -238,7 +242,7 @@ public class DateHistogramGroupConfigSerializingTests extends AbstractSerializin
             final StreamInput in = out.bytes().streamInput();
 
             // Deserialize the old format
-            DateHistogramGroupConfig test = new DateHistogramGroupConfig(in);
+            DateHistogramGroupConfig test = new DateHistogramGroupConfig.FixedInterval(in);
 
             assertThat(reference.getInterval(), equalTo(test.getInterval()));
             assertThat(reference.getField(), equalTo(test.getField()));

+ 0 - 41
x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java

@@ -163,43 +163,6 @@ public class RollupJobIdentifierUtils {
 
                             // Note that this ignores CALENDER_INTERVAL on purpose, it would not be compatible
 
-                        } else if (source.dateHistogramInterval() != null) {
-                            // The histo used a deprecated interval method, so meaning is ambiguous.
-                            // Use legacy method of preferring calendar over fixed
-                            final DateHistogramInterval requestInterval = source.dateHistogramInterval();
-
-                            // Try to use explicit calendar_interval on config if it exists
-                            // Both must be calendar intervals
-                            if (validateCalendarInterval(requestInterval, configCalendarInterval)) {
-                                localCaps.add(cap);
-                                break;
-                            }
-
-                            // Otherwise fall back to old style where we prefer calendar over fixed (e.g. `1h` == calendar)
-                            // Need to verify that the config interval is in fact calendar here
-                            if (isCalendarInterval(configLegacyInterval)
-                                && validateCalendarInterval(requestInterval, configLegacyInterval)) {
-
-                                localCaps.add(cap);
-                                break;
-                            }
-
-                            // The histo's interval couldn't be parsed as a calendar, so it is assumed fixed.
-                            // Try to use explicit fixed_interval on config if it exists
-                            if (validateFixedInterval(requestInterval, configFixedInterval)) {
-                                localCaps.add(cap);
-                                break;
-                            }
-
-                        } else if (source.interval() != 0) {
-                            // Otherwise fall back to old style interval millis
-                            // Need to verify that the config interval is not calendar here
-                            if (isCalendarInterval(configLegacyInterval) == false
-                                && validateFixedInterval(new DateHistogramInterval(source.interval() + "ms"), configLegacyInterval)) {
-
-                                localCaps.add(cap);
-                                break;
-                            }
                         } else {
                             // This _should not_ happen, but if miraculously it does we need to just quit
                             throw new IllegalArgumentException("An interval of some variety must be configured on " +
@@ -240,10 +203,6 @@ public class RollupJobIdentifierUtils {
         return interval;
     }
 
-    private static boolean isCalendarInterval(DateHistogramInterval interval) {
-        return interval != null && DateHistogramAggregationBuilder.DATE_FIELD_UNITS.containsKey(interval.toString());
-    }
-
     static boolean validateCalendarInterval(DateHistogramInterval requestInterval,
                                                     DateHistogramInterval configInterval) {
         if (requestInterval == null || configInterval == null) {

+ 0 - 7
x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java

@@ -14,7 +14,6 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.search.aggregations.AggregationBuilder;
 import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder;
-import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
 import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder;
 import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
 import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder;
@@ -205,12 +204,6 @@ public class RollupRequestTranslator {
                 rolledDateHisto.calendarInterval(source.getCalendarInterval());
             } else if (source.getFixedInterval() != null) {
                 rolledDateHisto.fixedInterval(source.getFixedInterval());
-            } else if (source.dateHistogramInterval() != null) {
-                // We have to fall back to deprecated interval because we're not sure if this is fixed or cal
-                rolledDateHisto.dateHistogramInterval(source.dateHistogramInterval());
-            } else {
-                // if interval() was used we know it is fixed and can upgrade
-                rolledDateHisto.fixedInterval(new DateHistogramInterval(source.interval() + "ms"));
             }
 
             ZoneId timeZone = source.timeZone() == null ? DateHistogramGroupConfig.DEFAULT_ZONEID_TIMEZONE : source.timeZone();

+ 1 - 1
x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupIndexer.java

@@ -227,7 +227,7 @@ public abstract class RollupIndexer extends AsyncTwoPhaseIndexer<Map<String, Obj
         } else if (dateHistogram instanceof DateHistogramGroupConfig.CalendarInterval) {
             dateHistogramBuilder.calendarInterval(dateHistogram.getInterval());
         } else {
-            dateHistogramBuilder.dateHistogramInterval(dateHistogram.getInterval());
+            throw new IllegalStateException("[date_histogram] must use either [fixed_interval] or [calendar_interval]");
         }
         dateHistogramBuilder.field(dateHistogramField);
         dateHistogramBuilder.timeZone(ZoneId.of(dateHistogram.getTimeZone()));

+ 4 - 38
x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupRequestTranslationTests.java

@@ -186,7 +186,7 @@ public class RollupRequestTranslationTests extends ESTestCase {
 
     public void testDateHistoLongIntervalWithMinMax() {
         DateHistogramAggregationBuilder histo = new DateHistogramAggregationBuilder("test_histo");
-        histo.interval(86400000)
+        histo.fixedInterval(DateHistogramInterval.seconds(86400))
                 .field("foo")
                 .subAggregation(new MaxAggregationBuilder("the_max").field("max_field"))
                 .subAggregation(new AvgAggregationBuilder("the_avg").field("avg_field"));
@@ -197,7 +197,7 @@ public class RollupRequestTranslationTests extends ESTestCase {
         DateHistogramAggregationBuilder translatedHisto = (DateHistogramAggregationBuilder)translated.get(0);
 
         assertNull(translatedHisto.getCalendarInterval());
-        assertThat(translatedHisto.getFixedInterval(), equalTo(new DateHistogramInterval("86400000ms")));
+        assertThat(translatedHisto.getFixedInterval(), equalTo(new DateHistogramInterval("86400s")));
         assertThat(translatedHisto.field(), equalTo("foo.date_histogram.timestamp"));
         assertThat(translatedHisto.getSubAggregations().size(), equalTo(4));
 
@@ -218,9 +218,6 @@ public class RollupRequestTranslationTests extends ESTestCase {
         assertThat(subAggs.get("test_histo._count"), instanceOf(SumAggregationBuilder.class));
         assertThat(((SumAggregationBuilder)subAggs.get("test_histo._count")).field(),
                 equalTo("foo.date_histogram._count"));
-
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
-            "or [calendar_interval] in the future.");
     }
 
     public void testDateHistoWithTimezone() {
@@ -242,46 +239,15 @@ public class RollupRequestTranslationTests extends ESTestCase {
 
     public void testDeprecatedInterval() {
         DateHistogramAggregationBuilder histo = new DateHistogramAggregationBuilder("test_histo");
-        histo.interval(86400000).field("foo");
+        histo.fixedInterval(DateHistogramInterval.seconds(86400)).field("foo");
 
         List<AggregationBuilder> translated = translateAggregation(histo, namedWriteableRegistry);
         assertThat(translated.size(), equalTo(1));
         assertThat(translated.get(0), instanceOf(DateHistogramAggregationBuilder.class));
         DateHistogramAggregationBuilder translatedHisto = (DateHistogramAggregationBuilder)translated.get(0);
 
-        assertThat(translatedHisto.getFixedInterval().toString(), equalTo("86400000ms"));
-        assertThat(translatedHisto.field(), equalTo("foo.date_histogram.timestamp"));
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
-            "or [calendar_interval] in the future.");
-    }
-
-    public void testDeprecatedDateHistoInterval() {
-        DateHistogramAggregationBuilder histo = new DateHistogramAggregationBuilder("test_histo");
-        histo.dateHistogramInterval(new DateHistogramInterval("1d")).field("foo");
-
-        List<AggregationBuilder> translated = translateAggregation(histo, namedWriteableRegistry);
-        assertThat(translated.size(), equalTo(1));
-        assertThat(translated.get(0), instanceOf(DateHistogramAggregationBuilder.class));
-        DateHistogramAggregationBuilder translatedHisto = (DateHistogramAggregationBuilder)translated.get(0);
-
-        assertThat(translatedHisto.dateHistogramInterval().toString(), equalTo("1d"));
-        assertThat(translatedHisto.field(), equalTo("foo.date_histogram.timestamp"));
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
-            "or [calendar_interval] in the future.");
-
-
-        histo = new DateHistogramAggregationBuilder("test_histo");
-        histo.dateHistogramInterval(new DateHistogramInterval("4d")).field("foo");
-
-        translated = translateAggregation(histo, namedWriteableRegistry);
-        assertThat(translated.size(), equalTo(1));
-        assertThat(translated.get(0), instanceOf(DateHistogramAggregationBuilder.class));
-        translatedHisto = (DateHistogramAggregationBuilder)translated.get(0);
-
-        assertThat(translatedHisto.dateHistogramInterval().toString(), equalTo("4d"));
+        assertThat(translatedHisto.getFixedInterval().toString(), equalTo("86400s"));
         assertThat(translatedHisto.field(), equalTo("foo.date_histogram.timestamp"));
-        assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
-            "or [calendar_interval] in the future.");
     }
 
     public void testAvgMetric() {

+ 6 - 2
x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java

@@ -422,7 +422,9 @@ public class PutJobStateMachineTests extends ESTestCase {
     }
 
     public void testDeprecatedTimeZone() {
-        GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"), null, "Japan"));
+        GroupConfig groupConfig = new GroupConfig(
+            new DateHistogramGroupConfig.FixedInterval("foo", new DateHistogramInterval("1h"), null, "Japan")
+        );
         RollupJobConfig config = new RollupJobConfig("foo", randomAlphaOfLength(5), "rollup", ConfigTestHelpers.randomCron(),
             100, groupConfig, Collections.emptyList(), null);
         PutRollupJobAction.Request request = new PutRollupJobAction.Request(config);
@@ -432,7 +434,9 @@ public class PutJobStateMachineTests extends ESTestCase {
     }
 
     public void testTimeZone() {
-        GroupConfig groupConfig = new GroupConfig(new DateHistogramGroupConfig("foo", new DateHistogramInterval("1h"), null, "EST"));
+        GroupConfig groupConfig = new GroupConfig(
+            new DateHistogramGroupConfig.FixedInterval("foo", new DateHistogramInterval("1h"), null, "EST")
+        );
         RollupJobConfig config = new RollupJobConfig("foo", randomAlphaOfLength(5), "rollup", ConfigTestHelpers.randomCron(),
             100, groupConfig, Collections.emptyList(), null);
         PutRollupJobAction.Request request = new PutRollupJobAction.Request(config);

+ 6 - 1
x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java

@@ -93,7 +93,12 @@ public class ConfigTests extends ESTestCase {
     }
 
     public void testObsoleteTimeZone() {
-        DateHistogramGroupConfig config = new DateHistogramGroupConfig("foo", DateHistogramInterval.HOUR, null, "Canada/Mountain");
+        DateHistogramGroupConfig config = new DateHistogramGroupConfig.FixedInterval(
+            "foo",
+            DateHistogramInterval.HOUR,
+            null,
+            "Canada/Mountain"
+        );
         assertThat(config.getTimeZone(), equalTo("Canada/Mountain"));
     }
 

+ 4 - 4
x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/rollup/rollup_search.yml

@@ -942,7 +942,7 @@ setup:
             "groups" : {
               "date_histogram": {
                 "field": "timestamp",
-                "interval": "5m",
+                "fixed_interval": "5m",
                 "time_zone": "Canada/Mountain"
               },
               "terms": {
@@ -1251,7 +1251,7 @@ setup:
             histo:
               date_histogram:
                 field: "timestamp"
-                interval: "asdfasdf"
+                fixed_interval: "asdfasdf"
 
 
 ---
@@ -1267,7 +1267,7 @@ setup:
             histo:
               date_histogram:
                 field: "timestamp"
-                interval: "asdfasdf"
+                fixed_interval: "asdfasdf"
 
 ---
 "Search error no matching indices":
@@ -1282,5 +1282,5 @@ setup:
             histo:
               date_histogram:
                 field: "timestamp"
-                interval: "1h"
+                fixed_interval: "1h"
 

+ 2 - 2
x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/condition/CompareConditionSearchTests.java

@@ -43,7 +43,7 @@ public class CompareConditionSearchTests extends AbstractWatcherIntegrationTestC
 
         SearchResponse response = client().prepareSearch("my-index")
                 .addAggregation(AggregationBuilders.dateHistogram("rate").field("@timestamp")
-                        .dateHistogramInterval(DateHistogramInterval.HOUR).order(BucketOrder.count(false)))
+                        .fixedInterval(DateHistogramInterval.HOUR).order(BucketOrder.count(false)))
                 .get();
 
         CompareCondition condition = new CompareCondition("ctx.payload.aggregations.rate.buckets.0.doc_count", CompareCondition.Op.GTE, 5,
@@ -61,7 +61,7 @@ public class CompareConditionSearchTests extends AbstractWatcherIntegrationTestC
 
         response = client().prepareSearch("my-index")
                 .addAggregation(AggregationBuilders.dateHistogram("rate")
-                        .field("@timestamp").dateHistogramInterval(DateHistogramInterval.HOUR).order(BucketOrder.count(false)))
+                        .field("@timestamp").fixedInterval(DateHistogramInterval.HOUR).order(BucketOrder.count(false)))
                 .get();
 
         ctx = mockExecutionContext("_name", new Payload.XContent(response, ToXContent.EMPTY_PARAMS));