diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml index 385f2e9da65..9c861e3dcd8 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml @@ -25,8 +25,7 @@ "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/20_ack_individual_action.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/20_ack_individual_action.yml index b59fd561a75..813e1f0c888 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/20_ack_individual_action.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/20_ack_individual_action.yml @@ -25,8 +25,7 @@ "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/30_reset_ack_after_unmet_condition.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/30_reset_ack_after_unmet_condition.yml index 2f3a8153464..2a9a4959de4 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/30_reset_ack_after_unmet_condition.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/30_reset_ack_after_unmet_condition.yml @@ -38,7 +38,6 @@ teardown: "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "my-type", "doc_id": "my-id" } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/40_reset_ack_after_unmet_action_condition.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/40_reset_ack_after_unmet_action_condition.yml index 93639163ac0..946f23a2f5a 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/40_reset_ack_after_unmet_action_condition.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/40_reset_ack_after_unmet_action_condition.yml @@ -38,7 +38,6 @@ teardown: }, "index" : { "index" : "my_test_index", - "doc_type" : "my-type", "doc_id": "my-id" } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml index 221887494c5..99459119e3c 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml @@ -25,8 +25,7 @@ "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml index 44d4e187e3f..d22b66f85d1 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml @@ -38,8 +38,7 @@ teardown: "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml index b3ad1e6d545..1fd3c06b2ee 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml @@ -33,7 +33,6 @@ teardown: "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "my-type", "doc_id": "my-id" } } @@ -87,7 +86,6 @@ teardown: "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "my-type", "doc_id": "my-id" } } @@ -130,7 +128,6 @@ teardown: "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "my-type", "refresh" : "wait_for", "doc_id": "my-id" } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/20_transform.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/20_transform.yml index 59ebacbfe90..3766cb6c4a7 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/20_transform.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/20_transform.yml @@ -9,7 +9,6 @@ setup: - do: index: index: my_test_index - type: doc id: my_id refresh: true body: > @@ -49,7 +48,6 @@ setup: "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "doc", "doc_id": "my-id" } } @@ -64,7 +62,6 @@ setup: - do: get: index: my_test_index - type: doc id: my_id - match: { _source.key: "value" } @@ -82,7 +79,6 @@ setup: - do: index: index: my_test_index - type: doc id: my_id refresh: true body: > @@ -123,7 +119,6 @@ setup: "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "doc", "doc_id": "my-id" } } @@ -138,7 +133,6 @@ setup: - do: get: index: my_test_index - type: doc id: my_id - match: { _source.key: "value" } @@ -183,7 +177,6 @@ setup: "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "doc", "doc_id": "my-id" } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/70_invalid.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/70_invalid.yml index fc8687eb699..f13c5faf599 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/70_invalid.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/70_invalid.yml @@ -38,7 +38,6 @@ "indexme" : { "index" : { "index" : "my_test_index", - "doc_type" : "my-type", "doc_id": "my-id" } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml index 180b72f2ba4..3ae54923287 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml @@ -38,8 +38,7 @@ teardown: "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/20_missing.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/20_missing.yml index ee4fd2e7e43..fc795005ac8 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/20_missing.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/20_missing.yml @@ -30,8 +30,7 @@ "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/10_basic.yml index b2ea5b8042f..78d1b6e65e6 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/10_basic.yml @@ -29,8 +29,7 @@ "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/20_put_watch_with_throttle_period.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/20_put_watch_with_throttle_period.yml index 14bd682bd02..ab8d852dab3 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/20_put_watch_with_throttle_period.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/20_put_watch_with_throttle_period.yml @@ -39,8 +39,7 @@ teardown: "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/30_put_watch_with_action_throttle_period.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/30_put_watch_with_action_throttle_period.yml index db4013bc38a..a48d667066e 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/30_put_watch_with_action_throttle_period.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/30_put_watch_with_action_throttle_period.yml @@ -39,8 +39,7 @@ teardown: "test_index": { "throttle_period" : "10s", "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/40_put_watch_as_inactive.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/40_put_watch_as_inactive.yml index 23075ecfa79..47b27d6b9be 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/40_put_watch_as_inactive.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/40_put_watch_as_inactive.yml @@ -39,8 +39,7 @@ teardown: "actions": { "test_index": { "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/60_put_watch_with_action_condition.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/60_put_watch_with_action_condition.yml index 670a64381d0..bc26a60e470 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/60_put_watch_with_action_condition.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/60_put_watch_with_action_condition.yml @@ -43,8 +43,7 @@ teardown: } }, "index": { - "index": "test", - "doc_type": "test2" + "index": "test" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/70_put_watch_with_index_action_using_id.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/70_put_watch_with_index_action_using_id.yml index 50420c1e4ee..7bad6c8f1ee 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/70_put_watch_with_index_action_using_id.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/70_put_watch_with_index_action_using_id.yml @@ -37,7 +37,6 @@ teardown: "test_index": { "index": { "index": "my_test_index", - "doc_type": "test2", "doc_id": "test_id1" } } @@ -86,8 +85,7 @@ teardown: "actions": { "test_index": { "index": { - "index": "my_test_index", - "doc_type": "test2" + "index": "my_test_index" } } } @@ -143,8 +141,7 @@ teardown: "actions": { "test_index": { "index": { - "index": "my_test_index", - "doc_type": "test2" + "index": "my_test_index" } } } @@ -202,8 +199,7 @@ teardown: "actions": { "test_index": { "index": { - "index": "my_test_index", - "doc_type": "test2" + "index": "my_test_index" } } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/91_search_total_hits_as_int.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/91_search_total_hits_as_int.yml index 46986438ee4..eba7f75a759 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/91_search_total_hits_as_int.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/91_search_total_hits_as_int.yml @@ -7,7 +7,6 @@ setup: - do: index: index: my_test_index - type: doc id: my_id refresh: true body: > @@ -97,7 +96,6 @@ setup: }, "index" : { "index" : "my_test_index", - "doc_type" : "doc", "doc_id": "my-id" } } @@ -108,7 +106,6 @@ setup: - do: get: index: my_test_index - type: doc id: my_id - match: { _source.key: "value" } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java index ceb6ac88f17..1b9bc373aae 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java @@ -5,10 +5,12 @@ */ package org.elasticsearch.xpack.watcher.actions.index; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -34,6 +36,9 @@ public class IndexAction implements Action { @Nullable final DateTimeZone dynamicNameTimeZone; @Nullable final RefreshPolicy refreshPolicy; + private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(IndexAction.class)); + public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in a watcher index action is deprecated."; + public IndexAction(@Nullable String index, @Nullable String docType, @Nullable String docId, @Nullable String executionTimeField, @Nullable TimeValue timeout, @Nullable DateTimeZone dynamicNameTimeZone, @Nullable RefreshPolicy refreshPolicy) { @@ -151,6 +156,7 @@ public class IndexAction implements Action { } } else if (token == XContentParser.Token.VALUE_STRING) { if (Field.DOC_TYPE.match(currentFieldName, parser.getDeprecationHandler())) { + deprecationLogger.deprecatedAndMaybeLog("watcher_index_action", TYPES_DEPRECATION_MESSAGE); docType = parser.text(); } else if (Field.DOC_ID.match(currentFieldName, parser.getDeprecationHandler())) { docId = parser.text(); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java index 245093f3b38..670f4ffe668 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.watcher.support.search; +import org.apache.logging.log4j.LogManager; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.support.IndicesOptions; @@ -13,6 +14,7 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -43,6 +45,10 @@ public class WatcherSearchTemplateRequest implements ToXContentObject { private final BytesReference searchSource; private boolean restTotalHitsAsInt = true; + private static final DeprecationLogger deprecationLogger = + new DeprecationLogger(LogManager.getLogger(WatcherSearchTemplateRequest.class)); + public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in a watcher search request is deprecated."; + public WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType searchType, IndicesOptions indicesOptions, BytesReference searchSource) { this.indices = indices; @@ -203,6 +209,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject { } } } else if (TYPES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { + deprecationLogger.deprecatedAndMaybeLog("watcher_search_input", TYPES_DEPRECATION_MESSAGE); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { types.add(parser.textOrNull()); @@ -278,6 +285,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject { String indicesStr = parser.text(); indices.addAll(Arrays.asList(Strings.delimitedListToStringArray(indicesStr, ",", " \t"))); } else if (TYPES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { + deprecationLogger.deprecatedAndMaybeLog("watcher_search_input", TYPES_DEPRECATION_MESSAGE); String typesStr = parser.text(); types.addAll(Arrays.asList(Strings.delimitedListToStringArray(typesStr, ",", " \t"))); } else if (SEARCH_TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { @@ -305,7 +313,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject { } WatcherSearchTemplateRequest request = new WatcherSearchTemplateRequest(indices.toArray(new String[0]), - types.toArray(new String[0]), searchType, indicesOptions, searchSource, template); + types.size() == 0 ? null : types.toArray(new String[0]), searchType, indicesOptions, searchSource, template); request.setRestTotalHitsAsInt(totalHitsAsInt); return request; } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java index 4cc3b0cb709..d86a63948c7 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java @@ -57,7 +57,9 @@ public class WatcherSearchTemplateService { public SearchRequest toSearchRequest(WatcherSearchTemplateRequest request) throws IOException { SearchRequest searchRequest = new SearchRequest(request.getIndices()); - searchRequest.types(request.getTypes()); + if (request.getTypes() != null) { + searchRequest.types(request.getTypes()); + } searchRequest.searchType(request.getSearchType()); searchRequest.indicesOptions(request.getIndicesOptions()); SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java index 346b2d0e85c..85f17fbd0e8 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java @@ -78,7 +78,6 @@ public class IndexActionTests extends ESTestCase { if (includeIndex) { builder.field(IndexAction.Field.INDEX.getPreferredName(), "test-index"); } - builder.field(IndexAction.Field.DOC_TYPE.getPreferredName(), "test-type"); if (timestampField != null) { builder.field(IndexAction.Field.EXECUTION_TIME_FIELD.getPreferredName(), timestampField); } @@ -93,7 +92,6 @@ public class IndexActionTests extends ESTestCase { ExecutableIndexAction executable = actionParser.parseExecutable(randomAlphaOfLength(5), randomAlphaOfLength(3), parser); - assertThat(executable.action().docType, equalTo("test-type")); if (includeIndex) { assertThat(executable.action().index, equalTo("test-index")); } @@ -103,6 +101,19 @@ public class IndexActionTests extends ESTestCase { assertThat(executable.action().timeout, equalTo(writeTimeout)); } + public void testDeprecationTypes() throws Exception { + XContentBuilder builder = jsonBuilder(); + builder.startObject(); + builder.field(IndexAction.Field.DOC_TYPE.getPreferredName(), "test-type"); + builder.endObject(); + IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, client); + XContentParser parser = createParser(builder); + parser.nextToken(); + ExecutableIndexAction executable = actionParser.parseExecutable(randomAlphaOfLength(5), randomAlphaOfLength(3), parser); + assertThat(executable.action().docType, equalTo("test-type")); + assertWarnings(IndexAction.TYPES_DEPRECATION_MESSAGE); + } + public void testParserFailure() throws Exception { // wrong type for field expectParseFailure(jsonBuilder() diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java index 401d101a469..7aab1d4d145 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java @@ -90,7 +90,7 @@ public class WatcherUtilsTests extends ESTestCase { public void testSerializeSearchRequest() throws Exception { String[] expectedIndices = generateRandomStringArray(5, 5, true); - String[] expectedTypes = generateRandomStringArray(2, 5, true); + String[] expectedTypes = generateRandomStringArray(2, 5, true, false); IndicesOptions expectedIndicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS); SearchType expectedSearchType = getRandomSupportedSearchType(); @@ -129,7 +129,6 @@ public class WatcherUtilsTests extends ESTestCase { WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(parser, DEFAULT_SEARCH_TYPE); assertThat(result.getIndices(), arrayContainingInAnyOrder(expectedIndices != null ? expectedIndices : new String[0])); - assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes != null ? expectedTypes : new String[0])); assertThat(result.getIndicesOptions(), equalTo(expectedIndicesOptions)); assertThat(result.getSearchType(), equalTo(expectedSearchType)); @@ -143,6 +142,12 @@ public class WatcherUtilsTests extends ESTestCase { assertThat(result.getTemplate().getIdOrCode(), equalTo(expectedSource.utf8ToString())); assertThat(result.getTemplate().getType(), equalTo(ScriptType.INLINE)); } + if (expectedTypes == null) { + assertNull(result.getTypes()); + } else { + assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes)); + assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE); + } } public void testDeserializeSearchRequest() throws Exception { @@ -161,7 +166,7 @@ public class WatcherUtilsTests extends ESTestCase { String[] types = Strings.EMPTY_ARRAY; if (randomBoolean()) { - types = generateRandomStringArray(2, 5, false); + types = generateRandomStringArray(2, 5, false, false); if (randomBoolean()) { builder.array("types", types); } else { @@ -220,7 +225,6 @@ public class WatcherUtilsTests extends ESTestCase { WatcherSearchTemplateRequest result = WatcherSearchTemplateRequest.fromXContent(parser, DEFAULT_SEARCH_TYPE); assertThat(result.getIndices(), arrayContainingInAnyOrder(indices)); - assertThat(result.getTypes(), arrayContainingInAnyOrder(types)); assertThat(result.getIndicesOptions(), equalTo(indicesOptions)); assertThat(result.getSearchType(), equalTo(searchType)); if (source == null) { @@ -236,6 +240,12 @@ public class WatcherUtilsTests extends ESTestCase { assertThat(result.getTemplate().getParams(), equalTo(template.getParams())); assertThat(result.getTemplate().getLang(), equalTo(stored ? null : "mustache")); } + if (types == Strings.EMPTY_ARRAY) { + assertNull(result.getTypes()); + } else { + assertThat(result.getTypes(), arrayContainingInAnyOrder(types)); + assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE); + } } } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java index 07fd3c77654..c535e103682 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java @@ -39,6 +39,24 @@ public class WatcherSearchTemplateRequestTests extends ESTestCase { assertHitCount(source, hitCountsAsInt); } + public void testDeprecationForSingleType() throws IOException { + String source = "{\"types\":\"mytype\"}"; + try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) { + parser.nextToken(); + WatcherSearchTemplateRequest.fromXContent(parser, SearchType.QUERY_THEN_FETCH); + } + assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE); + } + + public void testDeprecationForMultiType() throws IOException { + String source = "{\"types\":[\"mytype1\",\"mytype2\"]}"; + try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) { + parser.nextToken(); + WatcherSearchTemplateRequest.fromXContent(parser, SearchType.QUERY_THEN_FETCH); + } + assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE); + } + private void assertHitCount(String source, boolean expectedHitCountAsInt) throws IOException { try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) { parser.nextToken(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java index bb5a6eabdd5..e22d3d6f083 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java @@ -89,7 +89,7 @@ public final class WatcherTestUtils { try { XContentBuilder xContentBuilder = jsonBuilder(); xContentBuilder.value(sourceBuilder); - return new WatcherSearchTemplateRequest(indices, new String[0], searchType, + return new WatcherSearchTemplateRequest(indices, null, searchType, WatcherSearchTemplateRequest.DEFAULT_INDICES_OPTIONS, BytesReference.bytes(xContentBuilder)); } catch (IOException e) { throw new RuntimeException(e); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java index daf1f18f3bd..cb32c3eebec 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java @@ -586,7 +586,7 @@ public class WatchTests extends ESTestCase { DateTimeZone timeZone = randomBoolean() ? DateTimeZone.UTC : null; TimeValue timeout = randomBoolean() ? timeValueSeconds(between(1, 10000)) : null; WriteRequest.RefreshPolicy refreshPolicy = randomBoolean() ? null : randomFrom(WriteRequest.RefreshPolicy.values()); - IndexAction action = new IndexAction("_index", "_type", randomBoolean() ? "123" : null, null, timeout, timeZone, + IndexAction action = new IndexAction("_index", null, randomBoolean() ? "123" : null, null, timeout, timeZone, refreshPolicy); list.add(new ActionWrapper("_index_" + randomAlphaOfLength(8), randomThrottler(), AlwaysConditionTests.randomCondition(scriptService), randomTransform(), diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java index e52a6dd3b43..d1aefb40008 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java @@ -24,9 +24,11 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase; import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder; import org.elasticsearch.xpack.security.support.SecurityIndexManager; +import org.elasticsearch.xpack.watcher.actions.index.IndexAction; import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction; import org.elasticsearch.xpack.watcher.common.text.TextTemplate; import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; +import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest; import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule; import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger; import org.hamcrest.Matcher; @@ -193,7 +195,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { logger.info("checking that upgrade procedure on the new cluster is no longer required"); Map responseAfter = entityAsMap(client().performRequest( - new Request("GET", "/_migration/assistance"))); + new Request("GET", "/_migration/assistance"))); @SuppressWarnings("unchecked") Map indicesAfter = (Map) responseAfter.get("indices"); assertNull(indicesAfter.get(".watches")); } else { @@ -207,7 +209,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { Map statsWatchResponse = entityAsMap(client().performRequest(new Request("GET", "_watcher/stats"))); @SuppressWarnings("unchecked") List states = ((List) statsWatchResponse.get("stats")) - .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); + .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); assertThat(states, everyItem(is("started"))); }); @@ -223,10 +225,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(stopWatchResponse.get("acknowledged"), equalTo(Boolean.TRUE)); assertBusy(() -> { Map statsStoppedWatchResponse = entityAsMap(client().performRequest( - new Request("GET", "_watcher/stats"))); + new Request("GET", "_watcher/stats"))); @SuppressWarnings("unchecked") List states = ((List) statsStoppedWatchResponse.get("stats")) - .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); + .stream().map(o -> ((Map) o).get("watcher_state")).collect(Collectors.toList()); assertThat(states, everyItem(is("stopped"))); }); } @@ -456,7 +458,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { @SuppressWarnings("unchecked") private void assertWatchIndexContentsWork() throws Exception { // Fetch a basic watch - Map bwcWatch = entityAsMap(client().performRequest(new Request("GET", "_watcher/watch/bwc_watch"))); + Request getRequest = new Request("GET", "_watcher/watch/bwc_watch"); + getRequest.setOptions(expectWarnings(IndexAction.TYPES_DEPRECATION_MESSAGE, + WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE)); + Map bwcWatch = entityAsMap(client().performRequest(getRequest)); logger.error("-----> {}", bwcWatch); @@ -467,11 +472,13 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { assertThat(ObjectPath.eval("input.search.timeout_in_millis", source), equalTo(timeout)); assertThat(ObjectPath.eval("actions.index_payload.transform.search.timeout_in_millis", source), equalTo(timeout)); assertThat(ObjectPath.eval("actions.index_payload.index.index", source), equalTo("bwc_watch_index")); - assertThat(ObjectPath.eval("actions.index_payload.index.doc_type", source), equalTo("bwc_watch_type")); assertThat(ObjectPath.eval("actions.index_payload.index.timeout_in_millis", source), equalTo(timeout)); // Fetch a watch with "fun" throttle periods - bwcWatch = entityAsMap(client().performRequest(new Request("GET", "_watcher/watch/bwc_throttle_period"))); + getRequest = new Request("GET", "_watcher/watch/bwc_throttle_period"); + getRequest.setOptions(expectWarnings(IndexAction.TYPES_DEPRECATION_MESSAGE, + WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE)); + bwcWatch = entityAsMap(client().performRequest(getRequest)); assertThat(bwcWatch.get("found"), equalTo(true)); source = (Map) bwcWatch.get("watch"); assertEquals(timeout, source.get("throttle_period_in_millis")); diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml index f1f6ab88637..84d8d98e273 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml @@ -110,7 +110,6 @@ setup: - do: index: index: foobar - type: type id: 1 body: > { @@ -119,7 +118,6 @@ setup: - do: index: index: foobar - type: type id: 2 body: > { diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml index 0011fa7b444..2f4755943aa 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml @@ -110,7 +110,6 @@ setup: - do: index: index: foobar - type: type id: 1 body: > { @@ -119,7 +118,6 @@ setup: - do: index: index: foobar - type: type id: 2 body: > { diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml index a8fa79a04fc..4c4e673cd29 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml @@ -88,7 +88,6 @@ teardown: Authorization: "Basic am9lOngtcGFjay10ZXN0LXBhc3N3b3Jk" index: index: shared_logs - type: type pipeline: "my_pipeline" body: > { @@ -99,7 +98,6 @@ teardown: Authorization: "Basic am9objp4LXBhY2stdGVzdC1wYXNzd29yZA==" index: index: shared_logs - type: type pipeline: "my_pipeline" body: > { @@ -158,7 +156,6 @@ teardown: Authorization: "Basic am9lOngtcGFjay10ZXN0LXBhc3N3b3Jk" index: index: shared_logs - type: type pipeline: "my_pipeline" body: > { @@ -169,7 +166,6 @@ teardown: Authorization: "Basic am9objp4LXBhY2stdGVzdC1wYXNzd29yZA==" index: index: shared_logs - type: type pipeline: "my_pipeline" body: > { diff --git a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml index 913979a4bb5..a208bda67cf 100644 --- a/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml +++ b/x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml @@ -32,7 +32,6 @@ setup: - do: index: index: foobar - type: type id: 1 body: title: "contains some words" @@ -40,7 +39,6 @@ setup: - do: index: index: unauthorized_index - type: type id: 2 body: title: "contains some words too" diff --git a/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml b/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml index bd0d32ef9cc..ec0be2532a6 100644 --- a/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml +++ b/x-pack/qa/smoke-test-watcher-with-security/src/test/resources/rest-api-spec/test/watcher/watcher_and_security/20_test_run_as_execute_watch.yml @@ -8,7 +8,6 @@ setup: - do: index: index: my_test_index - type: type id: 1 refresh: true body: > @@ -220,7 +219,6 @@ teardown: "index": { "index": { "index" : "my_test_index", - "doc_type" : "type", "doc_id": "my-id" } } @@ -236,7 +234,6 @@ teardown: - do: get: index: my_test_index - type: type id: my-id # this value is from the document in the my_text_index index, see the setup - match: { _source.hits.hits.0._source.value: "15" } @@ -272,7 +269,6 @@ teardown: "index": { "index": { "index" : "my_test_index", - "doc_type" : "type", "doc_id": "my-id" } } @@ -288,7 +284,6 @@ teardown: - do: get: index: my_test_index - type: type id: my-id - match: { _source.hits.total: 0 } @@ -315,7 +310,6 @@ teardown: "index": { "index": { "index" : "my_test_index", - "doc_type" : "type", "doc_id": "my-id" } } @@ -339,7 +333,6 @@ teardown: - do: get: index: my_test_index - type: type id: 1 - match: { _id: "1" } @@ -366,7 +359,6 @@ teardown: "index": { "index": { "index" : "index_not_allowed_to_read", - "doc_type" : "type", "doc_id": "my-id" } } @@ -390,7 +382,6 @@ teardown: - do: get: index: index_not_allowed_to_read - type: type id: 1 catch: forbidden diff --git a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/60_chain_input_with_transform.yml b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/60_chain_input_with_transform.yml index 08097e0cace..69fd7b4d575 100644 --- a/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/60_chain_input_with_transform.yml +++ b/x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/60_chain_input_with_transform.yml @@ -34,7 +34,6 @@ "index" : { "index" : { "index" : "my-index", - "doc_type" : "my-type", "doc_id" : "my-id" } } @@ -47,7 +46,6 @@ - do: get: index: my-index - type: my-type id: my-id - match: { _source.first.foo: "bar" }