From 57db6114cc1b7e34ade8edfdee553dc3ec8a20e7 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 30 Mar 2020 09:56:59 -0400 Subject: [PATCH 1/2] Fix a master->7.x serialization bug `master` wasn't sending `auto_date_histogram`'s `minimumIntervalExpression` over the wire to `7.x` nodes even though everything above `7.3` expected it. We never noticed this because we didn't have any yml tests for `auto_date_histogram` until I added some in #54161. Closes #54396 --- .../330_auto_date_histogram.yml | 3 -- .../AutoDateHistogramAggregationBuilder.java | 43 +++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/330_auto_date_histogram.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/330_auto_date_histogram.yml index 32524b1e4892b..15f5962b1c63c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/330_auto_date_histogram.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/330_auto_date_histogram.yml @@ -25,9 +25,6 @@ setup: --- "basic": - - skip: - version: " - 7.99.99" - reason: BWC test failures https://github.com/elastic/elasticsearch/issues/54396 && waiting for backport https://github.com/elastic/elasticsearch/pull/54379 - do: search: body: diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java index 25e98b00b2464..4ae831d8875bf 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java @@ -110,20 +110,6 @@ static RoundingInfo[] buildRoundings(ZoneId timeZone, String minimumInterval) { private String minimumIntervalExpression; - public String getMinimumIntervalExpression() { - return minimumIntervalExpression; - } - - public AutoDateHistogramAggregationBuilder setMinimumIntervalExpression(String minimumIntervalExpression) { - if (minimumIntervalExpression != null && !ALLOWED_INTERVALS.containsValue(minimumIntervalExpression)) { - throw new IllegalArgumentException(MINIMUM_INTERVAL_FIELD.getPreferredName() + - " must be one of [" + ALLOWED_INTERVALS.values().toString() + "]"); - } - this.minimumIntervalExpression = minimumIntervalExpression; - return this; - } - - /** Create a new builder with the given name. */ public AutoDateHistogramAggregationBuilder(String name) { super(name); @@ -138,6 +124,14 @@ public AutoDateHistogramAggregationBuilder(StreamInput in) throws IOException { } } + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeVInt(numBuckets); + if (out.getVersion().onOrAfter(Version.V_8_0_0)) { + out.writeOptionalString(minimumIntervalExpression); + } + } + protected AutoDateHistogramAggregationBuilder(AutoDateHistogramAggregationBuilder clone, Builder factoriesBuilder, Map metaData) { super(clone, factoriesBuilder, metaData); @@ -156,19 +150,24 @@ protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map Date: Mon, 30 Mar 2020 10:47:04 -0400 Subject: [PATCH 2/2] Actually fix bug --- .../bucket/histogram/AutoDateHistogramAggregationBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java index 4ae831d8875bf..2036a312b18a2 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java @@ -127,7 +127,7 @@ public AutoDateHistogramAggregationBuilder(StreamInput in) throws IOException { @Override protected void innerWriteTo(StreamOutput out) throws IOException { out.writeVInt(numBuckets); - if (out.getVersion().onOrAfter(Version.V_8_0_0)) { + if (out.getVersion().onOrAfter(Version.V_7_3_0)) { out.writeOptionalString(minimumIntervalExpression); } }