-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rest Api Compatibility] MovAvgPipelineAggregation (#82828)
- Loading branch information
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...rc/yamlRestTestV7Compat/resources/rest-api-spec/test/search.aggregation/10_moving_avg.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
setup: | ||
- skip: | ||
version: "9.0.0 - " | ||
reason: "compatible from 8.x to 7.x" | ||
features: | ||
- "headers" | ||
|
||
--- | ||
moving_avg agg throws exception: | ||
- do: | ||
catch: "/Moving Average aggregation usage is not supported. Use the \\[moving_fn\\] aggregation instead./" | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
aggs: | ||
the_histo: | ||
date_histogram: | ||
field: "date" | ||
calendar_interval: "1d" | ||
aggs: | ||
the_avg: | ||
avg: | ||
field: "value_field" | ||
the_movavg: | ||
moving_avg: | ||
buckets_path: "the_avg" | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...java/org/elasticsearch/search/aggregations/pipeline/MovAvgPipelineAggregationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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.pipeline; | ||
|
||
import org.elasticsearch.common.ParsingException; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.core.RestApiVersion; | ||
import org.elasticsearch.index.query.CommonTermsQueryBuilder; | ||
import org.elasticsearch.xcontent.ContextParser; | ||
import org.elasticsearch.xcontent.ParseField; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* The actual moving_avg aggregation was removed as a breaking change in 8.0. This class exists to provide a friendlier error message | ||
* if somebody attempts to use the moving_avg aggregation via the compatible-with=7 mechanism. | ||
* | ||
* We can remove this class entirely when v7 rest api compatibility is dropped. | ||
* | ||
* @deprecated Only for 7.x rest compat | ||
*/ | ||
@Deprecated | ||
public class MovAvgPipelineAggregationBuilder extends AbstractPipelineAggregationBuilder<MovAvgPipelineAggregationBuilder> { | ||
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(CommonTermsQueryBuilder.class); | ||
public static final String MOVING_AVG_AGG_DEPRECATION_MSG = "Moving Average aggregation usage is not supported. " | ||
+ "Use the [moving_fn] aggregation instead."; | ||
|
||
public static ParseField NAME_V7 = new ParseField("moving_avg").withAllDeprecated(MOVING_AVG_AGG_DEPRECATION_MSG) | ||
.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)); | ||
|
||
public static final ContextParser<String, MovAvgPipelineAggregationBuilder> PARSER = (parser, name) -> { | ||
deprecationLogger.compatibleCritical("moving_avg_aggregation", MOVING_AVG_AGG_DEPRECATION_MSG); | ||
throw new ParsingException(parser.getTokenLocation(), MOVING_AVG_AGG_DEPRECATION_MSG); | ||
}; | ||
|
||
public MovAvgPipelineAggregationBuilder(StreamInput in) throws IOException { | ||
super(in, NAME_V7.getPreferredName()); | ||
throw new UnsupportedOperationException("moving_avg is not meant to be used."); | ||
} | ||
|
||
@Override | ||
protected void doWriteTo(StreamOutput out) throws IOException { | ||
throw new UnsupportedOperationException("moving_avg is not meant to be used."); | ||
} | ||
|
||
@Override | ||
protected PipelineAggregator createInternal(Map<String, Object> metadata) { | ||
throw new UnsupportedOperationException("moving_avg is not meant to be used."); | ||
} | ||
|
||
@Override | ||
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { | ||
throw new UnsupportedOperationException("moving_avg is not meant to be used."); | ||
} | ||
|
||
@Override | ||
protected void validate(ValidationContext context) { | ||
throw new UnsupportedOperationException("moving_avg is not meant to be used."); | ||
} | ||
|
||
@Override | ||
public final String getWriteableName() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters