Skip to content

Commit fac9bb4

Browse files
Remove support for types field in watcher search (#120748)
In 8.x, setting the `input.search.request.types` field in the payload when creating a watcher 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). ES-9747 #close #comment Types in search request removed in #120748
1 parent 969cd70 commit fac9bb4

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

docs/changelog/120748.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pr: 120748
2+
summary: Removing support for types field in watcher search
3+
area: Watcher
4+
type: breaking
5+
issues: []
6+
breaking:
7+
title: Removing support for types field in watcher search
8+
area: REST API
9+
details: >-
10+
Previously, setting the `input.search.request.types` field in the payload when creating a watcher to an empty array
11+
was allowed, although it resulted in a deprecation warning and had no effect (and any value other than an empty
12+
array would result in an error). Now, support for this field is entirely removed, and the empty array will also
13+
result in an error.
14+
impact: Users should stop setting this field (which did not have any effect anyway).
15+
notable: false

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.Map;
1818

1919
import static java.util.Collections.singletonMap;
20-
import static org.hamcrest.Matchers.arrayContaining;
2120
import static org.hamcrest.Matchers.equalTo;
2221
import static org.hamcrest.Matchers.is;
2322

@@ -52,8 +51,11 @@ public void testFromXContentWithEmptyTypes() throws IOException {
5251
""";
5352
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
5453
parser.nextToken();
55-
WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(parser, randomFrom(SearchType.values()));
56-
assertThat(result.getIndices(), arrayContaining(".ml-anomalies-*"));
54+
ElasticsearchParseException e = expectThrows(
55+
ElasticsearchParseException.class,
56+
() -> WatcherSearchTemplateRequest.fromXContent(parser, randomFrom(SearchType.values()))
57+
);
58+
assertThat(e.getMessage(), is("could not read search request. unexpected array field [types]"));
5759
}
5860
}
5961

@@ -74,7 +76,7 @@ public void testFromXContentWithNonEmptyTypes() throws IOException {
7476
ElasticsearchParseException.class,
7577
() -> WatcherSearchTemplateRequest.fromXContent(parser, randomFrom(SearchType.values()))
7678
);
77-
assertThat(e.getMessage(), is("could not read search request. unsupported non-empty array field [types]"));
79+
assertThat(e.getMessage(), is("could not read search request. unexpected array field [types]"));
7880
}
7981
}
8082

0 commit comments

Comments
 (0)