Skip to content

Commit 0f7b97a

Browse files
authored
Remove types from WatcherSearchTemplateRequest (#51112)
There is no longer any point in restricting the types for a Watcher search template. The types parameter was deprecated in 7x, and can be removed from 8x. Relates to #41059
1 parent 605620c commit 0f7b97a

File tree

6 files changed

+10
-94
lines changed

6 files changed

+10
-94
lines changed

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

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.watcher.support.search;
77

8-
import org.apache.logging.log4j.LogManager;
98
import org.elasticsearch.ElasticsearchParseException;
109
import org.elasticsearch.action.search.SearchType;
1110
import org.elasticsearch.action.support.IndicesOptions;
@@ -14,7 +13,6 @@
1413
import org.elasticsearch.common.Strings;
1514
import org.elasticsearch.common.bytes.BytesArray;
1615
import org.elasticsearch.common.bytes.BytesReference;
17-
import org.elasticsearch.common.logging.DeprecationLogger;
1816
import org.elasticsearch.common.xcontent.ToXContentObject;
1917
import org.elasticsearch.common.xcontent.XContentBuilder;
2018
import org.elasticsearch.common.xcontent.XContentFactory;
@@ -38,21 +36,15 @@
3836
public class WatcherSearchTemplateRequest implements ToXContentObject {
3937

4038
private final String[] indices;
41-
private final String[] types;
4239
private final SearchType searchType;
4340
private final IndicesOptions indicesOptions;
4441
private final Script template;
4542
private final BytesReference searchSource;
4643
private boolean restTotalHitsAsInt = true;
4744

48-
private static final DeprecationLogger deprecationLogger =
49-
new DeprecationLogger(LogManager.getLogger(WatcherSearchTemplateRequest.class));
50-
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in a watcher search request is deprecated.";
51-
52-
public WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType searchType, IndicesOptions indicesOptions,
45+
public WatcherSearchTemplateRequest(String[] indices, SearchType searchType, IndicesOptions indicesOptions,
5346
BytesReference searchSource) {
5447
this.indices = indices;
55-
this.types = types;
5648
this.searchType = searchType;
5749
this.indicesOptions = indicesOptions;
5850
// Here we convert a watch search request body into an inline search template,
@@ -61,10 +53,9 @@ public WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType
6153
this.searchSource = BytesArray.EMPTY;
6254
}
6355

64-
public WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType searchType, IndicesOptions indicesOptions,
56+
public WatcherSearchTemplateRequest(String[] indices, SearchType searchType, IndicesOptions indicesOptions,
6557
Script template) {
6658
this.indices = indices;
67-
this.types = types;
6859
this.searchType = searchType;
6960
this.indicesOptions = indicesOptions;
7061
this.template = template;
@@ -73,18 +64,16 @@ public WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType
7364

7465
public WatcherSearchTemplateRequest(WatcherSearchTemplateRequest original, BytesReference source) {
7566
this.indices = original.indices;
76-
this.types = original.types;
7767
this.searchType = original.searchType;
7868
this.indicesOptions = original.indicesOptions;
7969
this.searchSource = source;
8070
this.template = original.template;
8171
this.restTotalHitsAsInt = original.restTotalHitsAsInt;
8272
}
8373

84-
private WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType searchType, IndicesOptions indicesOptions,
74+
private WatcherSearchTemplateRequest(String[] indices, SearchType searchType, IndicesOptions indicesOptions,
8575
BytesReference searchSource, Script template) {
8676
this.indices = indices;
87-
this.types = types;
8877
this.searchType = searchType;
8978
this.indicesOptions = indicesOptions;
9079
this.template = template;
@@ -100,10 +89,6 @@ public String[] getIndices() {
10089
return indices;
10190
}
10291

103-
public String[] getTypes() {
104-
return types;
105-
}
106-
10792
public SearchType getSearchType() {
10893
return searchType;
10994
}
@@ -146,9 +131,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
146131
if (indices != null) {
147132
builder.array(INDICES_FIELD.getPreferredName(), indices);
148133
}
149-
if (types != null) {
150-
builder.array(TYPES_FIELD.getPreferredName(), types);
151-
}
152134
if (restTotalHitsAsInt) {
153135
builder.field(REST_TOTAL_HITS_AS_INT_FIELD.getPreferredName(), restTotalHitsAsInt);
154136
}
@@ -186,7 +168,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
186168
*/
187169
public static WatcherSearchTemplateRequest fromXContent(XContentParser parser, SearchType searchType) throws IOException {
188170
List<String> indices = new ArrayList<>();
189-
List<String> types = new ArrayList<>();
190171
IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;
191172
BytesReference searchSource = null;
192173
Script template = null;
@@ -208,16 +189,6 @@ public static WatcherSearchTemplateRequest fromXContent(XContentParser parser, S
208189
currentFieldName + "] field, but instead found [" + token + "]");
209190
}
210191
}
211-
} else if (TYPES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
212-
deprecationLogger.deprecatedAndMaybeLog("watcher_search_input", TYPES_DEPRECATION_MESSAGE);
213-
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
214-
if (token == XContentParser.Token.VALUE_STRING) {
215-
types.add(parser.textOrNull());
216-
} else {
217-
throw new ElasticsearchParseException("could not read search request. expected string values in [" +
218-
currentFieldName + "] field, but instead found [" + token + "]");
219-
}
220-
}
221192
} else {
222193
throw new ElasticsearchParseException("could not read search request. unexpected array field [" +
223194
currentFieldName + "]");
@@ -284,10 +255,6 @@ public static WatcherSearchTemplateRequest fromXContent(XContentParser parser, S
284255
if (INDICES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
285256
String indicesStr = parser.text();
286257
indices.addAll(Arrays.asList(Strings.delimitedListToStringArray(indicesStr, ",", " \t")));
287-
} else if (TYPES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
288-
deprecationLogger.deprecatedAndMaybeLog("watcher_search_input", TYPES_DEPRECATION_MESSAGE);
289-
String typesStr = parser.text();
290-
types.addAll(Arrays.asList(Strings.delimitedListToStringArray(typesStr, ",", " \t")));
291258
} else if (SEARCH_TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
292259
searchType = SearchType.fromString(parser.text().toLowerCase(Locale.ROOT));
293260
} else if (REST_TOTAL_HITS_AS_INT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
@@ -313,7 +280,7 @@ public static WatcherSearchTemplateRequest fromXContent(XContentParser parser, S
313280
}
314281

315282
WatcherSearchTemplateRequest request = new WatcherSearchTemplateRequest(indices.toArray(new String[0]),
316-
types.size() == 0 ? null : types.toArray(new String[0]), searchType, indicesOptions, searchSource, template);
283+
searchType, indicesOptions, searchSource, template);
317284
request.setRestTotalHitsAsInt(totalHitsAsInt);
318285
return request;
319286
}
@@ -325,7 +292,6 @@ public boolean equals(Object o) {
325292

326293
WatcherSearchTemplateRequest other = (WatcherSearchTemplateRequest) o;
327294
return Arrays.equals(indices, other.indices) &&
328-
Arrays.equals(types, other.types) &&
329295
Objects.equals(searchType, other.searchType) &&
330296
Objects.equals(indicesOptions, other.indicesOptions) &&
331297
Objects.equals(searchSource, other.searchSource) &&
@@ -336,11 +302,10 @@ public boolean equals(Object o) {
336302

337303
@Override
338304
public int hashCode() {
339-
return Objects.hash(indices, types, searchType, indicesOptions, searchSource, template, restTotalHitsAsInt);
305+
return Objects.hash(indices, searchType, indicesOptions, searchSource, template, restTotalHitsAsInt);
340306
}
341307

342308
private static final ParseField INDICES_FIELD = new ParseField("indices");
343-
private static final ParseField TYPES_FIELD = new ParseField("types");
344309
private static final ParseField BODY_FIELD = new ParseField("body");
345310
private static final ParseField SEARCH_TYPE_FIELD = new ParseField("search_type");
346311
private static final ParseField INDICES_OPTIONS_FIELD = new ParseField("indices_options");

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ public class HistoryTemplateSearchInputMappingsTests extends AbstractWatcherInte
3636

3737
public void testHttpFields() throws Exception {
3838
String index = "the-index";
39-
String type = "the-type";
4039
createIndex(index);
4140
indexDoc(index, "{}");
4241
flush();
4342
refresh();
4443

4544
WatcherSearchTemplateRequest request = new WatcherSearchTemplateRequest(
46-
new String[]{index}, new String[]{type}, SearchType.QUERY_THEN_FETCH,
45+
new String[]{index}, SearchType.QUERY_THEN_FETCH,
4746
WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, new BytesArray("{}")
4847
);
4948
PutWatchResponse putWatchResponse = new PutWatchRequestBuilder(client(), "_id").setSource(watchBuilder()
@@ -64,7 +63,6 @@ WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, new BytesArray("{}")
6463
SearchResponse response = client().prepareSearch(HistoryStoreField.INDEX_PREFIX_WITH_TEMPLATE + "*").setSource(searchSource()
6564
.aggregation(terms("input_search_type").field("result.input.search.request.search_type"))
6665
.aggregation(terms("input_indices").field("result.input.search.request.indices"))
67-
.aggregation(terms("input_types").field("result.input.search.request.types"))
6866
.aggregation(terms("input_body").field("result.input.search.request.body")))
6967
.get();
7068

@@ -85,12 +83,6 @@ WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, new BytesArray("{}")
8583
assertThat(terms.getBucketByKey(index), notNullValue());
8684
assertThat(terms.getBucketByKey(index).getDocCount(), is(1L));
8785

88-
terms = aggs.get("input_types");
89-
assertThat(terms, notNullValue());
90-
assertThat(terms.getBuckets().size(), is(1));
91-
assertThat(terms.getBucketByKey(type), notNullValue());
92-
assertThat(terms.getBucketByKey(type).getDocCount(), is(1L));
93-
9486
terms = aggs.get("input_body");
9587
assertThat(terms, notNullValue());
9688
assertThat(terms.getBuckets().size(), is(0));

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public void testResponseToData() throws Exception {
9090

9191
public void testSerializeSearchRequest() throws Exception {
9292
String[] expectedIndices = generateRandomStringArray(5, 5, true);
93-
String[] expectedTypes = generateRandomStringArray(2, 5, true, false);
9493
IndicesOptions expectedIndicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
9594
randomBoolean(), WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS);
9695
SearchType expectedSearchType = getRandomSupportedSearchType();
@@ -111,14 +110,14 @@ public void testSerializeSearchRequest() throws Exception {
111110
ScriptType scriptType = randomFrom(ScriptType.values());
112111
stored = scriptType == ScriptType.STORED;
113112
expectedTemplate = new Script(scriptType, stored ? null : "mustache", text, params);
114-
request = new WatcherSearchTemplateRequest(expectedIndices, expectedTypes, expectedSearchType,
113+
request = new WatcherSearchTemplateRequest(expectedIndices, expectedSearchType,
115114
expectedIndicesOptions, expectedTemplate);
116115
} else {
117116
SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource().query(QueryBuilders.matchAllQuery()).size(11);
118117
XContentBuilder builder = jsonBuilder();
119118
builder.value(sourceBuilder);
120119
expectedSource = BytesReference.bytes(builder);
121-
request = new WatcherSearchTemplateRequest(expectedIndices, expectedTypes, expectedSearchType,
120+
request = new WatcherSearchTemplateRequest(expectedIndices, expectedSearchType,
122121
expectedIndicesOptions, expectedSource);
123122
}
124123

@@ -142,12 +141,6 @@ public void testSerializeSearchRequest() throws Exception {
142141
assertThat(result.getTemplate().getIdOrCode(), equalTo(expectedSource.utf8ToString()));
143142
assertThat(result.getTemplate().getType(), equalTo(ScriptType.INLINE));
144143
}
145-
if (expectedTypes == null) {
146-
assertNull(result.getTypes());
147-
} else {
148-
assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes));
149-
assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);
150-
}
151144
}
152145

153146
public void testDeserializeSearchRequest() throws Exception {
@@ -164,16 +157,6 @@ public void testDeserializeSearchRequest() throws Exception {
164157
}
165158
}
166159

167-
String[] types = Strings.EMPTY_ARRAY;
168-
if (randomBoolean()) {
169-
types = generateRandomStringArray(2, 5, false, false);
170-
if (randomBoolean()) {
171-
builder.array("types", types);
172-
} else {
173-
builder.field("types", Strings.arrayToCommaDelimitedString(types));
174-
}
175-
}
176-
177160
IndicesOptions indicesOptions = WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS;
178161
if (randomBoolean()) {
179162
indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
@@ -240,12 +223,6 @@ public void testDeserializeSearchRequest() throws Exception {
240223
assertThat(result.getTemplate().getParams(), equalTo(template.getParams()));
241224
assertThat(result.getTemplate().getLang(), equalTo(stored ? null : "mustache"));
242225
}
243-
if (types == Strings.EMPTY_ARRAY) {
244-
assertNull(result.getTypes());
245-
} else {
246-
assertThat(result.getTypes(), arrayContainingInAnyOrder(types));
247-
assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);
248-
}
249226
}
250227

251228
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,6 @@ public void testDefaultHitCountsConfigured() throws IOException {
3939
assertHitCount(source, hitCountsAsInt);
4040
}
4141

42-
public void testDeprecationForSingleType() throws IOException {
43-
String source = "{\"types\":\"mytype\"}";
44-
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
45-
parser.nextToken();
46-
WatcherSearchTemplateRequest.fromXContent(parser, SearchType.QUERY_THEN_FETCH);
47-
}
48-
assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);
49-
}
50-
51-
public void testDeprecationForMultiType() throws IOException {
52-
String source = "{\"types\":[\"mytype1\",\"mytype2\"]}";
53-
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
54-
parser.nextToken();
55-
WatcherSearchTemplateRequest.fromXContent(parser, SearchType.QUERY_THEN_FETCH);
56-
}
57-
assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);
58-
}
59-
6042
private void assertHitCount(String source, boolean expectedHitCountAsInt) throws IOException {
6143
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
6244
parser.nextToken();

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static WatcherSearchTemplateRequest templateRequest(SearchSourceBuilder s
9292
try {
9393
XContentBuilder xContentBuilder = jsonBuilder();
9494
xContentBuilder.value(sourceBuilder);
95-
return new WatcherSearchTemplateRequest(indices, null, searchType,
95+
return new WatcherSearchTemplateRequest(indices, searchType,
9696
WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, BytesReference.bytes(xContentBuilder));
9797
} catch (IOException e) {
9898
throw new RuntimeException(e);

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public void testConditionSearchWithIndexedTemplate() throws Exception {
223223
.get());
224224

225225
Script template = new Script(ScriptType.STORED, null, "my-template", Collections.emptyMap());
226-
WatcherSearchTemplateRequest searchRequest = new WatcherSearchTemplateRequest(new String[]{"events"}, new String[0],
226+
WatcherSearchTemplateRequest searchRequest = new WatcherSearchTemplateRequest(new String[]{"events"},
227227
SearchType.DEFAULT, WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, template);
228228
testConditionSearch(searchRequest);
229229
}

0 commit comments

Comments
 (0)