Skip to content

Commit 12aa3be

Browse files
Remove support for types field in watcher search
In 8.x, setting `input.search.request.types` to an empty array was allowed, although it resulted in a deprecation warning and had no effect (and any value other than an empty array would result in an error). In 9.x, support for this field is entirely removed, and the empty array will also result in an error. We have already introduced a script to be run as part of the upgrade which removes the field from existing watches in #120371. This also removes an unrelated TODO in passing, because we are not going to do that (the functionality it refers to exists and is not deprecated so cannot be removed).
1 parent be7635e commit 12aa3be

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.common.Strings;
1313
import org.elasticsearch.common.bytes.BytesArray;
1414
import org.elasticsearch.common.bytes.BytesReference;
15-
import org.elasticsearch.common.logging.DeprecationCategory;
1615
import org.elasticsearch.common.logging.DeprecationLogger;
1716
import org.elasticsearch.core.Nullable;
1817
import org.elasticsearch.script.Script;
@@ -173,7 +172,6 @@ public static WatcherSearchTemplateRequest fromXContent(XContentParser parser, S
173172
IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;
174173
BytesReference searchSource = null;
175174
Script template = null;
176-
// TODO this is to retain BWC compatibility in 7.0 and can be removed for 8.0
177175
boolean totalHitsAsInt = true;
178176

179177
XContentParser.Token token;
@@ -196,17 +194,6 @@ public static WatcherSearchTemplateRequest fromXContent(XContentParser parser, S
196194
);
197195
}
198196
}
199-
} else if (TYPES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
200-
// Tolerate an empty types array, because some watches created internally in 6.x have
201-
// an empty types array in their search, and it's clearly equivalent to typeless.
202-
if (parser.nextToken() != XContentParser.Token.END_ARRAY) {
203-
throw new ElasticsearchParseException(
204-
"could not read search request. unsupported non-empty array field [" + currentFieldName + "]"
205-
);
206-
}
207-
// Empty types arrays still generate the same deprecation warning they did in 7.x.
208-
// Ideally they should be removed from the definition.
209-
deprecationLogger.critical(DeprecationCategory.PARSING, "watcher_search_input", TYPES_DEPRECATION_MESSAGE);
210197
} else {
211198
throw new ElasticsearchParseException(
212199
"could not read search request. unexpected array field [" + currentFieldName + "]"
@@ -289,7 +276,6 @@ public int hashCode() {
289276
}
290277

291278
private static final ParseField INDICES_FIELD = new ParseField("indices");
292-
private static final ParseField TYPES_FIELD = new ParseField("types");
293279
private static final ParseField BODY_FIELD = new ParseField("body");
294280
private static final ParseField SEARCH_TYPE_FIELD = new ParseField("search_type");
295281
private static final ParseField INDICES_OPTIONS_FIELD = new ParseField("indices_options");

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ public void testFromXContentWithEmptyTypes() throws IOException {
5252
""";
5353
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
5454
parser.nextToken();
55-
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(parser, randomFrom(SearchType.values()));
56-
assertThat(result.getIndices(), arrayContaining(".ml-anomalies-*"));
55+
ElasticsearchParseException e = expectThrows(
56+
ElasticsearchParseException.class,
57+
() -> WatcherSearchTemplateRequest.fromXContent(parser, randomFrom(SearchType.values()))
58+
);
59+
assertThat(e.getMessage(), is("could not read search request. unexpected array field [types]"));
5760
}
5861
}
5962

@@ -74,7 +77,7 @@ public void testFromXContentWithNonEmptyTypes() throws IOException {
7477
ElasticsearchParseException.class,
7578
() -> WatcherSearchTemplateRequest.fromXContent(parser, randomFrom(SearchType.values()))
7679
);
77-
assertThat(e.getMessage(), is("could not read search request. unsupported non-empty array field [types]"));
80+
assertThat(e.getMessage(), is("could not read search request. unexpected array field [types]"));
7881
}
7982
}
8083

0 commit comments

Comments
 (0)