Selaa lähdekoodia

deprecate types for watcher (#37594)

This commit adds deprecation warnings for index actions
and search actions when executed via watcher. Unit and 
integration tests updated accordingly. 

relates #35190
Jake Landis 6 vuotta sitten
vanhempi
commit
99b75a9bdf
33 muutettua tiedostoa jossa 93 lisäystä ja 83 poistoa
  1. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/10_basic.yml
  2. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/20_ack_individual_action.yml
  3. 0 1
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/30_reset_ack_after_unmet_condition.yml
  4. 0 1
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/ack_watch/40_reset_ack_after_unmet_action_condition.yml
  5. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/activate_watch/10_basic.yml
  6. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/delete_watch/10_basic.yml
  7. 0 3
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yml
  8. 0 7
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/20_transform.yml
  9. 0 1
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/70_invalid.yml
  10. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/10_basic.yml
  11. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/get_watch/20_missing.yml
  12. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/10_basic.yml
  13. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/20_put_watch_with_throttle_period.yml
  14. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/30_put_watch_with_action_throttle_period.yml
  15. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/40_put_watch_as_inactive.yml
  16. 1 2
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/60_put_watch_with_action_condition.yml
  17. 3 7
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/70_put_watch_with_index_action_using_id.yml
  18. 0 3
      x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/put_watch/91_search_total_hits_as_int.yml
  19. 6 0
      x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java
  20. 9 1
      x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java
  21. 3 1
      x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateService.java
  22. 13 2
      x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java
  23. 14 4
      x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java
  24. 18 0
      x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequestTests.java
  25. 1 1
      x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java
  26. 1 1
      x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java
  27. 14 7
      x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java
  28. 0 2
      x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/10_templated_role_query.yml
  29. 0 2
      x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/11_templated_role_query_runas.yml
  30. 0 4
      x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/20_small_users_one_index.yml
  31. 0 2
      x-pack/qa/smoke-test-security-with-mustache/src/test/resources/rest-api-spec/test/30_search_template.yml
  32. 0 9
      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
  33. 0 2
      x-pack/qa/smoke-test-watcher/src/test/resources/rest-api-spec/test/painless/60_chain_input_with_transform.yml

+ 1 - 2
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"
                 }
               }
             }

+ 1 - 2
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"
                 }
               }
             }

+ 0 - 1
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"
                 }
               }

+ 0 - 1
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"
                 }
               }

+ 1 - 2
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"
                 }
               }
             }

+ 1 - 2
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"
                 }
               }
             }

+ 0 - 3
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"
                 }

+ 0 - 7
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"
                   }
                 }

+ 0 - 1
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"
                 }
               }

+ 1 - 2
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"
                   }
                 }
               }

+ 1 - 2
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"
                   }
                 }
               }

+ 1 - 2
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"
                 }
               }
             }

+ 1 - 2
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"
                 }
               }
             }

+ 1 - 2
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"
                 }
               }
             }

+ 1 - 2
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"
                 }
               }
             }

+ 1 - 2
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"
                 }
               }
             }

+ 3 - 7
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"
                 }
               }
             }

+ 0 - 3
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" }

+ 6 - 0
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();

+ 9 - 1
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;
     }

+ 3 - 1
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();

+ 13 - 2
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()

+ 14 - 4
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);
+        }
     }
 
 }

+ 18 - 0
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();

+ 1 - 1
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);

+ 1 - 1
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(),

+ 14 - 7
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<String, Object> responseAfter = entityAsMap(client().performRequest(
-                        new Request("GET", "/_migration/assistance")));
+                    new Request("GET", "/_migration/assistance")));
                 @SuppressWarnings("unchecked") Map<String, Object> indicesAfter = (Map<String, Object>) responseAfter.get("indices");
                 assertNull(indicesAfter.get(".watches"));
             } else {
@@ -207,7 +209,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
                 Map<String, Object> statsWatchResponse = entityAsMap(client().performRequest(new Request("GET", "_watcher/stats")));
                 @SuppressWarnings("unchecked")
                 List<Object> states = ((List<Object>) statsWatchResponse.get("stats"))
-                        .stream().map(o -> ((Map<String, Object>) o).get("watcher_state")).collect(Collectors.toList());
+                    .stream().map(o -> ((Map<String, Object>) 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<String, Object> statsStoppedWatchResponse = entityAsMap(client().performRequest(
-                            new Request("GET", "_watcher/stats")));
+                        new Request("GET", "_watcher/stats")));
                     @SuppressWarnings("unchecked")
                     List<Object> states = ((List<Object>) statsStoppedWatchResponse.get("stats"))
-                            .stream().map(o -> ((Map<String, Object>) o).get("watcher_state")).collect(Collectors.toList());
+                        .stream().map(o -> ((Map<String, Object>) 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<String, Object> 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<String, Object> 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<String, Object>) bwcWatch.get("watch");
         assertEquals(timeout, source.get("throttle_period_in_millis"));

+ 0 - 2
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:  >
           {

+ 0 - 2
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:  >
           {

+ 0 - 4
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:  >
           {

+ 0 - 2
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"

+ 0 - 9
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
 

+ 0 - 2
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" }