Browse Source

Remove CreateIndexRequest.addMapping(type, string, xcontenttype) (#50419)

We still have a number of places, mainly in test code but some in production, that
are building mappings with a named type as the root of a map. CreateIndexRequest
handles this automatically, but PutMappingRequest does not, which is a bit trappy -
we can get situations like #50359 where the same mapping will work when an
index is created but fail on an update.

This commit is a first step to removing the leniency in CreateIndexRequest so that
we can catch mappings with a named type root earlier.

Relates to #41059
Alan Woodward 5 years ago
parent
commit
418edc6658
34 changed files with 116 additions and 224 deletions
  1. 0 11
      server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java
  2. 2 4
      server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java
  3. 2 26
      server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestTests.java
  4. 1 2
      server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java
  5. 3 4
      server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java
  6. 2 5
      server/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java
  7. 6 7
      server/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java
  8. 2 3
      server/src/test/java/org/elasticsearch/get/GetActionIT.java
  9. 3 4
      server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java
  10. 3 3
      server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java
  11. 2 3
      server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java
  12. 3 5
      server/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateIT.java
  13. 4 4
      server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java
  14. 1 4
      server/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java
  15. 3 6
      server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java
  16. 2 4
      server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java
  17. 2 3
      server/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java
  18. 3 4
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java
  19. 1 2
      server/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java
  20. 2 6
      server/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java
  21. 2 5
      server/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java
  22. 6 7
      server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java
  23. 1 3
      server/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java
  24. 11 11
      server/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java
  25. 14 14
      server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java
  26. 9 9
      server/src/test/java/org/elasticsearch/search/geo/LegacyGeoShapeIntegrationIT.java
  27. 4 24
      server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java
  28. 4 6
      server/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java
  29. 2 6
      server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java
  30. 2 5
      server/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java
  31. 2 7
      server/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java
  32. 10 13
      x-pack/plugin/ml/src/test/java/org/elasticsearch/license/MachineLearningLicensingTests.java
  33. 1 1
      x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java
  34. 1 3
      x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java

+ 0 - 11
server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java

@@ -231,17 +231,6 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
         return this;
     }
 
-    /**
-     * Adds mapping that will be added when the index gets created.
-     *
-     * @param type   The mapping type
-     * @param source The mapping source
-     * @param xContentType The content type of the source
-     */
-    public CreateIndexRequest mapping(String type, String source, XContentType xContentType) {
-        return mapping(type, new BytesArray(source), xContentType);
-    }
-
     /**
      * Adds mapping that will be added when the index gets created.
      *

+ 2 - 4
server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java

@@ -96,12 +96,10 @@ public class CreateIndexRequestBuilder
     /**
      * Adds mapping that will be added when the index gets created.
      *
-     * @param type   The mapping type
      * @param source The mapping source
-     * @param xContentType The content type of the source
      */
