@@ -113,20 +113,6 @@ static RoundingInfo[] buildRoundings(ZoneId timeZone, String minimumInterval) {
113
113
114
114
private String minimumIntervalExpression ;
115
115
116
- public String getMinimumIntervalExpression () {
117
- return minimumIntervalExpression ;
118
- }
119
-
120
- public AutoDateHistogramAggregationBuilder setMinimumIntervalExpression (String minimumIntervalExpression ) {
121
- if (minimumIntervalExpression != null && !ALLOWED_INTERVALS .containsValue (minimumIntervalExpression )) {
122
- throw new IllegalArgumentException (MINIMUM_INTERVAL_FIELD .getPreferredName () +
123
- " must be one of [" + ALLOWED_INTERVALS .values ().toString () + "]" );
124
- }
125
- this .minimumIntervalExpression = minimumIntervalExpression ;
126
- return this ;
127
- }
128
-
129
-
130
116
/** Create a new builder with the given name. */
131
117
public AutoDateHistogramAggregationBuilder (String name ) {
132
118
super (name , CoreValuesSourceType .NUMERIC , ValueType .DATE );
@@ -141,6 +127,14 @@ public AutoDateHistogramAggregationBuilder(StreamInput in) throws IOException {
141
127
}
142
128
}
143
129
130
+ @ Override
131
+ protected void innerWriteTo (StreamOutput out ) throws IOException {
132
+ out .writeVInt (numBuckets );
133
+ if (out .getVersion ().onOrAfter (Version .V_7_3_0 )) {
134
+ out .writeOptionalString (minimumIntervalExpression );
135
+ }
136
+ }
137
+
144
138
protected AutoDateHistogramAggregationBuilder (AutoDateHistogramAggregationBuilder clone , Builder factoriesBuilder ,
145
139
Map <String , Object > metaData ) {
146
140
super (clone , factoriesBuilder , metaData );
@@ -153,19 +147,24 @@ protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, O
153
147
return new AutoDateHistogramAggregationBuilder (this , factoriesBuilder , metaData );
154
148
}
155
149
156
- @ Override
157
- protected void innerWriteTo (StreamOutput out ) throws IOException {
158
- out .writeVInt (numBuckets );
159
- if (out .getVersion ().onOrAfter (Version .V_7_3_0 )) {
160
- out .writeOptionalString (minimumIntervalExpression );
161
- }
162
- }
163
-
164
150
@ Override
165
151
public String getType () {
166
152
return NAME ;
167
153
}
168
154
155
+ public String getMinimumIntervalExpression () {
156
+ return minimumIntervalExpression ;
157
+ }
158
+
159
+ public AutoDateHistogramAggregationBuilder setMinimumIntervalExpression (String minimumIntervalExpression ) {
160
+ if (minimumIntervalExpression != null && !ALLOWED_INTERVALS .containsValue (minimumIntervalExpression )) {
161
+ throw new IllegalArgumentException (MINIMUM_INTERVAL_FIELD .getPreferredName () +
162
+ " must be one of [" + ALLOWED_INTERVALS .values ().toString () + "]" );
163
+ }
164
+ this .minimumIntervalExpression = minimumIntervalExpression ;
165
+ return this ;
166
+ }
167
+
169
168
public AutoDateHistogramAggregationBuilder setNumBuckets (int numBuckets ) {
170
169
if (numBuckets <= 0 ) {
171
170
throw new IllegalArgumentException (NUM_BUCKETS_FIELD .getPreferredName () + " must be greater than 0 for [" + name + "]" );
@@ -262,7 +261,17 @@ public RoundingInfo(StreamInput in) throws IOException {
262
261
roughEstimateDurationMillis = in .readVLong ();
263
262
innerIntervals = in .readIntArray ();
264
263
unitAbbreviation = in .readString ();
265
- dateTimeUnit = in .readString ();
264
+ if (in .getVersion ().onOrAfter (Version .V_7_3_0 )) {
265
+ dateTimeUnit = in .readString ();
266
+ } else {
267
+ /*
268
+ * This *should* be safe because we only deserialize RoundingInfo
269
+ * when reading result and results don't actually use this at all.
270
+ * We just set it to something non-null to line up with the normal
271
+ * ctor. "seconds" is the smallest unit anyway.
272
+ */
273
+ dateTimeUnit = "second" ;
274
+ }
266
275
}
267
276
268
277
@ Override
@@ -271,7 +280,9 @@ public void writeTo(StreamOutput out) throws IOException {
271
280
out .writeVLong (roughEstimateDurationMillis );
272
281
out .writeIntArray (innerIntervals );
273
282
out .writeString (unitAbbreviation );
274
- out .writeString (dateTimeUnit );
283
+ if (out .getVersion ().onOrAfter (Version .V_7_3_0 )) {
284
+ out .writeString (dateTimeUnit );
285
+ }
275
286
}
276
287
277
288
public int getMaximumInnerInterval () {
0 commit comments