diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java index 1cd76e48ffff5..53524a6a5c215 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java @@ -1235,12 +1235,10 @@ public void testGet() throws Exception { createIndex.setJsonEntity( "{\n" + " \"mappings\" : {\n" + - " \"_doc\" : {\n" + - " \"properties\" : {\n" + - " \"message\" : {\n" + - " \"type\": \"text\",\n" + - " \"store\": true\n" + - " }\n" + + " \"properties\" : {\n" + + " \"message\" : {\n" + + " \"type\": \"text\",\n" + + " \"store\": true\n" + " }\n" + " }\n" + " }\n" + @@ -1764,12 +1762,10 @@ public void testMultiGet() throws Exception { createIndex.setJsonEntity( "{\n" + " \"mappings\" : {\n" + - " \"_doc\" : {\n" + - " \"properties\" : {\n" + - " \"foo\" : {\n" + - " \"type\": \"text\",\n" + - " \"store\": true\n" + - " }\n" + + " \"properties\" : {\n" + + " \"foo\" : {\n" + + " \"type\": \"text\",\n" + + " \"store\": true\n" + " }\n" + " }\n" + " }\n" + diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java index 02b7d597ce24e..14def60b277e8 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java @@ -313,15 +313,13 @@ public void testCreateIndex() throws IOException { { request = new CreateIndexRequest("twitter2"); //tag::create-index-mappings-map - Map jsonMap = new HashMap<>(); Map message = new HashMap<>(); message.put("type", "text"); Map properties = new HashMap<>(); properties.put("message", message); Map mapping = new HashMap<>(); mapping.put("properties", properties); - jsonMap.put("_doc", mapping); - request.mapping(jsonMap); // <1> + request.mapping(mapping); // <1> //end::create-index-mappings-map CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); assertTrue(createIndexResponse.isAcknowledged()); @@ -332,15 +330,11 @@ public void testCreateIndex() throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); { - builder.startObject("_doc"); + builder.startObject("properties"); { - builder.startObject("properties"); + builder.startObject("message"); { - builder.startObject("message"); - { - builder.field("type", "text"); - } - builder.endObject(); + builder.field("type", "text"); } builder.endObject(); } @@ -381,10 +375,8 @@ public void testCreateIndex() throws IOException { " \"number_of_replicas\" : 0\n" + " },\n" + " \"mappings\" : {\n" + - " \"_doc\" : {\n" + - " \"properties\" : {\n" + - " \"message\" : { \"type\" : \"text\" }\n" + - " }\n" + + " \"properties\" : {\n" + + " \"message\" : { \"type\" : \"text\" }\n" + " }\n" + " },\n" + " \"aliases\" : {\n" + diff --git a/docs/build.gradle b/docs/build.gradle index e7112c08ac41e..1083d07b94f46 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -98,19 +98,17 @@ Closure setupTwitter = { String name, int count -> number_of_shards: 1 number_of_replicas: 1 mappings: - _doc: - properties: - user: - type: keyword - doc_values: true - date: - type: date - likes: - type: long + properties: + user: + type: keyword + doc_values: true + date: + type: date + likes: + type: long - do: bulk: index: twitter - type: _doc refresh: true body: |''' for (int i = 0; i < count; i++) { @@ -161,16 +159,14 @@ buildRestTests.setups['ledger'] = ''' number_of_shards: 2 number_of_replicas: 1 mappings: - _doc: - properties: - type: - type: keyword - amount: - type: double + properties: + type: + type: keyword + amount: + type: double - do: bulk: index: ledger - type: _doc refresh: true body: | {"index":{}} @@ -194,14 +190,12 @@ buildRestTests.setups['sales'] = ''' number_of_shards: 2 number_of_replicas: 1 mappings: - _doc: - properties: - type: - type: keyword + properties: + type: + type: keyword - do: bulk: index: sales - type: _doc refresh: true body: | {"index":{}} @@ -231,7 +225,6 @@ buildRestTests.setups['bank'] = ''' - do: bulk: index: bank - type: _doc refresh: true body: | #bank_data# @@ -273,16 +266,14 @@ buildRestTests.setups['stackoverflow'] = ''' number_of_shards: 1 number_of_replicas: 1 mappings: - _doc: - properties: - author: - type: keyword - tags: - type: keyword + properties: + author: + type: keyword + tags: + type: keyword - do: bulk: index: stackoverflow - type: _doc refresh: true body: |''' @@ -328,16 +319,14 @@ buildRestTests.setups['news'] = ''' number_of_shards: 1 number_of_replicas: 1 mappings: - _doc: - properties: - source: - type: keyword - content: - type: text + properties: + source: + type: keyword + content: + type: text - do: bulk: index: news - type: _doc refresh: true body: |''' @@ -381,14 +370,12 @@ buildRestTests.setups['exams'] = ''' number_of_shards: 1 number_of_replicas: 1 mappings: - _doc: - properties: - grade: - type: byte + properties: + grade: + type: byte - do: bulk: index: exams - type: _doc refresh: true body: | {"index":{}} @@ -446,10 +433,9 @@ buildRestTests.setups['analyze_sample'] = ''' type: custom filter: [lowercase] mappings: - _doc: - properties: - obj1.field1: - type: text''' + properties: + obj1.field1: + type: text''' // Used by percentile/percentile-rank aggregations buildRestTests.setups['latency'] = ''' @@ -461,14 +447,12 @@ buildRestTests.setups['latency'] = ''' number_of_shards: 1 number_of_replicas: 1 mappings: - _doc: - properties: - load_time: - type: long + properties: + load_time: + type: long - do: bulk: index: latency - type: _doc refresh: true body: |''' @@ -493,14 +477,12 @@ buildRestTests.setups['iprange'] = ''' number_of_shards: 1 number_of_replicas: 1 mappings: - _doc: - properties: - ip: - type: ip + properties: + ip: + type: ip - do: bulk: index: ip_addresses - type: _doc refresh: true body: |''' @@ -613,16 +595,15 @@ buildRestTests.setups['sensor_rollup_job'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword - do: raw: method: PUT @@ -664,21 +645,19 @@ buildRestTests.setups['sensor_started_rollup_job'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword - do: bulk: index: sensor-1 - type: _doc refresh: true body: | {"index":{}} @@ -740,26 +719,25 @@ buildRestTests.setups['sensor_index'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword - load: - type: double - net_in: - type: long - net_out: - type: long - hostname: - type: keyword - datacenter: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword + load: + type: double + net_in: + type: long + net_out: + type: long + hostname: + type: keyword + datacenter: + type: keyword ''' buildRestTests.setups['sensor_prefab_data'] = ''' @@ -771,16 +749,15 @@ buildRestTests.setups['sensor_prefab_data'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword - do: indices.create: index: sensor_rollup @@ -789,64 +766,62 @@ buildRestTests.setups['sensor_prefab_data'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - node.terms.value: - type: keyword - temperature.sum.value: - type: double - temperature.max.value: - type: double - temperature.min.value: - type: double - timestamp.date_histogram.time_zone: - type: keyword - timestamp.date_histogram.interval: - type: keyword - timestamp.date_histogram.timestamp: - type: date - timestamp.date_histogram._count: - type: long - voltage.avg.value: - type: double - voltage.avg._count: - type: long - _rollup.id: - type: keyword - _rollup.version: - type: long - _meta: - _rollup: - sensor: - cron: "* * * * * ?" - rollup_index: "sensor_rollup" - index_pattern: "sensor-*" - timeout: "20s" - page_size: 1000 - groups: - date_histogram: - delay: "7d" - field: "timestamp" - interval: "60m" - time_zone: "UTC" - terms: - fields: - - "node" - id: sensor - metrics: - - field: "temperature" - metrics: - - min - - max - - sum - - field: "voltage" - metrics: - - avg + properties: + node.terms.value: + type: keyword + temperature.sum.value: + type: double + temperature.max.value: + type: double + temperature.min.value: + type: double + timestamp.date_histogram.time_zone: + type: keyword + timestamp.date_histogram.interval: + type: keyword + timestamp.date_histogram.timestamp: + type: date + timestamp.date_histogram._count: + type: long + voltage.avg.value: + type: double + voltage.avg._count: + type: long + _rollup.id: + type: keyword + _rollup.version: + type: long + _meta: + _rollup: + sensor: + cron: "* * * * * ?" + rollup_index: "sensor_rollup" + index_pattern: "sensor-*" + timeout: "20s" + page_size: 1000 + groups: + date_histogram: + delay: "7d" + field: "timestamp" + interval: "60m" + time_zone: "UTC" + terms: + fields: + - "node" + id: sensor + metrics: + - field: "temperature" + metrics: + - min + - max + - sum + - field: "voltage" + metrics: + - avg - do: bulk: index: sensor_rollup - type: _doc refresh: true body: | {"index":{}} @@ -1093,16 +1068,14 @@ buildRestTests.setups['reviews'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - product: - type: keyword - rating: - type: long + properties: + product: + type: keyword + rating: + type: long - do: bulk: index: reviews - type: _doc refresh: true body: | {"index": {"_id": "1"}} @@ -1139,22 +1112,20 @@ buildRestTests.setups['seats'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - theatre: - type: keyword - cost: - type: long - row: - type: long - number: - type: long - sold: - type: boolean + properties: + theatre: + type: keyword + cost: + type: long + row: + type: long + number: + type: long + sold: + type: boolean - do: bulk: index: seats - type: _doc refresh: true body: | {"index":{"_id": "1"}} diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/80_script_score.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/80_script_score.yml index c9b73bca029b1..a3135777c952c 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/80_script_score.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/80_script_score.yml @@ -14,26 +14,22 @@ setup: settings: number_of_shards: 2 mappings: - _doc: - properties: - dval: - type: double + properties: + dval: + type: double - do: index: index: test - type: _doc id: d1 body: {"dval": 10} - do: index: index: test - type: _doc id: d2 body: {"dval": 100} - do: index: index: test - type: _doc id: d3 body: {"dval": 1000} @@ -225,10 +221,9 @@ setup: settings: number_of_shards: 1 mappings: - _doc: - properties: - date: - type: date + properties: + date: + type: date - do: index: index: test @@ -309,16 +304,15 @@ setup: settings: number_of_shards: 1 mappings: - _doc: - properties: - ival: - type: integer - lval: - type: long - fval: - type: float - dval: - type: double + properties: + ival: + type: integer + lval: + type: long + fval: + type: float + dval: + type: double - do: index: diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml index 5e750f89f12ad..b6823f88c15fc 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yml @@ -44,9 +44,8 @@ index: test body: mappings: - _doc: - _source: - enabled: false + _source: + enabled: false - do: index: index: test diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.create/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.create/10_basic.yml index 78e67541a1f36..965083421cbaf 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.create/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.create/10_basic.yml @@ -135,3 +135,22 @@ properties: "": type: keyword + +--- +"Create index with explicit _doc type": + - skip: + version: " - 6.99.99" + reason: include_type_name defaults to true before 7.0 + - do: + catch: bad_request + indices.create: + index: test_index + body: + mappings: + _doc: + properties: + field: + type: keyword + + - match: { error.type: "illegal_argument_exception" } + - match: { error.reason: "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true." } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml index 420b12398d267..2c4658afad2db 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml @@ -68,3 +68,26 @@ properties: "": type: keyword + +--- +"Put mappings with explicit _doc type": + - skip: + version: " - 6.99.99" + reason: include_type_name defaults to true before 7.0 + + - do: + indices.create: + index: test_index + + - do: + catch: bad_request + indices.put_mapping: + index: test_index + body: + _doc: + properties: + field: + type: keyword + + - match: { error.type: "illegal_argument_exception" } + - match: { error.reason: "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true." } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml index c0b0bbe5d30b7..3850ba4150b4f 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml @@ -238,3 +238,24 @@ indices.put_template: name: test body: {} + +--- +"Put template with explicit _doc type": + - skip: + version: " - 6.99.99" + reason: include_type_name defaults to true before 7.0 + + - do: + catch: bad_request + indices.put_template: + name: test + body: + index_patterns: test-* + mappings: + _doc: + properties: + field: + type: keyword + + - match: { error.type: "illegal_argument_exception" } + - match: { error.reason: "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true." } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/40_mapping.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/40_mapping.yml index 59e027fb98457..47b004326a457 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/40_mapping.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.rollover/40_mapping.yml @@ -41,3 +41,32 @@ - match: { conditions: { "[max_docs: 2]": true } } - match: { rolled_over: true } + +--- +"Mappings with explicit _doc type": + - skip: + version: " - 6.99.99" + reason: include_type_name defaults to true before 7.0 + + - do: + indices.create: + index: logs-1 + body: + aliases: + logs_search: {} + + - do: + catch: bad_request + indices.rollover: + alias: "logs_search" + body: + conditions: + max_docs: 2 + mappings: + _doc: + properties: + field: + type: keyword + + - match: { error.caused_by.type: "illegal_argument_exception" } + - match: { error.caused_by.reason: "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true." } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 3bd3153d83180..1150a29b07766 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -70,13 +70,18 @@ public class RolloverRequest extends AcknowledgedRequest implem CONDITIONS, ObjectParser.ValueType.OBJECT); PARSER.declareField((parser, request, context) -> request.createIndexRequest.settings(parser.map()), CreateIndexRequest.SETTINGS, ObjectParser.ValueType.OBJECT); - PARSER.declareField((parser, request, isTypeIncluded) -> { - if (isTypeIncluded) { + PARSER.declareField((parser, request, includeTypeName) -> { + if (includeTypeName) { for (Map.Entry mappingsEntry : parser.map().entrySet()) { request.createIndexRequest.mapping(mappingsEntry.getKey(), (Map) mappingsEntry.getValue()); } } else { // a type is not included, add a dummy _doc type + Map mappings = parser.map(); + if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) { + throw new IllegalArgumentException("The mapping definition cannot be nested under a type " + + "[" + MapperService.SINGLE_MAPPING_NAME + "] unless include_type_name is set to true."); + } request.createIndexRequest.mapping(MapperService.SINGLE_MAPPING_NAME, parser.map()); } }, CreateIndexRequest.MAPPINGS, ObjectParser.ValueType.OBJECT); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index cf31401983a62..feec1833443a2 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -22,13 +22,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest; import org.elasticsearch.cluster.AckedClusterStateTaskListener; -import org.elasticsearch.cluster.ClusterStateTaskExecutor; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateTaskConfig; +import org.elasticsearch.cluster.ClusterStateTaskExecutor; import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; @@ -37,8 +36,7 @@ import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; @@ -55,6 +53,7 @@ import java.util.List; import java.util.Map; +import static org.elasticsearch.index.mapper.MapperService.isMappingSourceTyped; import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.NO_LONGER_ASSIGNED; /** @@ -279,7 +278,7 @@ private ClusterState applyRequest(ClusterState currentState, PutMappingClusterSt if (mappingType == null) { mappingType = newMapper.type(); } else if (mappingType.equals(newMapper.type()) == false - && (isMappingSourceTyped(mapperService, mappingUpdateSource, request.type()) + && (isMappingSourceTyped(request.type(), mappingUpdateSource) || mapperService.resolveDocumentType(mappingType).equals(newMapper.type()) == false)) { throw new InvalidTypeNameException("Type name provided does not match type name within mapping definition."); } @@ -304,7 +303,7 @@ private ClusterState applyRequest(ClusterState currentState, PutMappingClusterSt // are handling a typeless call. In such a case, we override _doc with the actual type // name in the mappings. This allows to use typeless APIs on typed indices. String typeForUpdate = mappingType; // the type to use to apply the mapping update - if (isMappingSourceTyped(mapperService, mappingUpdateSource, request.type()) == false) { + if (isMappingSourceTyped(request.type(), mappingUpdateSource) == false) { typeForUpdate = mapperService.resolveDocumentType(mappingType); } @@ -371,15 +370,6 @@ public String describeTasks(List tasks) { } } - /** - * Returns {@code true} if the given {@code mappingSource} includes a type - * as a top-level object. - */ - private static boolean isMappingSourceTyped(MapperService mapperService, CompressedXContent mappingSource, String type) { - Map root = XContentHelper.convertToMap(mappingSource.compressedReference(), true, XContentType.JSON).v2(); - return root.size() == 1 && root.keySet().iterator().next().equals(type); - } - public void putMapping(final PutMappingClusterStateUpdateRequest request, final ActionListener listener) { clusterService.submitStateUpdateTask("put-mapping", request, diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java index add313d7aa87b..398ce4cdd17ce 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -39,6 +39,7 @@ import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.AbstractIndexComponent; @@ -665,6 +666,20 @@ public DocumentMapper documentMapper(String type) { return null; } + /** + * Returns {@code true} if the given {@code mappingSource} includes a type + * as a top-level object. + */ + public static boolean isMappingSourceTyped(String type, Map mapping) { + return mapping.size() == 1 && mapping.keySet().iterator().next().equals(type); + } + + + public static boolean isMappingSourceTyped(String type, CompressedXContent mappingSource) { + Map root = XContentHelper.convertToMap(mappingSource.compressedReference(), true, XContentType.JSON).v2(); + return isMappingSourceTyped(type, root); + } + /** * Resolves a type from a mapping-related request into the type that should be used when * merging and updating mappings. diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java index adcdc0b281c2e..527b0830c8022 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java @@ -64,18 +64,38 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC } CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index")); + if (request.hasContent()) { - Map sourceAsMap = XContentHelper.convertToMap(request.content(), false, request.getXContentType()).v2(); - if (includeTypeName == false && sourceAsMap.containsKey("mappings")) { - Map newSourceAsMap = new HashMap<>(sourceAsMap); - newSourceAsMap.put("mappings", Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, sourceAsMap.get("mappings"))); - sourceAsMap = newSourceAsMap; - } + Map sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, + request.getXContentType()).v2(); + sourceAsMap = prepareMappings(sourceAsMap, includeTypeName); createIndexRequest.source(sourceAsMap, LoggingDeprecationHandler.INSTANCE); } + createIndexRequest.timeout(request.paramAsTime("timeout", createIndexRequest.timeout())); createIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createIndexRequest.masterNodeTimeout())); createIndexRequest.waitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards"))); return channel -> client.admin().indices().create(createIndexRequest, new RestToXContentListener<>(channel)); } + + + static Map prepareMappings(Map source, boolean includeTypeName) { + if (includeTypeName + || source.containsKey("mappings") == false + || (source.get("mappings") instanceof Map) == false) { + return source; + } + + Map newSource = new HashMap<>(source); + + @SuppressWarnings("unchecked") + Map mappings = (Map) source.get("mappings"); + if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) { + throw new IllegalArgumentException("The mapping definition cannot be nested under a type " + + "[" + MapperService.SINGLE_MAPPING_NAME + "] unless include_type_name is set to true."); + } + + newSource.put("mappings", Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, mappings)); + return newSource; + } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java index 445d393fef82b..bb0f282639bd4 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -35,7 +34,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.Map; public class RestPutIndexTemplateAction extends BaseRestHandler { @@ -59,6 +57,8 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); + PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name")); if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) { deprecationLogger.deprecatedAndMaybeLog("put_index_template_with_types", TYPES_DEPRECATION_MESSAGE); @@ -74,22 +74,11 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC putRequest.create(request.paramAsBoolean("create", false)); putRequest.cause(request.param("cause", "")); - boolean includeTypeName = request.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY); - Map sourceAsMap = prepareRequestSource(request, includeTypeName); + Map sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, + request.getXContentType()).v2(); + sourceAsMap = RestCreateIndexAction.prepareMappings(sourceAsMap, includeTypeName); putRequest.source(sourceAsMap); return channel -> client.admin().indices().putTemplate(putRequest, new RestToXContentListener<>(channel)); } - - Map prepareRequestSource(RestRequest request, boolean includeTypeName) { - Map sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, - request.getXContentType()).v2(); - if (includeTypeName == false && sourceAsMap.containsKey("mappings")) { - Map newSourceAsMap = new HashMap<>(sourceAsMap); - newSourceAsMap.put("mappings", Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, sourceAsMap.get("mappings"))); - return newSourceAsMap; - } else { - return sourceAsMap; - } - } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java index bd99c26a155a0..f5e760d54ed45 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; @@ -33,8 +34,10 @@ import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +import java.util.Map; import static org.elasticsearch.client.Requests.putMappingRequest; +import static org.elasticsearch.index.mapper.MapperService.isMappingSourceTyped; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -81,15 +84,20 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC deprecationLogger.deprecatedAndMaybeLog("put_mapping_with_types", TYPES_DEPRECATION_MESSAGE); } + PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); + final String type = request.param("type"); - if (type != null && includeTypeName == false) { + putMappingRequest.type(includeTypeName ? type : MapperService.SINGLE_MAPPING_NAME); + + Map sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, + request.getXContentType()).v2(); + if (includeTypeName == false && + (type != null || isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, sourceAsMap))) { throw new IllegalArgumentException("Types cannot be provided in put mapping requests, unless " + "the include_type_name parameter is set to true."); } - PutMappingRequest putMappingRequest = putMappingRequest(Strings.splitStringByCommaToArray(request.param("index"))); - putMappingRequest.type(includeTypeName ? type : MapperService.SINGLE_MAPPING_NAME); - putMappingRequest.source(request.requiredContent(), request.getXContentType()); + putMappingRequest.source(sourceAsMap); putMappingRequest.timeout(request.paramAsTime("timeout", putMappingRequest.timeout())); putMappingRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putMappingRequest.masterNodeTimeout())); putMappingRequest.indicesOptions(IndicesOptions.fromRequest(request, putMappingRequest.indicesOptions())); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java index 1ec0a0f949965..f37f36a8d0645 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexActionTests.java @@ -20,7 +20,11 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; @@ -59,4 +63,80 @@ public void testIncludeTypeName() throws IOException { .build(); action.prepareRequest(validRequest, mock(NodeClient.class)); } + + public void testPrepareTypelessRequest() throws IOException { + XContentBuilder content = XContentFactory.jsonBuilder().startObject() + .startObject("mappings") + .startObject("properties") + .startObject("field1").field("type", "keyword").endObject() + .startObject("field2").field("type", "text").endObject() + .endObject() + .endObject() + .startObject("aliases") + .startObject("read_alias").endObject() + .endObject() + .endObject(); + + Map contentAsMap = XContentHelper.convertToMap( + BytesReference.bytes(content), true, content.contentType()).v2(); + boolean includeTypeName = false; + Map source = RestCreateIndexAction.prepareMappings(contentAsMap, includeTypeName); + + XContentBuilder expectedContent = XContentFactory.jsonBuilder().startObject() + .startObject("mappings") + .startObject("_doc") + .startObject("properties") + .startObject("field1").field("type", "keyword").endObject() + .startObject("field2").field("type", "text").endObject() + .endObject() + .endObject() + .endObject() + .startObject("aliases") + .startObject("read_alias").endObject() + .endObject() + .endObject(); + Map expectedContentAsMap = XContentHelper.convertToMap( + BytesReference.bytes(expectedContent), true, expectedContent.contentType()).v2(); + + assertEquals(expectedContentAsMap, source); + } + + public void testPrepareTypedRequest() throws IOException { + XContentBuilder content = XContentFactory.jsonBuilder().startObject() + .startObject("mappings") + .startObject("type") + .startObject("properties") + .startObject("field1").field("type", "keyword").endObject() + .startObject("field2").field("type", "text").endObject() + .endObject() + .endObject() + .endObject() + .startObject("aliases") + .startObject("read_alias").endObject() + .endObject() + .endObject(); + + Map contentAsMap = XContentHelper.convertToMap( + BytesReference.bytes(content), true, content.contentType()).v2(); + boolean includeTypeName = true; + Map source = RestCreateIndexAction.prepareMappings(contentAsMap, includeTypeName); + + assertEquals(contentAsMap, source); + } + + public void testMalformedMappings() throws IOException { + XContentBuilder content = XContentFactory.jsonBuilder().startObject() + .field("mappings", "some string") + .startObject("aliases") + .startObject("read_alias").endObject() + .endObject() + .endObject(); + + Map contentAsMap = XContentHelper.convertToMap( + BytesReference.bytes(content), true, content.contentType()).v2(); + + boolean includeTypeName = false; + Map source = RestCreateIndexAction.prepareMappings(contentAsMap, includeTypeName); + assertEquals(contentAsMap, source); + } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java index d1900aaee84d5..2a5e5db92d40e 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateActionTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.rest.FakeRestRequest; @@ -46,51 +45,6 @@ public void setUpAction() { action = new RestPutIndexTemplateAction(Settings.EMPTY, controller()); } - public void testPrepareTypelessRequest() throws IOException { - XContentBuilder content = XContentFactory.jsonBuilder().startObject() - .startObject("mappings") - .startObject("properties") - .startObject("field1").field("type", "keyword").endObject() - .startObject("field2").field("type", "text").endObject() - .endObject() - .endObject() - .startObject("aliases") - .startObject("read_alias").endObject() - .endObject() - .endObject(); - - RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) - .withMethod(RestRequest.Method.PUT) - .withPath("/_template/_some_template") - .withContent(BytesReference.bytes(content), XContentType.JSON) - .build(); - action.prepareRequest(request, mock(NodeClient.class)); - - // Internally the above prepareRequest method calls prepareRequestSource to inject a - // default type into the mapping. Here we test that this does what is expected by - // explicitly calling that same helper function - boolean includeTypeName = false; - Map source = action.prepareRequestSource(request, includeTypeName); - - XContentBuilder expectedContent = XContentFactory.jsonBuilder().startObject() - .startObject("mappings") - .startObject("_doc") - .startObject("properties") - .startObject("field1").field("type", "keyword").endObject() - .startObject("field2").field("type", "text").endObject() - .endObject() - .endObject() - .endObject() - .startObject("aliases") - .startObject("read_alias").endObject() - .endObject() - .endObject(); - Map expectedContentAsMap = XContentHelper.convertToMap( - BytesReference.bytes(expectedContent), true, expectedContent.contentType()).v2(); - - assertEquals(expectedContentAsMap, source); - } - public void testIncludeTypeName() throws IOException { XContentBuilder typedContent = XContentFactory.jsonBuilder().startObject() .startObject("mappings") @@ -116,25 +70,5 @@ public void testIncludeTypeName() throws IOException { .build(); action.prepareRequest(request, mock(NodeClient.class)); assertWarnings(RestPutIndexTemplateAction.TYPES_DEPRECATION_MESSAGE); - boolean includeTypeName = true; - Map source = action.prepareRequestSource(request, includeTypeName); - - XContentBuilder expectedContent = XContentFactory.jsonBuilder().startObject() - .startObject("mappings") - .startObject("my_doc") - .startObject("properties") - .startObject("field1").field("type", "keyword").endObject() - .startObject("field2").field("type", "text").endObject() - .endObject() - .endObject() - .endObject() - .startObject("aliases") - .startObject("read_alias").endObject() - .endObject() - .endObject(); - Map expectedContentAsMap = XContentHelper.convertToMap( - BytesReference.bytes(expectedContent), true, expectedContent.contentType()).v2(); - - assertEquals(expectedContentAsMap, source); - } + } } diff --git a/x-pack/docs/build.gradle b/x-pack/docs/build.gradle index ecfd30bb7469b..0e5cd633a9061 100644 --- a/x-pack/docs/build.gradle +++ b/x-pack/docs/build.gradle @@ -464,16 +464,15 @@ setups['sensor_rollup_job'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword - do: xpack.rollup.put_job: id: "sensor" @@ -514,21 +513,19 @@ setups['sensor_started_rollup_job'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword - do: bulk: index: sensor-1 - type: _doc refresh: true body: | {"index":{}} @@ -588,26 +585,25 @@ setups['sensor_index'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword - load: - type: double - net_in: - type: long - net_out: - type: long - hostname: - type: keyword - datacenter: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword + load: + type: double + net_in: + type: long + net_out: + type: long + hostname: + type: keyword + datacenter: + type: keyword ''' setups['sensor_prefab_data'] = ''' @@ -619,16 +615,15 @@ setups['sensor_prefab_data'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - timestamp: - type: date - temperature: - type: long - voltage: - type: float - node: - type: keyword + properties: + timestamp: + type: date + temperature: + type: long + voltage: + type: float + node: + type: keyword - do: indices.create: index: sensor_rollup @@ -637,63 +632,61 @@ setups['sensor_prefab_data'] = ''' number_of_shards: 1 number_of_replicas: 0 mappings: - _doc: - properties: - node.terms.value: - type: keyword - temperature.sum.value: - type: double - temperature.max.value: - type: double - temperature.min.value: - type: double - timestamp.date_histogram.time_zone: - type: keyword - timestamp.date_histogram.interval: - type: keyword - timestamp.date_histogram.timestamp: - type: date - timestamp.date_histogram._count: - type: long - voltage.avg.value: - type: double - voltage.avg._count: - type: long - _rollup.id: - type: keyword - _rollup.version: - type: long - _meta: - _rollup: - sensor: - cron: "* * * * * ?" - rollup_index: "sensor_rollup" - index_pattern: "sensor-*" - timeout: "20s" - page_size: 1000 - groups: - date_histogram: - field: "timestamp" - interval: "7d" - time_zone: "UTC" - terms: - fields: - - "node" - id: sensor - metrics: - - field: "temperature" - metrics: - - min - - max - - sum - - field: "voltage" - metrics: - - avg + properties: + node.terms.value: + type: keyword + temperature.sum.value: + type: double + temperature.max.value: + type: double + temperature.min.value: + type: double + timestamp.date_histogram.time_zone: + type: keyword + timestamp.date_histogram.interval: + type: keyword + timestamp.date_histogram.timestamp: + type: date + timestamp.date_histogram._count: + type: long + voltage.avg.value: + type: double + voltage.avg._count: + type: long + _rollup.id: + type: keyword + _rollup.version: + type: long + _meta: + _rollup: + sensor: + cron: "* * * * * ?" + rollup_index: "sensor_rollup" + index_pattern: "sensor-*" + timeout: "20s" + page_size: 1000 + groups: + date_histogram: + field: "timestamp" + interval: "7d" + time_zone: "UTC" + terms: + fields: + - "node" + id: sensor + metrics: + - field: "temperature" + metrics: + - min + - max + - sum + - field: "voltage" + metrics: + - avg - do: bulk: index: sensor_rollup - type: _doc refresh: true body: | {"index":{}} diff --git a/x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/indexlifecycle/CCRIndexLifecycleIT.java b/x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/indexlifecycle/CCRIndexLifecycleIT.java index 01f0eb4c7d0d4..b3c93acb97b99 100644 --- a/x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/indexlifecycle/CCRIndexLifecycleIT.java +++ b/x-pack/plugin/ilm/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/indexlifecycle/CCRIndexLifecycleIT.java @@ -210,7 +210,7 @@ public void testCcrAndIlmWithRollover() throws Exception { // Create an index on the leader using the template set up above Request createIndexRequest = new Request("PUT", "/" + indexName); createIndexRequest.setJsonEntity("{" + - "\"mappings\": {\"_doc\": {\"properties\": {\"field\": {\"type\": \"keyword\"}}}}, " + + "\"mappings\": {\"properties\": {\"field\": {\"type\": \"keyword\"}}}, " + "\"aliases\": {\"" + alias + "\": {\"is_write_index\": true}} }"); assertOK(leaderClient.performRequest(createIndexRequest)); // Check that the new index is created diff --git a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DataLoader.java b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DataLoader.java index efa39ec517eb2..b12203294c158 100644 --- a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DataLoader.java +++ b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DataLoader.java @@ -83,50 +83,46 @@ private static void loadEmpDatasetIntoEs(RestClient client, String index, String createIndex.endObject(); createIndex.startObject("mappings"); { - createIndex.startObject("_doc"); + createIndex.startObject("properties"); { - createIndex.startObject("properties"); + createIndex.startObject("emp_no").field("type", "integer"); + if (extraFields) { + createIndex.field("copy_to", "extra_no"); + } + createIndex.endObject(); + if (extraFields) { + createIndex.startObject("extra_no").field("type", "integer").endObject(); + } + createString("first_name", createIndex); + createString("last_name", createIndex); + createIndex.startObject("gender").field("type", "keyword"); + if (extraFields) { + createIndex.field("copy_to", "extra_gender"); + } + createIndex.endObject(); + + if (extraFields) { + createIndex.startObject("extra_gender").field("type", "keyword").endObject(); + createIndex.startObject("extra.info.gender") + .field("type", "alias") + .field("path", "gender") + .endObject(); + } + + createIndex.startObject("birth_date").field("type", "date").endObject(); + createIndex.startObject("hire_date").field("type", "date").endObject(); + createIndex.startObject("salary").field("type", "integer").endObject(); + createIndex.startObject("languages").field("type", "byte").endObject(); { - createIndex.startObject("emp_no").field("type", "integer"); - if (extraFields) { - createIndex.field("copy_to", "extra_no"); - } + createIndex.startObject("dep").field("type", "nested"); + createIndex.startObject("properties"); + createIndex.startObject("dep_id").field("type", "keyword").endObject(); + createString("dep_name", createIndex); + createIndex.startObject("from_date").field("type", "date").endObject(); + createIndex.startObject("to_date").field("type", "date").endObject(); createIndex.endObject(); - if (extraFields) { - createIndex.startObject("extra_no").field("type", "integer").endObject(); - } - createString("first_name", createIndex); - createString("last_name", createIndex); - createIndex.startObject("gender").field("type", "keyword"); - if (extraFields) { - createIndex.field("copy_to", "extra_gender"); - } createIndex.endObject(); - - if (extraFields) { - createIndex.startObject("extra_gender").field("type", "keyword").endObject(); - createIndex.startObject("extra.info.gender") - .field("type", "alias") - .field("path", "gender") - .endObject(); - } - - createIndex.startObject("birth_date").field("type", "date").endObject(); - createIndex.startObject("hire_date").field("type", "date").endObject(); - createIndex.startObject("salary").field("type", "integer").endObject(); - createIndex.startObject("languages").field("type", "byte").endObject(); - { - createIndex.startObject("dep").field("type", "nested"); - createIndex.startObject("properties"); - createIndex.startObject("dep_id").field("type", "keyword").endObject(); - createString("dep_name", createIndex); - createIndex.startObject("from_date").field("type", "date").endObject(); - createIndex.startObject("to_date").field("type", "date").endObject(); - createIndex.endObject(); - createIndex.endObject(); - } } - createIndex.endObject(); } createIndex.endObject(); } @@ -211,20 +207,16 @@ protected static void loadLogsDatasetIntoEs(RestClient client, String index, Str createIndex.endObject(); createIndex.startObject("mappings"); { - createIndex.startObject("_doc"); + createIndex.startObject("properties"); { - createIndex.startObject("properties"); - { - createIndex.startObject("id").field("type", "integer").endObject(); - createIndex.startObject("@timestamp").field("type", "date").endObject(); - createIndex.startObject("bytes_in").field("type", "integer").endObject(); - createIndex.startObject("bytes_out").field("type", "integer").endObject(); - createIndex.startObject("client_ip").field("type", "ip").endObject(); - createIndex.startObject("client_port").field("type", "integer").endObject(); - createIndex.startObject("dest_ip").field("type", "ip").endObject(); - createIndex.startObject("status").field("type", "keyword").endObject(); - } - createIndex.endObject(); + createIndex.startObject("id").field("type", "integer").endObject(); + createIndex.startObject("@timestamp").field("type", "date").endObject(); + createIndex.startObject("bytes_in").field("type", "integer").endObject(); + createIndex.startObject("bytes_out").field("type", "integer").endObject(); + createIndex.startObject("client_ip").field("type", "ip").endObject(); + createIndex.startObject("client_port").field("type", "integer").endObject(); + createIndex.startObject("dest_ip").field("type", "ip").endObject(); + createIndex.startObject("status").field("type", "keyword").endObject(); } createIndex.endObject(); } @@ -263,16 +255,12 @@ protected static void loadLibDatasetIntoEs(RestClient client, String index) thro createIndex.endObject(); createIndex.startObject("mappings"); { - createIndex.startObject("_doc"); + createIndex.startObject("properties"); { - createIndex.startObject("properties"); - { - createString("name", createIndex); - createString("author", createIndex); - createIndex.startObject("release_date").field("type", "date").endObject(); - createIndex.startObject("page_count").field("type", "short").endObject(); - } - createIndex.endObject(); + createString("name", createIndex); + createString("author", createIndex); + createIndex.startObject("release_date").field("type", "date").endObject(); + createIndex.startObject("page_count").field("type", "short").endObject(); } createIndex.endObject(); } @@ -329,4 +317,4 @@ private static void csvToLines(String name, CheckedBiConsumer, List public static InputStream readFromJarUrl(URL source) throws IOException { return source.openStream(); } -} \ No newline at end of file +} diff --git a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/FetchSizeTestCase.java b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/FetchSizeTestCase.java index 86fa4805ba6ea..3da3c0ba73bc2 100644 --- a/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/FetchSizeTestCase.java +++ b/x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/FetchSizeTestCase.java @@ -30,16 +30,12 @@ public void createTestIndex() throws IOException { XContentBuilder createIndex = JsonXContent.contentBuilder().startObject(); createIndex.startObject("mappings"); { - createIndex.startObject("_doc"); + createIndex.startObject("properties"); { + createIndex.startObject("nested").field("type", "nested"); createIndex.startObject("properties"); - { - createIndex.startObject("nested").field("type", "nested"); - createIndex.startObject("properties"); - createIndex.startObject("inner_field").field("type", "integer").endObject(); - createIndex.endObject(); - createIndex.endObject(); - } + createIndex.startObject("inner_field").field("type", "integer").endObject(); + createIndex.endObject(); createIndex.endObject(); } createIndex.endObject(); diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/delete_job.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/delete_job.yml index 2208502b3e4cf..40fa404f36147 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/delete_job.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/delete_job.yml @@ -6,12 +6,11 @@ setup: index: foo body: mappings: - _doc: - properties: - the_field: - type: date - value_field: - type: integer + properties: + the_field: + type: date + value_field: + type: integer - do: headers: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/get_jobs.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/get_jobs.yml index 3e03ac924ec89..6332302e67418 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/get_jobs.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/get_jobs.yml @@ -6,12 +6,11 @@ setup: index: foo body: mappings: - _doc: - properties: - the_field: - type: date - value_field: - type: integer + properties: + the_field: + type: date + value_field: + type: integer --- "Test basic get_jobs": diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml index 7f3f0347ec0df..f8cfe85cc2e6a 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml @@ -6,12 +6,11 @@ setup: index: foo body: mappings: - _doc: - properties: - the_field: - type: date - value_field: - type: integer + properties: + the_field: + type: date + value_field: + type: integer --- "Test basic put_job": diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml index 0865cf084eb61..9af896f4c9fab 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/rollup_search.yml @@ -6,14 +6,13 @@ setup: index: foo body: mappings: - _doc: - properties: - timestamp: - type: date - partition: - type: keyword - price: - type: integer + properties: + timestamp: + type: date + partition: + type: keyword + price: + type: integer - do: headers: @@ -51,7 +50,6 @@ setup: body: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -67,7 +65,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -83,7 +80,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -99,7 +95,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -115,7 +110,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -319,7 +313,6 @@ setup: body: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -335,7 +328,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -351,7 +343,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -367,7 +358,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -383,7 +373,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -467,7 +456,6 @@ setup: body: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -483,7 +471,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -499,7 +486,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -515,7 +501,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -531,7 +516,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -617,7 +601,6 @@ setup: body: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -633,7 +616,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -649,7 +631,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -665,7 +646,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -681,7 +661,6 @@ setup: - index: _index: "foo_rollup" - _type: "_doc" - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z" timestamp.date_histogram.interval: "1h" timestamp.date_histogram.time_zone: "UTC" @@ -760,14 +739,13 @@ setup: index: bar body: mappings: - _doc: - properties: - timestamp: - type: date - partition: - type: keyword - price: - type: integer + properties: + timestamp: + type: date + partition: + type: keyword + price: + type: integer - do: headers: @@ -849,14 +827,13 @@ setup: index: bar body: mappings: - _doc: - properties: - timestamp: - type: date - partition: - type: keyword - price: - type: integer + properties: + timestamp: + type: date + partition: + type: keyword + price: + type: integer - do: headers: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml index c42ab9d06f6ce..5a53847187484 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/security_tests.yml @@ -48,18 +48,16 @@ teardown: index: foo body: mappings: - _doc: - properties: - timestamp: - type: date - value_field: - type: integer + properties: + timestamp: + type: date + value_field: + type: integer - do: headers: Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser index: index: foo - type: _doc body: timestamp: 123 value_field: 1232 @@ -69,18 +67,16 @@ teardown: index: foobar body: mappings: - _doc: - properties: - timestamp: - type: date - value_field: - type: integer + properties: + timestamp: + type: date + value_field: + type: integer - do: headers: Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser index: index: foobar - type: _doc body: timestamp: 123 value_field: 456 @@ -220,20 +216,18 @@ teardown: index: foo body: mappings: - _doc: - properties: - timestamp: - type: date - value_field: - type: integer - visibility: - type: keyword + properties: + timestamp: + type: date + value_field: + type: integer + visibility: + type: keyword - do: headers: Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser index: index: foo - type: _doc body: timestamp: 123 value_field: 1232 @@ -243,7 +237,6 @@ teardown: Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser index: index: foobar - type: _doc body: timestamp: 123 value_field: 456 diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/start_job.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/start_job.yml index 0ed11ab1b04a0..88619e0dfc8ee 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/start_job.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/start_job.yml @@ -6,12 +6,11 @@ setup: index: foo body: mappings: - _doc: - properties: - the_field: - type: date - value_field: - type: integer + properties: + the_field: + type: date + value_field: + type: integer - do: headers: diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/stop_job.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/stop_job.yml index c19325bf707de..bcb592be7a074 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/stop_job.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/stop_job.yml @@ -6,12 +6,11 @@ setup: index: foo body: mappings: - _doc: - properties: - the_field: - type: date - value_field: - type: integer + properties: + the_field: + type: date + value_field: + type: integer - do: headers: diff --git a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java index 1feb05b9c6468..feddc57f6e014 100644 --- a/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java +++ b/x-pack/qa/multi-node/src/test/java/org/elasticsearch/multi_node/RollupIT.java @@ -69,7 +69,7 @@ public void testBigRollup() throws Exception { try (XContentBuilder builder = jsonBuilder()) { builder.startObject(); { - builder.startObject("mappings").startObject("_doc") + builder.startObject("mappings") .startObject("properties") .startObject("timestamp") .field("type", "date") @@ -78,7 +78,6 @@ public void testBigRollup() throws Exception { .startObject("value") .field("type", "integer") .endObject() - .endObject() .endObject().endObject(); } builder.endObject();