-    public CreateIndexRequestBuilder addMapping(String type, String source, XContentType xContentType) {
-        request.mapping(type, source, xContentType);
+    public CreateIndexRequestBuilder setMapping(String source) {
+        request.mapping(source);
         return this;
     }
 

+ 2 - 26
server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestTests.java

@@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.indices.create;
 import org.elasticsearch.ElasticsearchParseException;
 import org.elasticsearch.action.admin.indices.alias.Alias;
 import org.elasticsearch.common.Strings;
-import org.elasticsearch.common.collect.MapBuilder;
 import org.elasticsearch.common.io.stream.BytesStreamOutput;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
@@ -44,8 +43,8 @@ public class CreateIndexRequestTests extends ESTestCase {
 
     public void testSerialization() throws IOException {
         CreateIndexRequest request = new CreateIndexRequest("foo");
-        String mapping = Strings.toString(JsonXContent.contentBuilder().startObject().startObject("my_type").endObject().endObject());
-        request.mapping("my_type", mapping, XContentType.JSON);
+        String mapping = Strings.toString(JsonXContent.contentBuilder().startObject().startObject("_doc").endObject().endObject());
+        request.mapping(mapping);
 
         try (BytesStreamOutput output = new BytesStreamOutput()) {
             request.writeTo(output);
@@ -117,29 +116,6 @@ public class CreateIndexRequestTests extends ESTestCase {
             request2.mapping("type1", builder);
             assertEquals(request1.mappings(), request2.mappings());
         }
-        {
-            request1 = new CreateIndexRequest("foo");
-            request2 = new CreateIndexRequest("bar");
-            String nakedMapping = "{\"properties\": {\"foo\": {\"type\": \"integer\"}}}";
-            request1.mapping("type2", nakedMapping, XContentType.JSON);
-            request2.mapping("type2", "{\"type2\": " + nakedMapping + "}", XContentType.JSON);
-            assertEquals(request1.mappings(), request2.mappings());
-        }
-        {
-            request1 = new CreateIndexRequest("foo");
-            request2 = new CreateIndexRequest("bar");
-            Map<String , Object> nakedMapping = MapBuilder.<String, Object>newMapBuilder()
-                    .put("properties", MapBuilder.<String, Object>newMapBuilder()
-                            .put("bar", MapBuilder.<String, Object>newMapBuilder()
-                                    .put("type", "scaled_float")
-                                    .put("scaling_factor", 100)
-                            .map())
-                    .map())
-            .map();
-            request1.mapping("type3", nakedMapping);
-            request2.mapping("type3", MapBuilder.<String, Object>newMapBuilder().put("type3", nakedMapping).map());
-            assertEquals(request1.mappings(), request2.mappings());
-        }
     }
 
     public void testSettingsType() throws IOException {

+ 1 - 2
server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java

@@ -27,7 +27,6 @@ import org.elasticsearch.cluster.metadata.AliasMetaData;
 import org.elasticsearch.cluster.metadata.MappingMetaData;
 import org.elasticsearch.common.collect.ImmutableOpenMap;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.IndexNotFoundException;
 import org.elasticsearch.test.ESIntegTestCase;
 
@@ -51,7 +50,7 @@ import static org.hamcrest.Matchers.notNullValue;
 public class GetIndexIT extends ESIntegTestCase {
     @Override
     protected void setupSuiteScopeCluster() throws Exception {
-        assertAcked(prepareCreate("idx").addAlias(new Alias("alias_idx")).addMapping("type1", "{\"type1\":{}}", XContentType.JSON)
+        assertAcked(prepareCreate("idx").addAlias(new Alias("alias_idx"))
                 .setSettings(Settings.builder().put("number_of_shards", 1)).get());
         ensureSearchable("idx");
         createIndex("empty_idx");

+ 3 - 4
server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java

@@ -23,7 +23,6 @@ import org.apache.lucene.search.join.ScoreMode;
 import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
 import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.discovery.MasterNotDiscoveredException;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.node.Node;
@@ -141,9 +140,9 @@ public class SpecificMasterNodesIT extends ESIntegTestCase {
         internalCluster().startNode(Settings.builder()
             .put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false));
 
-        assertAcked(prepareCreate("test").addMapping(
-            "type1", "{\"type1\" : {\"properties\" : {\"table_a\" : { \"type\" : \"nested\", " +
-            "\"properties\" : {\"field_a\" : { \"type\" : \"keyword\" },\"field_b\" :{ \"type\" : \"keyword\" }}}}}}", XContentType.JSON));
+        assertAcked(prepareCreate("test").setMapping(
+            "{\"properties\" : {\"table_a\" : { \"type\" : \"nested\", " +
+            "\"properties\" : {\"field_a\" : { \"type\" : \"keyword\" },\"field_b\" :{ \"type\" : \"keyword\" }}}}}"));
         client().admin().indices().prepareAliases().addAlias("test", "a_test",
             QueryBuilders.nestedQuery("table_a", QueryBuilders.termQuery("table_a.field_b", "y"), ScoreMode.Avg)).get();
     }

+ 2 - 5
server/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java

@@ -46,7 +46,6 @@ import org.elasticsearch.common.CheckedConsumer;
 import org.elasticsearch.common.Priority;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.core.internal.io.IOUtils;
 import org.elasticsearch.env.NodeEnvironment;
 import org.elasticsearch.index.mapper.MapperParsingException;
@@ -424,16 +423,14 @@ public class GatewayIndexStateIT extends ESIntegTestCase {
         prepareCreate("test").setSettings(Settings.builder()
             .put("index.analysis.analyzer.test.tokenizer", "standard")
             .put("index.number_of_shards", "1"))
-            .addMapping("type1", "{\n" +
-                "    \"type1\": {\n" +
+            .setMapping("{\n" +
                 "      \"properties\": {\n" +
                 "        \"field1\": {\n" +
                 "          \"type\": \"text\",\n" +
                 "          \"analyzer\": \"test\"\n" +
                 "        }\n" +
                 "      }\n" +
-                "    }\n" +
-                "  }}", XContentType.JSON).get();
+                "  }}").get();
         logger.info("--> indexing a simple document");
         client().prepareIndex("test").setId("1").setSource("field1", "value one").setRefreshPolicy(IMMEDIATE).get();
         logger.info("--> waiting for green status");

+ 6 - 7
server/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java

@@ -37,7 +37,6 @@ import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.env.NodeEnvironment;
 import org.elasticsearch.index.Index;
 import org.elasticsearch.index.IndexService;
@@ -98,10 +97,10 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
 
         internalCluster().startNode();
 
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
-            .startObject("properties").startObject("appAccountIds").field("type", "text").endObject().endObject()
+        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
+            .startObject("properties").startObject("appAccountIds").field("type", "text").endObject()
             .endObject().endObject());
-        assertAcked(prepareCreate("test").addMapping("type1", mapping, XContentType.JSON));
+        assertAcked(prepareCreate("test").setMapping(mapping));
 
         client().prepareIndex("test").setId("10990239").setSource(jsonBuilder().startObject()
             .startArray("appAccountIds").value(14).value(179).endArray().endObject()).execute().actionGet();
@@ -168,14 +167,14 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
     public void testSingleNodeNoFlush() throws Exception {
         internalCluster().startNode();
 
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
+        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
             .startObject("properties").startObject("field").field("type", "text").endObject().startObject("num").field("type", "integer")
-            .endObject().endObject()
+            .endObject()
             .endObject().endObject());
         // note: default replica settings are tied to #data nodes-1 which is 0 here. We can do with 1 in this test.
         int numberOfShards = numberOfShards();
         assertAcked(prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, numberOfShards())
-            .put(SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 1))).addMapping("type1", mapping, XContentType.JSON));
+            .put(SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 1))).setMapping(mapping));
 
         int value1Docs;
         int value2Docs;

+ 2 - 3
server/src/test/java/org/elasticsearch/get/GetActionIT.java

@@ -271,13 +271,12 @@ public class GetActionIT extends ESIntegTestCase {
     }
 
     public void testGetDocWithMultivaluedFields() throws Exception {
-        String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
+        String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject()
                 .startObject("properties")
                 .startObject("field").field("type", "text").field("store", true).endObject()
-                .endObject()
                 .endObject().endObject());
         assertAcked(prepareCreate("test")
-                .addMapping("type1", mapping1, XContentType.JSON));
+                .setMapping(mapping1));
         ensureGreen();
 
         GetResponse response = client().prepareGet("test", "1").get();

+ 3 - 4
server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java

@@ -23,7 +23,6 @@ import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
 import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
