|
22 | 22 | import org.elasticsearch.action.ActionRequestValidationException;
|
23 | 23 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
24 | 24 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequestTests;
|
| 25 | +import org.elasticsearch.common.bytes.BytesArray; |
25 | 26 | import org.elasticsearch.common.bytes.BytesReference;
|
26 | 27 | import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
27 | 28 | import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
|
32 | 33 | import org.elasticsearch.common.unit.TimeValue;
|
33 | 34 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
34 | 35 | import org.elasticsearch.common.xcontent.XContentFactory;
|
| 36 | +import org.elasticsearch.common.xcontent.XContentHelper; |
35 | 37 | import org.elasticsearch.common.xcontent.XContentParseException;
|
36 | 38 | import org.elasticsearch.common.xcontent.XContentType;
|
37 | 39 | import org.elasticsearch.index.RandomCreateIndexGenerator;
|
| 40 | +import org.elasticsearch.index.mapper.MapperService; |
38 | 41 | import org.elasticsearch.indices.IndicesModule;
|
39 | 42 | import org.elasticsearch.test.ESTestCase;
|
40 | 43 | import org.elasticsearch.test.XContentTestUtils;
|
@@ -115,6 +118,35 @@ public void testParsingWithIndexSettings() throws Exception {
|
115 | 118 | assertThat(request.getCreateIndexRequest().settings().getAsInt("number_of_shards", 0), equalTo(10));
|
116 | 119 | }
|
117 | 120 |
|
| 121 | + public void testTypelessMappingParsing() throws Exception { |
| 122 | + final RolloverRequest request = new RolloverRequest(randomAlphaOfLength(10), randomAlphaOfLength(10)); |
| 123 | + final XContentBuilder builder = XContentFactory.jsonBuilder() |
| 124 | + .startObject() |
| 125 | + .startObject("mappings") |
| 126 | + .startObject("properties") |
| 127 | + .startObject("field1") |
| 128 | + .field("type", "keyword") |
| 129 | + .endObject() |
| 130 | + .endObject() |
| 131 | + .endObject() |
| 132 | + .endObject(); |
| 133 | + |
| 134 | + boolean includeTypeName = false; |
| 135 | + request.fromXContent(includeTypeName, createParser(builder)); |
| 136 | + |
| 137 | + CreateIndexRequest createIndexRequest = request.getCreateIndexRequest(); |
| 138 | + String mapping = createIndexRequest.mappings().get(MapperService.SINGLE_MAPPING_NAME); |
| 139 | + assertNotNull(mapping); |
| 140 | + |
| 141 | + Map<String, Object> parsedMapping = XContentHelper.convertToMap( |
| 142 | + new BytesArray(mapping), false, XContentType.JSON).v2(); |
| 143 | + |
| 144 | + @SuppressWarnings("unchecked") |
| 145 | + Map<String, Object> properties = (Map<String, Object>) parsedMapping.get(MapperService.SINGLE_MAPPING_NAME); |
| 146 | + assertNotNull(properties); |
| 147 | + assertFalse(properties.isEmpty()); |
| 148 | + } |
| 149 | + |
118 | 150 | public void testSerialize() throws Exception {
|
119 | 151 | RolloverRequest originalRequest = new RolloverRequest("alias-index", "new-index-name");
|
120 | 152 | originalRequest.addMaxIndexDocsCondition(randomNonNegativeLong());
|
|
0 commit comments