@@ -70,15 +69,15 @@ public class CopyToMapperIntegrationIT extends ESIntegTestCase {
     }
 
     public void testDynamicObjectCopyTo() throws Exception {
-        String mapping = Strings.toString(jsonBuilder().startObject().startObject("_doc").startObject("properties")
+        String mapping = Strings.toString(jsonBuilder().startObject().startObject("properties")
             .startObject("foo")
                 .field("type", "text")
                 .field("copy_to", "root.top.child")
             .endObject()
-            .endObject().endObject().endObject());
+            .endObject().endObject());
         assertAcked(
             client().admin().indices().prepareCreate("test-idx")
-                .addMapping("_doc", mapping, XContentType.JSON)
+                .setMapping(mapping)
         );
         client().prepareIndex("test-idx").setId("1")
             .setSource("foo", "bar")

+ 3 - 3
server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java

@@ -337,16 +337,16 @@ public class GeoPointFieldMapperTests extends ESSingleNodeTestCase {
 
     public void testMultiField() throws Exception {
         int numDocs = randomIntBetween(10, 100);
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("pin")
+        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
             .startObject("properties").startObject("location")
             .field("type", "geo_point")
             .startObject("fields")
             .startObject("geohash").field("type", "keyword").endObject()  // test geohash as keyword
             .startObject("latlon").field("type", "keyword").endObject()  // test geohash as string
             .endObject()
-            .endObject().endObject().endObject().endObject());
+            .endObject().endObject().endObject());
         CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test")
-            .addMapping("pin", mapping, XContentType.JSON);
+            .setMapping(mapping);
         mappingRequest.execute().actionGet();
 
         // create index and add random test points

+ 2 - 3
server/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java

@@ -27,7 +27,6 @@ import org.elasticsearch.common.compress.CompressedXContent;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.env.Environment;
 import org.elasticsearch.index.IndexService;
 import org.elasticsearch.index.IndexSettings;
@@ -148,7 +147,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
         // partitioned index must have routing
          IllegalArgumentException noRoutingException = expectThrows(IllegalArgumentException.class, () -> {
             client().admin().indices().prepareCreate("test-index")
-                    .addMapping("type", "{\"type\":{}}", XContentType.JSON)
+                    .setMapping("{\"_doc\":{}}")
                     .setSettings(Settings.builder()
                         .put("index.number_of_shards", 4)
                         .put("index.routing_partition_size", 2))
@@ -158,7 +157,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
 
         // valid partitioned index
         assertTrue(client().admin().indices().prepareCreate("test-index")
-            .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
+            .setMapping("{\"_doc\":{\"_routing\":{\"required\":true}}}")
             .setSettings(Settings.builder()
                 .put("index.number_of_shards", 4)
                 .put("index.routing_partition_size", 2))

+ 3 - 5
server/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateIT.java

@@ -22,7 +22,6 @@ package org.elasticsearch.indices.mapping;
 
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.test.ESIntegTestCase;
 
@@ -37,15 +36,14 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC
 import static org.hamcrest.Matchers.emptyIterable;
 
 public class ConcurrentDynamicTemplateIT extends ESIntegTestCase {
-    private final String mappingType = "test-mapping";
 
     // see #3544
     public void testConcurrentDynamicMapping() throws Exception {
         final String fieldName = "field";
-        final String mapping = "{ \"" + mappingType + "\": {" +
+        final String mapping = "{" +
                 "\"dynamic_templates\": ["
                 + "{ \"" + fieldName + "\": {" + "\"path_match\": \"*\"," + "\"mapping\": {" + "\"type\": \"text\"," + "\"store\": true,"
-                + "\"analyzer\": \"whitespace\" } } } ] } }";
+                + "\"analyzer\": \"whitespace\" } } } ] }";
         // The 'fieldNames' array is used to help with retrieval of index terms
         // after testing
 
@@ -53,7 +51,7 @@ public class ConcurrentDynamicTemplateIT extends ESIntegTestCase {
         for (int i = 0; i < iters; i++) {
             cluster().wipeIndices("test");
             assertAcked(prepareCreate("test")
-                    .addMapping(mappingType, mapping, XContentType.JSON));
+                    .setMapping(mapping));
             int numDocs = scaledRandomIntBetween(10, 100);
             final CountDownLatch latch = new CountDownLatch(numDocs);
             final List<Throwable> throwable = new CopyOnWriteArrayList<>();

+ 4 - 4
server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java

@@ -117,7 +117,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
                         Settings.builder()
                                 .put("index.number_of_shards", 1)
                                 .put("index.number_of_replicas", 0)
-                ).addMapping("_doc", "{\"_doc\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
+                ).setMapping("{\"properties\":{\"body\":{\"type\":\"text\"}}}")
                 .execute().actionGet();
         client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
 
@@ -158,7 +158,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
                         Settings.builder()
                                 .put("index.number_of_shards", 2)
                                 .put("index.number_of_replicas", 0)
-                ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
+                ).setMapping("{\"properties\":{\"body\":{\"type\":\"text\"}}}")
                 .execute().actionGet();
         client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
 
@@ -173,7 +173,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
 
     public void testUpdateMappingWithNormsConflicts() {
         client().admin().indices().prepareCreate("test")
-                .addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": false }}}}", XContentType.JSON)
+                .setMapping("{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": false }}}")
                 .execute().actionGet();
         try {
             client().admin().indices().preparePutMapping("test")
@@ -194,7 +194,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
                         Settings.builder()
                                 .put("index.number_of_shards", 2)
                                 .put("index.number_of_replicas", 0)
-                ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON)
+                ).setMapping("{\"properties\":{\"body\":{\"type\":\"text\"}}}")
                 .execute().actionGet();
         client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
 

+ 1 - 4
server/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java

@@ -36,7 +36,6 @@ import org.elasticsearch.common.settings.Setting.Property;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.MockEngineFactoryPlugin;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.indices.IndicesService;
@@ -81,7 +80,6 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase {
         String mapping = Strings // {}
                 .toString(XContentFactory.jsonBuilder()
                         .startObject()
-                        .startObject("type")
                         .startObject("properties")
                         .startObject("test-str")
                         .field("type", "keyword")
@@ -92,7 +90,6 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase {
                         .field("type", randomFrom(Arrays.asList("float", "long", "double", "short", "integer")))
                         .endObject() // test-num
                         .endObject() // properties
-                        .endObject() // type
                         .endObject());
         final double topLevelRate;
         final double lowLevelRate;
@@ -123,7 +120,7 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase {
         logger.info("creating index: [test] using settings: [{}]", settings.build());
         CreateIndexResponse response = client().admin().indices().prepareCreate("test")
                 .setSettings(settings)
-                .addMapping("type", mapping, XContentType.JSON).execute().actionGet();
+                .setMapping(mapping).execute().actionGet();
         final int numDocs;
         if (response.isShardsAcknowledged() == false) {
             /* some seeds just won't let you create the index at all and we enter a ping-pong mode

+ 3 - 6
server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java

@@ -33,7 +33,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.IndexNotFoundException;
 import org.elasticsearch.index.IndexSettings;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -266,17 +265,15 @@ public class OpenCloseIndexIT extends ESIntegTestCase {
     public void testOpenCloseWithDocs() throws IOException, ExecutionException, InterruptedException {
         String mapping = Strings.toString(XContentFactory.jsonBuilder().
                 startObject().
-                startObject("type").
                 startObject("properties").
                 startObject("test")
                 .field("type", "keyword")
-                .endObject().
-                        endObject().
-                        endObject()
+                .endObject()
+                .endObject()
                 .endObject());
 
         assertAcked(client().admin().indices().prepareCreate("test")
-                .addMapping("type", mapping, XContentType.JSON));
+                .setMapping(mapping));
         ensureGreen();
         int docs = between(10, 100);
         IndexRequestBuilder[] builder = new IndexRequestBuilder[docs];

+ 2 - 4
server/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java

@@ -773,11 +773,9 @@ public class IndexStatsIT extends ESIntegTestCase {
 
     public void testCompletionFieldsParam() throws Exception {
         assertAcked(prepareCreate("test1")
-                .addMapping(
-                        "_doc",
+                .setMapping(
                         "{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}" +
-                            ",\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}",
-                    XContentType.JSON));
+                            ",\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}"));
         ensureGreen();
 
         client().prepareIndex("test1").setId(Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}"

+ 2 - 3
server/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java

@@ -23,7 +23,6 @@ import org.apache.lucene.util.Constants;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.cluster.node.DiscoveryNode;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.test.ESIntegTestCase;
 import org.mockito.internal.util.collections.Sets;
@@ -45,7 +44,7 @@ public class PartitionedRoutingIT extends ESIntegTestCase {
                         .put("index.number_of_shards", shards)
                         .put("index.number_of_routing_shards", shards)
                         .put("index.routing_partition_size", partitionSize))
-                    .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
+                    .setMapping("{\"_routing\":{\"required\":true}}")
                     .execute().actionGet();
                 ensureGreen();
 
@@ -74,7 +73,7 @@ public class PartitionedRoutingIT extends ESIntegTestCase {
                 .put("index.number_of_routing_shards", currentShards)
                 .put("index.number_of_replicas", numberOfReplicas())
                 .put("index.routing_partition_size", partitionSize))
-            .addMapping("_doc", "{\"_doc\":{\"_routing\":{\"required\":true}}}", XContentType.JSON)
+            .setMapping("{\"_routing\":{\"required\":true}}")
             .execute().actionGet();
         ensureGreen();
 

+ 3 - 4
server/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java

@@ -28,7 +28,6 @@ import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.time.DateFormatter;
 import org.elasticsearch.common.time.DateFormatters;
 import org.elasticsearch.common.time.DateMathParser;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.mapper.DateFieldMapper;
 import org.elasticsearch.index.query.MatchNoneQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -1238,10 +1237,10 @@ public class DateHistogramIT extends ESIntegTestCase {
 
     public void testSingleValueWithMultipleDateFormatsFromMapping() throws Exception {
         String mappingJson = Strings.toString(jsonBuilder().startObject()
-                .startObject("type").startObject("properties")
+                .startObject("properties")
                 .startObject("date").field("type", "date").field("format", "strict_date_optional_time||dd-MM-yyyy")
-                .endObject().endObject().endObject().endObject());
-        prepareCreate("idx2").addMapping("type", mappingJson, XContentType.JSON).get();
+                .endObject().endObject().endObject());
+        prepareCreate("idx2").setMapping(mappingJson).get();
         IndexRequestBuilder[] reqs = new IndexRequestBuilder[5];
         for (int i = 0; i < reqs.length; i++) {
             reqs[i] = client().prepareIndex("idx2").setId("" + i)

+ 1 - 2
server/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java

@@ -23,7 +23,6 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.cluster.metadata.IndexMetaData;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
 import org.elasticsearch.search.aggregations.BucketOrder;
 import org.elasticsearch.search.aggregations.bucket.terms.Terms;
@@ -89,7 +88,7 @@ public class TermsDocCountErrorIT extends ESIntegTestCase {
         }
         numRoutingValues = between(1,40);
         assertAcked(prepareCreate("idx_with_routing")
-            .addMapping("type", "{ \"type\" : { \"_routing\" : { \"required\" : true } } }", XContentType.JSON));
+            .setMapping("{ \"_routing\" : { \"required\" : true } }"));
         for (int i = 0; i < numDocs; i++) {
             builders.add(client().prepareIndex("idx_single_shard").setId("" + i)
                 .setRouting(String.valueOf(randomInt(numRoutingValues)))

+ 2 - 6
server/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java

@@ -36,7 +36,6 @@ import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.settings.Settings.Builder;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.MockEngineFactoryPlugin;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.plugins.Plugin;
@@ -70,13 +69,10 @@ public class SearchWithRandomExceptionsIT extends ESIntegTestCase {
     public void testRandomExceptions() throws IOException, InterruptedException, ExecutionException {
         String mapping = Strings.toString(XContentFactory.jsonBuilder().
                 startObject().
-                startObject("type").
                 startObject("properties").
                 startObject("test")
                 .field("type", "keyword")
-                .endObject().
-                        endObject().
-                        endObject()
+                .endObject().endObject()
                 .endObject());
         final double lowLevelRate;
         final double topLevelRate;
@@ -107,7 +103,7 @@ public class SearchWithRandomExceptionsIT extends ESIntegTestCase {
         logger.info("creating index: [test] using settings: [{}]", settings.build());
         assertAcked(prepareCreate("test")
                 .setSettings(settings)
-                .addMapping("type", mapping, XContentType.JSON));
+                .setMapping(mapping));
         ensureSearchable();
         final int numDocs = between(10, 100);
         int numCreated = 0;

+ 2 - 5
server/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java

@@ -32,7 +32,6 @@ import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.search.sort.SortOrder;
@@ -61,12 +60,10 @@ public class SearchWithRandomIOExceptionsIT extends ESIntegTestCase {
     public void testRandomDirectoryIOExceptions() throws IOException, InterruptedException, ExecutionException {
         String mapping = Strings.toString(XContentFactory.jsonBuilder().
             startObject().
-            startObject("type").
             startObject("properties").
             startObject("test")
             .field("type", "keyword")
             .endObject().
-                endObject().
                 endObject()
             .endObject());
         final double exceptionRate;
@@ -98,7 +95,7 @@ public class SearchWithRandomIOExceptionsIT extends ESIntegTestCase {
             logger.info("creating index: [test] using settings: [{}]", settings.build());
             client().admin().indices().prepareCreate("test")
                 .setSettings(settings)
-                .addMapping("type", mapping, XContentType.JSON).get();
+                .setMapping(mapping).get();
             numInitialDocs = between(10, 100);
             ensureGreen();
             for (int i = 0; i < numInitialDocs; i++) {
@@ -121,7 +118,7 @@ public class SearchWithRandomIOExceptionsIT extends ESIntegTestCase {
             logger.info("creating index: [test] using settings: [{}]", settings.build());
             client().admin().indices().prepareCreate("test")
                 .setSettings(settings)
-                .addMapping("type", mapping, XContentType.JSON).get();
+                .setMapping(mapping).get();
         }
         ClusterHealthResponse clusterHealthResponse = client().admin().cluster()
             // it's OK to timeout here

+ 6 - 7
server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java

@@ -37,7 +37,6 @@ import org.elasticsearch.common.settings.Settings.Builder;
 import org.elasticsearch.common.time.DateFormatter;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider;
 import org.elasticsearch.index.analysis.AnalyzerProvider;
 import org.elasticsearch.index.analysis.PreConfiguredTokenFilter;
@@ -2722,7 +2721,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
     }
 
     public void testACopyFieldWithNestedQuery() throws Exception {
-        String mapping = Strings.toString(jsonBuilder().startObject().startObject("type").startObject("properties")
+        String mapping = Strings.toString(jsonBuilder().startObject().startObject("properties")
                     .startObject("foo")
                         .field("type", "nested")
                         .startObject("properties")
@@ -2737,8 +2736,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
                         .field("term_vector", "with_positions_offsets")
                         .field("store", true)
                     .endObject()
-                .endObject().endObject().endObject());
-        prepareCreate("test").addMapping("type", mapping, XContentType.JSON).get();
+                .endObject().endObject());
+        prepareCreate("test").setMapping(mapping).get();
 
         client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().startArray("foo")
                     .startObject().field("text", "brown").endObject()
@@ -2833,7 +2832,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
     }
 
     public void testWithNestedQuery() throws Exception {
-        String mapping = Strings.toString(jsonBuilder().startObject().startObject("type").startObject("properties")
+        String mapping = Strings.toString(jsonBuilder().startObject().startObject("properties")
             .startObject("text")
                 .field("type", "text")
                 .field("index_options", "offsets")
@@ -2847,8 +2846,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
                     .endObject()
                 .endObject()
             .endObject()
-            .endObject().endObject().endObject());
-        prepareCreate("test").addMapping("type", mapping, XContentType.JSON).get();
+            .endObject().endObject());
+        prepareCreate("test").setMapping(mapping).get();
 
         client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject()
             .startArray("foo")

+ 1 - 3
server/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java

@@ -203,18 +203,16 @@ public class GeoFilterIT extends ESIntegTestCase {
 
         String mapping = Strings.toString(XContentFactory.jsonBuilder()
                 .startObject()
-                .startObject("polygon")
                 .startObject("properties")
                 .startObject("area")
                 .field("type", "geo_shape")
                 .field("tree", "geohash")
                 .endObject()
                 .endObject()
-                .endObject()
                 .endObject());
 
         CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("shapes")
-            .addMapping("polygon", mapping, XContentType.JSON);
+            .setMapping(mapping);
         mappingRequest.get();
         client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().get();
 

+ 11 - 11
server/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java

@@ -46,24 +46,24 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase {
      */
     public void testOrientationPersistence() throws Exception {
         String idxName = "orientation";
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("shape")
+        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
             .startObject("properties").startObject("location")
             .field("type", "geo_shape")
             .field("orientation", "left")
-            .endObject().endObject()
+            .endObject()
             .endObject().endObject());
 
         // create index
-        assertAcked(prepareCreate(idxName).addMapping("shape", mapping, XContentType.JSON));
+        assertAcked(prepareCreate(idxName).setMapping(mapping));
 
-        mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("shape")
+        mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
             .startObject("properties").startObject("location")
             .field("type", "geo_shape")
             .field("orientation", "right")
-            .endObject().endObject()
+            .endObject()
             .endObject().endObject());
 
-        assertAcked(prepareCreate(idxName+"2").addMapping("shape", mapping, XContentType.JSON));
+        assertAcked(prepareCreate(idxName+"2").setMapping(mapping));
         ensureGreen(idxName, idxName+"2");
 
         internalCluster().fullRestart();
@@ -149,7 +149,7 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase {
      * Test that the indexed shape routing can be provided if it is required
      */
     public void testIndexShapeRouting() throws Exception {
-        String mapping = "{\n" +
+        String mapping = "{\"_doc\":{\n" +
             "    \"_routing\": {\n" +
             "      \"required\": true\n" +
             "    },\n" +
@@ -158,11 +158,11 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase {
             "        \"type\": \"geo_shape\"\n" +
             "      }\n" +
             "    }\n" +
-            "  }";
+            "  }}";
 
 
         // create index
-        assertAcked(client().admin().indices().prepareCreate("test").addMapping("doc", mapping, XContentType.JSON).get());
+        assertAcked(client().admin().indices().prepareCreate("test").setMapping(mapping).get());
         ensureGreen();
 
         String source = "{\n" +
@@ -201,10 +201,10 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase {
 
 
         // create index
-        assertAcked(client().admin().indices().prepareCreate("vector").addMapping("doc", mappingVector, XContentType.JSON).get());
+        assertAcked(client().admin().indices().prepareCreate("vector").setMapping(mappingVector).get());
         ensureGreen();
 
-        assertAcked(client().admin().indices().prepareCreate("quad").addMapping("doc", mappingQuad, XContentType.JSON).get());
+        assertAcked(client().admin().indices().prepareCreate("quad").setMapping(mappingQuad).get());
         ensureGreen();
 
         String source = "{\n" +

+ 14 - 14
server/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java

@@ -77,21 +77,21 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
     };
 
     private XContentBuilder createMapping() throws Exception {
-        XContentBuilder xcb = XContentFactory.jsonBuilder().startObject().startObject("type1")
+        XContentBuilder xcb = XContentFactory.jsonBuilder().startObject()
             .startObject("properties").startObject("location")
             .field("type", "geo_shape");
         if (randomBoolean()) {
             xcb = xcb.field("tree", randomFrom(PREFIX_TREES))
             .field("strategy", randomFrom(SpatialStrategy.RECURSIVE, SpatialStrategy.TERM));
         }
-        xcb = xcb.endObject().endObject().endObject().endObject();
+        xcb = xcb.endObject().endObject().endObject();
 
         return xcb;
     }
 
     public void testNullShape() throws Exception {
         String mapping = Strings.toString(createMapping());
-        client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("test").setMapping(mapping).get();
         ensureGreen();
 
         client().prepareIndex("test").setId("aNullshape").setSource("{\"location\": null}", XContentType.JSON)
@@ -102,7 +102,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
 
     public void testIndexPointsFilterRectangle() throws Exception {
         String mapping = Strings.toString(createMapping());
-        client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("test").setMapping(mapping).get();
         ensureGreen();
 
         client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject()
@@ -143,12 +143,12 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
     }
 
     public void testEdgeCases() throws Exception {
-        XContentBuilder xcb = XContentFactory.jsonBuilder().startObject().startObject("type1")
+        XContentBuilder xcb = XContentFactory.jsonBuilder().startObject()
             .startObject("properties").startObject("location")
             .field("type", "geo_shape")
-            .endObject().endObject().endObject().endObject();
+            .endObject().endObject().endObject();
         String mapping = Strings.toString(xcb);
-        client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("test").setMapping(mapping).get();
         ensureGreen();
 
         client().prepareIndex("test").setId("blakely").setSource(jsonBuilder().startObject()
@@ -180,7 +180,7 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
 
     public void testIndexedShapeReference() throws Exception {
         String mapping = Strings.toString(createMapping());
-        client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("test").setMapping(mapping).get();
         createIndex("shapes");
         ensureGreen();
 
@@ -584,17 +584,17 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
     }
 
     public void testPointsOnly() throws Exception {
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
+        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
                 .startObject("properties").startObject("location")
                 .field("type", "geo_shape")
                 .field("tree", randomBoolean() ? "quadtree" : "geohash")
                 .field("tree_levels", "6")
                 .field("distance_error_pct", "0.01")
                 .field("points_only", true)
-                .endObject().endObject()
+                .endObject()
                 .endObject().endObject());
 
-        client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("geo_points_only").setMapping(mapping).get();
         ensureGreen();
 
         ShapeBuilder shape = RandomShapeGenerator.createShape(random());
@@ -617,17 +617,17 @@ public class GeoShapeQueryTests extends ESSingleNodeTestCase {
     }
 
     public void testPointsOnlyExplicit() throws Exception {
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1")
+        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
             .startObject("properties").startObject("location")
             .field("type", "geo_shape")
             .field("tree", randomBoolean() ? "quadtree" : "geohash")
             .field("tree_levels", "6")
             .field("distance_error_pct", "0.01")
             .field("points_only", true)
-            .endObject().endObject()
+            .endObject()
             .endObject().endObject());
 
-        client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("geo_points_only").setMapping(mapping).get();
         ensureGreen();
 
         // MULTIPOINT

+ 9 - 9
server/src/test/java/org/elasticsearch/search/geo/LegacyGeoShapeIntegrationIT.java

@@ -46,26 +46,26 @@ public class LegacyGeoShapeIntegrationIT extends ESIntegTestCase {
      */
     public void testOrientationPersistence() throws Exception {
         String idxName = "orientation";
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("shape")
+        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
                 .startObject("properties").startObject("location")
                 .field("type", "geo_shape")
                 .field("tree", "quadtree")
                 .field("orientation", "left")
-                .endObject().endObject()
+                .endObject()
                 .endObject().endObject());
 
         // create index
-        assertAcked(prepareCreate(idxName).addMapping("shape", mapping, XContentType.JSON));
+        assertAcked(prepareCreate(idxName).setMapping(mapping));
 
-        mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("shape")
+        mapping = Strings.toString(XContentFactory.jsonBuilder().startObject()
                 .startObject("properties").startObject("location")
                 .field("type", "geo_shape")
                 .field("tree", "quadtree")
                 .field("orientation", "right")
-                .endObject().endObject()
+                .endObject()
                 .endObject().endObject());
 
-        assertAcked(prepareCreate(idxName+"2").addMapping("shape", mapping, XContentType.JSON));
+        assertAcked(prepareCreate(idxName+"2").setMapping(mapping));
         ensureGreen(idxName, idxName+"2");
 
         internalCluster().fullRestart();
@@ -130,7 +130,7 @@ public class LegacyGeoShapeIntegrationIT extends ESIntegTestCase {
      * Test that the indexed shape routing can be provided if it is required
      */
     public void testIndexShapeRouting() throws Exception {
-        String mapping = "{\n" +
+        String mapping = "{\"_doc\":{\n" +
             "    \"_routing\": {\n" +
             "      \"required\": true\n" +
             "    },\n" +
@@ -140,11 +140,11 @@ public class LegacyGeoShapeIntegrationIT extends ESIntegTestCase {
             "        \"tree\" : \"quadtree\"\n" +
             "      }\n" +
             "    }\n" +
-            "  }";
+            "  }}";
 
 
         // create index
-        assertAcked(client().admin().indices().prepareCreate("test").addMapping("doc", mapping, XContentType.JSON).get());
+        assertAcked(client().admin().indices().prepareCreate("test").setMapping(mapping).get());
         ensureGreen();
 
         String source = "{\n" +

+ 4 - 24
server/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java

@@ -25,11 +25,9 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.search.SearchPhaseExecutionException;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.cluster.health.ClusterHealthStatus;
-import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
 import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
 import org.elasticsearch.index.query.QueryBuilder;
@@ -223,13 +221,8 @@ public class MoreLikeThisIT extends ESIntegTestCase {
     public void testMoreLikeThisWithAliasesInLikeDocuments() throws Exception {
         String indexName = "foo";
         String aliasName = "foo_name";
-        String typeName = "bar";
 
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("bar")
-                .startObject("properties")
-                .endObject()
-                .endObject().endObject());
-        client().admin().indices().prepareCreate(indexName).addMapping(typeName, mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate(indexName).get();
         client().admin().indices().prepareAliases().addAlias(indexName, aliasName).get();
 
         assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
@@ -249,11 +242,7 @@ public class MoreLikeThisIT extends ESIntegTestCase {
     }
 
     public void testMoreLikeThisIssue2197() throws Exception {
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("bar")
-                .startObject("properties")
-                .endObject()
-                .endObject().endObject());
-        client().admin().indices().prepareCreate("foo").addMapping("bar", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("foo").get();
         client().prepareIndex("foo").setId("1")
                 .setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject().endObject())
                 .get();
@@ -272,11 +261,7 @@ public class MoreLikeThisIT extends ESIntegTestCase {
 
     // Issue #2489
     public void testMoreLikeWithCustomRouting() throws Exception {
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("bar")
-                .startObject("properties")
-                .endObject()
-                .endObject().endObject());
-        client().admin().indices().prepareCreate("foo").addMapping("bar", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("foo").get();
         ensureGreen();
 
         client().prepareIndex("foo").setId("1")
@@ -293,13 +278,8 @@ public class MoreLikeThisIT extends ESIntegTestCase {
 
     // Issue #3039
     public void testMoreLikeThisIssueRoutingNotSerialized() throws Exception {
-        String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("bar")
-                .startObject("properties")
-                .endObject()
-                .endObject().endObject());
         assertAcked(prepareCreate("foo", 2,
-                Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put(SETTING_NUMBER_OF_REPLICAS, 0))
-                .addMapping("bar", mapping, XContentType.JSON));
+                Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put(SETTING_NUMBER_OF_REPLICAS, 0)));
         ensureGreen();
 
         client().prepareIndex("foo").setId("1")

+ 4 - 6
server/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java

@@ -522,8 +522,7 @@ public class SimpleNestedIT extends ESIntegTestCase {
 
     public void testNestedSortWithMultiLevelFiltering() throws Exception {
         assertAcked(prepareCreate("test")
-            .addMapping("type1", "{\n"
-                + "  \"type1\": {\n"
+            .setMapping("{\n"
                 + "    \"properties\": {\n"
                 + "      \"acl\": {\n"
                 + "        \"type\": \"nested\",\n"
@@ -545,8 +544,7 @@ public class SimpleNestedIT extends ESIntegTestCase {
                 + "        }\n"
                 + "      }\n"
                 + "    }\n"
-                + "  }\n"
-                + "}", XContentType.JSON));
+                + "}"));
         ensureGreen();
 
         client().prepareIndex("test").setId("1").setSource("{\n"
@@ -738,7 +736,7 @@ public class SimpleNestedIT extends ESIntegTestCase {
     public void testLeakingSortValues() throws Exception {
         assertAcked(prepareCreate("test")
             .setSettings(Settings.builder().put("number_of_shards", 1))
-            .addMapping("test-type", "{\n"
+            .setMapping("{\"_doc\":{\n"
                     + "        \"dynamic\": \"strict\",\n"
                     + "        \"properties\": {\n"
                     + "          \"nested1\": {\n"
@@ -758,7 +756,7 @@ public class SimpleNestedIT extends ESIntegTestCase {
                     + "            }\n"
                     + "          }\n"
                     + "        }\n"
-                    + "      }\n", XContentType.JSON));
+                    + "      }}\n"));
             ensureGreen();
 
             client().prepareIndex("test").setId("1").setSource("{\n"

+ 2 - 6
server/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java

@@ -336,18 +336,16 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
     public void testSimpleQueryStringAnalyzeWildcard() throws ExecutionException, InterruptedException, IOException {
         String mapping = Strings.toString(XContentFactory.jsonBuilder()
                 .startObject()
-                .startObject("type1")
                 .startObject("properties")
                 .startObject("location")
                 .field("type", "text")
                 .field("analyzer", "standard")
                 .endObject()
                 .endObject()
-                .endObject()
                 .endObject());
 
         CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test1")
-            .addMapping("type1", mapping, XContentType.JSON);
+            .setMapping(mapping);
         mappingRequest.get();
         indexRandom(true, client().prepareIndex("test1").setId("1").setSource("location", "Köln"));
         refresh();
@@ -386,19 +384,17 @@ public class SimpleQueryStringIT extends ESIntegTestCase {
         // https://github.com/elastic/elasticsearch/issues/18202
         String mapping = Strings.toString(XContentFactory.jsonBuilder()
                 .startObject()
-                .startObject("type1")
                 .startObject("properties")
                 .startObject("body")
                 .field("type", "text")
                 .field("analyzer", "stop")
                 .endObject()
                 .endObject()
-                .endObject()
                 .endObject());
 
         CreateIndexRequestBuilder mappingRequest = client().admin().indices()
                 .prepareCreate("test1")
-                .addMapping("type1", mapping, XContentType.JSON);
+                .setMapping(mapping);
         mappingRequest.get();
         indexRandom(true, client().prepareIndex("test1").setId("1").setSource("body", "Some Text"));
         refresh();

+ 2 - 5
server/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java

@@ -29,7 +29,6 @@ import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.search.Scroll;
 import org.elasticsearch.search.SearchException;
 import org.elasticsearch.search.SearchHit;
@@ -37,9 +36,9 @@ import org.elasticsearch.search.sort.SortBuilders;
 import org.elasticsearch.test.ESIntegTestCase;
 
 import java.io.IOException;
-import java.util.List;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@@ -52,7 +51,6 @@ public class SearchSliceIT extends ESIntegTestCase {
     private void setupIndex(int numDocs, int numberOfShards) throws IOException, ExecutionException, InterruptedException {
         String mapping = Strings.toString(XContentFactory.jsonBuilder().
             startObject()
-                .startObject("type")
                     .startObject("properties")
                         .startObject("invalid_random_kw")
                             .field("type", "keyword")
@@ -67,11 +65,10 @@ public class SearchSliceIT extends ESIntegTestCase {
                             .field("doc_values", "false")
                         .endObject()
                     .endObject()
-                .endObject()
             .endObject());
         assertAcked(client().admin().indices().prepareCreate("test")
             .setSettings(Settings.builder().put("number_of_shards", numberOfShards).put("index.max_slices_per_scroll", 10000))
-            .addMapping("type", mapping, XContentType.JSON));
+            .setMapping(mapping));
         ensureGreen();
 
         List<IndexRequestBuilder> requests = new ArrayList<>();

+ 2 - 7
server/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java

@@ -26,7 +26,6 @@ import org.elasticsearch.action.search.ShardSearchFailure;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.geo.GeoPoint;
 import org.elasticsearch.common.geo.GeoUtils;
-import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.fielddata.ScriptDocValues;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.script.MockScriptPlugin;
@@ -225,7 +224,6 @@ public class SimpleSortIT extends ESIntegTestCase {
     public void testSortMinValueScript() throws IOException {
         String mapping = Strings.toString(jsonBuilder()
                 .startObject()
-                    .startObject("type1")
                         .startObject("properties")
                             .startObject("lvalue")
                                 .field("type", "long")
@@ -240,10 +238,9 @@ public class SimpleSortIT extends ESIntegTestCase {
                                 .field("type", "geo_point")
                             .endObject()
                         .endObject()
-                    .endObject()
                 .endObject());
 
-        assertAcked(prepareCreate("test").addMapping("type1", mapping, XContentType.JSON));
+        assertAcked(prepareCreate("test").setMapping(mapping));
         ensureGreen();
 
         for (int i = 0; i < 10; i++) {
@@ -344,7 +341,6 @@ public class SimpleSortIT extends ESIntegTestCase {
         // be propagated to all nodes yet and sort operation fail when the sort field is not defined
         String mapping = Strings.toString(jsonBuilder()
                 .startObject()
-                    .startObject("type1")
                         .startObject("properties")
                             .startObject("id")
                                 .field("type", "keyword")
@@ -353,9 +349,8 @@ public class SimpleSortIT extends ESIntegTestCase {
                                 .field("type", "keyword")
                             .endObject()
                         .endObject()
-                    .endObject()
                 .endObject());
-        assertAcked(prepareCreate("test").addMapping("type1", mapping, XContentType.JSON));
+        assertAcked(prepareCreate("test").setMapping(mapping));
         ensureGreen();
 
         client().prepareIndex("test")

+ 10 - 13
x-pack/plugin/ml/src/test/java/org/elasticsearch/license/MachineLearningLicensingTests.java

@@ -152,7 +152,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         // test that license restricted apis do not work
         ElasticsearchSecurityException e = expectThrows(ElasticsearchSecurityException.class, () -> {
             PlainActionFuture<PutDatafeedAction.Response> listener = PlainActionFuture.newFuture();
-            client().execute(PutDatafeedAction.INSTANCE, 
+            client().execute(PutDatafeedAction.INSTANCE,
                 new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), listener);
             listener.actionGet();
         });
@@ -166,7 +166,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         assertMLAllowed(true);
         // test that license restricted apis do now work
         PlainActionFuture<PutDatafeedAction.Response> listener = PlainActionFuture.newFuture();
-        client().execute(PutDatafeedAction.INSTANCE, 
+        client().execute(PutDatafeedAction.INSTANCE,
                 new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), listener);
         PutDatafeedAction.Response response = listener.actionGet();
         assertNotNull(response);
@@ -177,8 +177,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         String datafeedId = jobId + "-datafeed";
         assertMLAllowed(true);
         String datafeedIndex = jobId + "-data";
-        prepareCreate(datafeedIndex).addMapping("type", "{\"type\":{\"properties\":{\"time\":{\"type\":\"date\"}}}}",
-            XContentType.JSON).get();
+        prepareCreate(datafeedIndex).setMapping("{\"_doc\":{\"properties\":{\"time\":{\"type\":\"date\"}}}}").get();
 
         // put job
         PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
@@ -187,7 +186,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         assertNotNull(putJobResponse);
         // put datafeed
         PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
-        client().execute(PutDatafeedAction.INSTANCE, 
+        client().execute(PutDatafeedAction.INSTANCE,
                 new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId,
                         Collections.singletonList(datafeedIndex))), putDatafeedListener);
         PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();
@@ -276,15 +275,14 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         String datafeedId = jobId + "-datafeed";
         assertMLAllowed(true);
         String datafeedIndex = jobId + "-data";
-        prepareCreate(datafeedIndex).addMapping("type", "{\"type\":{\"properties\":{\"time\":{\"type\":\"date\"}}}}",
-            XContentType.JSON).get();
+        prepareCreate(datafeedIndex).setMapping("{\"_doc\":{\"properties\":{\"time\":{\"type\":\"date\"}}}}").get();
         // test that license restricted apis do now work
         PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
         client().execute(PutJobAction.INSTANCE, new PutJobAction.Request(createJob(jobId)), putJobListener);
         PutJobAction.Response putJobResponse = putJobListener.actionGet();
         assertNotNull(putJobResponse);
         PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
-        client().execute(PutDatafeedAction.INSTANCE, 
+        client().execute(PutDatafeedAction.INSTANCE,
                 new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId,
                         Collections.singletonList(datafeedIndex))), putDatafeedListener);
         PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();
@@ -340,15 +338,14 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         String datafeedId = jobId + "-datafeed";
         assertMLAllowed(true);
         String datafeedIndex = jobId + "-data";
-        prepareCreate(datafeedIndex).addMapping("type", "{\"type\":{\"properties\":{\"time\":{\"type\":\"date\"}}}}",
-            XContentType.JSON).get();
+        prepareCreate(datafeedIndex).setMapping("{\"_doc\":{\"properties\":{\"time\":{\"type\":\"date\"}}}}").get();
         // test that license restricted apis do now work
         PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
         client().execute(PutJobAction.INSTANCE, new PutJobAction.Request(createJob(jobId)), putJobListener);
         PutJobAction.Response putJobResponse = putJobListener.actionGet();
         assertNotNull(putJobResponse);
         PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
-        client().execute(PutDatafeedAction.INSTANCE, 
+        client().execute(PutDatafeedAction.INSTANCE,
                 new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId,
                         Collections.singletonList(datafeedIndex))), putDatafeedListener);
         PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();
@@ -358,7 +355,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         AcknowledgedResponse openJobResponse = openJobListener.actionGet();
         assertNotNull(openJobResponse);
         PlainActionFuture<AcknowledgedResponse> startDatafeedListener = PlainActionFuture.newFuture();
-        client().execute(StartDatafeedAction.INSTANCE, 
+        client().execute(StartDatafeedAction.INSTANCE,
             new StartDatafeedAction.Request(datafeedId, 0L), startDatafeedListener);
         AcknowledgedResponse startDatafeedResponse = startDatafeedListener.actionGet();
         assertNotNull(startDatafeedResponse);
@@ -457,7 +454,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
         PutJobAction.Response putJobResponse = putJobListener.actionGet();
         assertNotNull(putJobResponse);
         PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
-        client().execute(PutDatafeedAction.INSTANCE, 
+        client().execute(PutDatafeedAction.INSTANCE,
                 new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId,
                         Collections.singletonList(jobId))), putDatafeedListener);
         PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();

+ 1 - 1
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java

@@ -360,7 +360,7 @@ public class SecurityIndexManager implements ClusterStateListener {
                 final Tuple<String, Settings> mappingAndSettings = parseMappingAndSettingsFromTemplateBytes(mappingSource);
                 CreateIndexRequest request = new CreateIndexRequest(indexState.concreteIndexName)
                         .alias(new Alias(this.aliasName))
-                        .mapping(MapperService.SINGLE_MAPPING_NAME, mappingAndSettings.v1(), XContentType.JSON)
+                        .mapping("{\"_doc\":" + mappingAndSettings.v1() + "}")
                         .waitForActiveShards(ActiveShardCount.ALL)
                         .settings(mappingAndSettings.v2());
                 executeAsyncWithOrigin(client.threadPool().getThreadContext(), SECURITY_ORIGIN, request,

+ 1 - 3
x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java

@@ -284,16 +284,14 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase {
         // create a mapping with a wrong @timestamp field, so that the index action of the watch below will fail
         String mapping = Strings.toString(XContentFactory.jsonBuilder()
                 .startObject()
-                .startObject("bar")
                 .startObject("properties")
                 .startObject("@timestamp")
                 .field("type", "integer")
                 .endObject()
                 .endObject()
-                .endObject()
                 .endObject());
 
-        client().admin().indices().prepareCreate("foo").addMapping("bar", mapping, XContentType.JSON).get();
+        client().admin().indices().prepareCreate("foo").setMapping(mapping).get();
 
         TimeValue throttlePeriod = new TimeValue(60, TimeUnit.MINUTES);