diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java index 165dbe66f5f66..04ac52376d4c9 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java @@ -64,11 +64,11 @@ static int getFrequency(TokenStream tk) throws IOException { } public void testDefaults() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "rank_feature").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -99,12 +99,12 @@ public void testDefaults() throws Exception { } public void testNegativeScoreImpact() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "rank_feature") .field("positive_score_impact", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -135,12 +135,12 @@ public void testNegativeScoreImpact() throws Exception { } public void testRejectMultiValuedFields() throws MapperParsingException, IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "rank_feature").endObject().startObject("foo") .startObject("properties").startObject("field").field("type", "rank_feature").endObject().endObject() .endObject().endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapperTests.java index 46c2316aa161e..f293e10f9e9ea 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureMetaFieldMapperTests.java @@ -44,13 +44,13 @@ public void setup() { protected Collection> getPlugins() { return pluginList(MapperExtrasPlugin.class); } - + public void testBasics() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "rank_feature").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); assertNotNull(mapper.metadataMapper(RankFeatureMetaFieldMapper.class)); diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java index ea8f2ed16f81b..f6dd518191e2c 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java @@ -53,11 +53,11 @@ protected Collection> getPlugins() { } public void testDefaults() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "rank_features").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -85,12 +85,12 @@ public void testDefaults() throws Exception { } public void testRejectMultiValuedFields() throws MapperParsingException, IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "rank_features").endObject().startObject("foo") .startObject("properties").startObject("field").field("type", "rank_features").endObject().endObject() .endObject().endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java index c5c7358c8220f..94ae0cee76bb7 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java @@ -58,12 +58,12 @@ protected Collection> getPlugins() { } public void testDefaults() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("scaling_factor", 10.0).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -108,12 +108,12 @@ public void testIllegalScalingFactor() throws IOException { } public void testNotIndexed() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("index", false).field("scaling_factor", 10.0).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -132,12 +132,12 @@ public void testNotIndexed() throws Exception { } public void testNoDocValues() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("doc_values", false).field("scaling_factor", 10.0).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -156,12 +156,12 @@ public void testNoDocValues() throws Exception { } public void testStore() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("store", true).field("scaling_factor", 10.0).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -185,12 +185,12 @@ public void testStore() throws Exception { } public void testCoerce() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("scaling_factor", 10.0).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -209,12 +209,12 @@ public void testCoerce() throws Exception { IndexableField dvField = fields[1]; assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType()); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("scaling_factor", 10.0).field("coerce", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper2 = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper2.mappingSource().toString()); @@ -238,12 +238,12 @@ public void testIgnoreMalformed() throws Exception { } private void doTestIgnoreMalformed(String value, String exceptionMessageContains) throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("scaling_factor", 10.0).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -256,12 +256,12 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains MapperParsingException e = expectThrows(MapperParsingException.class, runnable); assertThat(e.getCause().getMessage(), containsString(exceptionMessageContains)); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "scaled_float") .field("scaling_factor", 10.0).field("ignore_malformed", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper2 = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); ParsedDocument doc = mapper2.parse(new SourceToParse("test", "1", BytesReference .bytes(XContentFactory.jsonBuilder() @@ -276,7 +276,7 @@ private void doTestIgnoreMalformed(String value, String exceptionMessageContains public void testNullValue() throws IOException { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "scaled_float") @@ -285,7 +285,7 @@ public void testNullValue() throws IOException { .endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -297,7 +297,7 @@ public void testNullValue() throws IOException { assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "scaled_float") @@ -307,7 +307,7 @@ public void testNullValue() throws IOException { .endObject() .endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); doc = mapper.parse(new SourceToParse("test", "1", BytesReference diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java index 630113daf621f..e4db71bc07bb7 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java @@ -64,11 +64,11 @@ public void setup() { } public void testDefaults() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -105,11 +105,11 @@ public void testDefaults() throws Exception { } public void testNullValue() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -120,12 +120,12 @@ public void testNullValue() throws IOException { XContentType.JSON)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE) .field("null_value", "1234").endObject().endObject() .endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -155,12 +155,12 @@ public void testNullValue() throws IOException { } public void testEnableStore() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE) .field("store", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -177,12 +177,12 @@ public void testEnableStore() throws IOException { } public void testDisableIndex() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE) .field("index", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -200,12 +200,12 @@ public void testDisableIndex() throws IOException { } public void testDisableDocValues() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE) .field("doc_values", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -222,11 +222,11 @@ public void testDisableDocValues() throws IOException { } public void testMultipleValues() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -284,12 +284,12 @@ public void testMultipleValues() throws IOException { } public void testIndexOptions() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE) .field("index_options", "freqs").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -317,12 +317,12 @@ public void testIndexOptions() throws IOException { } public void testEnableNorms() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE) .field("norms", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -339,14 +339,14 @@ public void testEnableNorms() throws IOException { } public void testCollator() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", FIELD_TYPE) .field("language", "tr") .field("strength", "primary") .endObject().endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -406,12 +406,12 @@ public void testUpdateCollator() throws IOException { public void testIgnoreAbove() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", FIELD_TYPE) .field("ignore_above", 5).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); diff --git a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java index 885bf834ab23d..5acc8c9a82280 100644 --- a/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java +++ b/plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java @@ -252,11 +252,11 @@ public void testAgainstTermVectorsAPI() throws IOException { // ===== Code below copied from TextFieldMapperTests ======== public void testDefaults() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", getFieldType()).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -284,11 +284,11 @@ public void testDefaults() throws IOException { } public void testEnableStore() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", getFieldType()).field("store", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -305,14 +305,14 @@ public void testEnableStore() throws IOException { } public void testDisableNorms() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", getFieldType()) .field("norms", false) .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -360,11 +360,11 @@ public void testIndexOptions() throws IOException { } public void testDefaultPositionIncrementGap() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", getFieldType()).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = indexService.mapperService().merge("_doc", + DocumentMapper mapper = indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); @@ -399,14 +399,14 @@ public void testDefaultPositionIncrementGap() throws IOException { public void testPositionIncrementGap() throws IOException { final int positionIncrementGap = randomIntBetween(1, 1000); - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", getFieldType()) .field("position_increment_gap", positionIncrementGap) .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = indexService.mapperService().merge("_doc", + DocumentMapper mapper = indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); @@ -440,7 +440,7 @@ public void testPositionIncrementGap() throws IOException { } public void testSearchAnalyzerSerialization() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", getFieldType()) @@ -449,11 +449,11 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); // special case: default index analyzer - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", getFieldType()) @@ -462,10 +462,10 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", getFieldType()) @@ -473,11 +473,11 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); // special case: default search analyzer - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", getFieldType()) @@ -486,17 +486,17 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", getFieldType()) .field("analyzer", "keyword") .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); @@ -510,7 +510,7 @@ public void testSearchAnalyzerSerialization() throws IOException { } public void testSearchQuoteAnalyzerSerialization() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", getFieldType()) @@ -520,11 +520,11 @@ public void testSearchQuoteAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); // special case: default index/search analyzer - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", getFieldType()) @@ -534,7 +534,7 @@ public void testSearchQuoteAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java index 1307e74f9f2f5..d4f16bcaf8458 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java @@ -74,22 +74,25 @@ public DocumentMapper parse(@Nullable String type, CompressedXContent source) th if (source != null) { Map root = XContentHelper.convertToMap(source.compressedReference(), true, XContentType.JSON).v2(); Tuple> t = extractMapping(type, root); + type = t.v1(); mapping = t.v2(); } if (mapping == null) { mapping = new HashMap<>(); } - return parse(mapping); + return parse(type, mapping); } @SuppressWarnings({"unchecked"}) - private DocumentMapper parse(Map mapping) throws MapperParsingException { + private DocumentMapper parse(String type, Map mapping) throws MapperParsingException { + if (type == null) { + throw new MapperParsingException("Failed to derive type"); + } Mapper.TypeParser.ParserContext parserContext = parserContext(); // parse RootObjectMapper DocumentMapper.Builder docBuilder = new DocumentMapper.Builder( - (RootObjectMapper.Builder) rootObjectTypeParser.parse(MapperService.SINGLE_MAPPING_NAME, mapping, parserContext), - mapperService); + (RootObjectMapper.Builder) rootObjectTypeParser.parse(type, mapping, parserContext), mapperService); Iterator> iterator = mapping.entrySet().iterator(); // parse DocumentMapper while(iterator.hasNext()) { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java index d8712f582a5e5..1fd3f51ece916 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java @@ -180,7 +180,7 @@ public void testParsesBooleansNestedStrict() throws IOException { public void testMultiFields() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "boolean") @@ -192,7 +192,7 @@ public void testMultiFields() throws IOException { .endObject().endObject() .endObject().endObject()); DocumentMapper mapper = indexService.mapperService() - .merge("_doc", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); + .merge("type", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder() .startObject() diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java index 445611aba40fb..6805db662821f 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java @@ -232,7 +232,7 @@ public void testCopyToDynamicInnerInnerObjectParsing() throws Exception { } public void testCopyToStrictDynamicInnerObjectParsing() throws Exception { - String mapping = Strings.toString(jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(jsonBuilder().startObject().startObject("type1") .field("dynamic", "strict") .startObject("properties") .startObject("copy_test") @@ -243,7 +243,7 @@ public void testCopyToStrictDynamicInnerObjectParsing() throws Exception { .endObject().endObject()); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser() - .parse("_doc", new CompressedXContent(mapping)); + .parse("type1", new CompressedXContent(mapping)); BytesReference json = BytesReference.bytes(jsonBuilder().startObject() .field("copy_test", "foo") @@ -253,7 +253,7 @@ public void testCopyToStrictDynamicInnerObjectParsing() throws Exception { docMapper.parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc(); fail(); } catch (MapperParsingException ex) { - assertThat(ex.getMessage(), startsWith("mapping set to strict, dynamic introduction of [very] within [_doc] is not allowed")); + assertThat(ex.getMessage(), startsWith("mapping set to strict, dynamic introduction of [very] within [type1] is not allowed")); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java index e7b2b90832ae6..477cf7de8285c 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java @@ -62,11 +62,11 @@ protected Collection> getPlugins() { } public void testDefaults() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "date").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -91,11 +91,11 @@ public void testDefaults() throws Exception { } public void testNotIndexed() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "date").field("index", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -113,11 +113,11 @@ public void testNotIndexed() throws Exception { } public void testNoDocValues() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "date").field("doc_values", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -135,11 +135,11 @@ public void testNoDocValues() throws Exception { } public void testStore() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "date").field("store", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -169,11 +169,11 @@ public void testIgnoreMalformed() throws IOException { } private void testIgnoreMalfomedForValue(String value, String expectedException) throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "date").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -206,12 +206,12 @@ private void testIgnoreMalfomedForValue(String value, String expectedException) } public void testChangeFormat() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "date") .field("format", "epoch_second").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -230,13 +230,13 @@ public void testChangeFormat() throws IOException { public void testChangeLocale() throws IOException { assumeTrue("need java 9 for testing ",JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0); - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "date") .field("format", "E, d MMM yyyy HH:mm:ss Z") .field("locale", "de") .endObject().endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -250,7 +250,7 @@ public void testChangeLocale() throws IOException { public void testNullValue() throws IOException { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "date") @@ -258,7 +258,7 @@ public void testNullValue() throws IOException { .endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -270,7 +270,7 @@ public void testNullValue() throws IOException { assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "date") @@ -279,7 +279,7 @@ public void testNullValue() throws IOException { .endObject() .endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -332,7 +332,7 @@ public void testTimeZoneParsing() throws Exception { final String timeZonePattern = "yyyy-MM-dd" + randomFrom("XXX", "[XXX]", "'['XXX']'"); String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "date") @@ -341,7 +341,7 @@ public void testTimeZoneParsing() throws Exception { .endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); DateFormatter formatter = DateFormatter.forPattern(timeZonePattern); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperParserTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperParserTests.java index b16ecb9a1591b..c35e083d687b1 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperParserTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperParserTests.java @@ -25,7 +25,17 @@ import org.elasticsearch.index.IndexService; import org.elasticsearch.test.ESSingleNodeTestCase; +import static org.hamcrest.Matchers.equalTo; + public class DocumentMapperParserTests extends ESSingleNodeTestCase { + public void testTypeLevel() throws Exception { + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") + .endObject().endObject()); + + DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); + assertThat(mapper.type(), equalTo("type")); + } public void testFieldNameWithDots() throws Exception { IndexService indexService = createIndex("test"); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java index 8a14c1fbcca36..724c53d04f15b 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java @@ -155,7 +155,7 @@ public void testChangeSearchAnalyzerToDefault() throws Exception { public void testConcurrentMergeTest() throws Throwable { final MapperService mapperService = createIndex("test").mapperService(); - mapperService.merge("_doc", new CompressedXContent("{\"_doc\":{}}"), MapperService.MergeReason.MAPPING_UPDATE); + mapperService.merge("test", new CompressedXContent("{\"test\":{}}"), MapperService.MergeReason.MAPPING_UPDATE); final DocumentMapper documentMapper = mapperService.documentMapper(); DocumentFieldMappers dfm = documentMapper.mappers(); @@ -184,7 +184,7 @@ public void run() { Mapping update = doc.dynamicMappingsUpdate(); assert update != null; lastIntroducedFieldName.set(fieldName); - mapperService.merge("_doc", new CompressedXContent(update.toString()), MapperService.MergeReason.MAPPING_UPDATE); + mapperService.merge("test", new CompressedXContent(update.toString()), MapperService.MergeReason.MAPPING_UPDATE); } } catch (Exception e) { error.set(e); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index 1d76efdd008b4..e430125f28187 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -549,7 +549,7 @@ public void testDynamicStrictLongArray() throws Exception { .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))); - assertEquals("mapping set to strict, dynamic introduction of [foo] within [_doc] is not allowed", exception.getMessage()); + assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } public void testMappedGeoPointArray() throws Exception { @@ -631,7 +631,7 @@ public void testDynamicStrictObject() throws Exception { .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))); - assertEquals("mapping set to strict, dynamic introduction of [foo] within [_doc] is not allowed", exception.getMessage()); + assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } public void testDynamicFalseValue() throws Exception { @@ -662,7 +662,7 @@ public void testDynamicStrictValue() throws Exception { .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))); - assertEquals("mapping set to strict, dynamic introduction of [bar] within [_doc] is not allowed", exception.getMessage()); + assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } public void testDynamicFalseNull() throws Exception { @@ -693,7 +693,7 @@ public void testDynamicStrictNull() throws Exception { .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))); - assertEquals("mapping set to strict, dynamic introduction of [bar] within [_doc] is not allowed", exception.getMessage()); + assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); } public void testMappedNullValue() throws Exception { @@ -892,7 +892,7 @@ public void testDynamicStrictDottedFieldNameLongArray() throws Exception { .endArray().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))); - assertEquals("mapping set to strict, dynamic introduction of [foo] within [_doc] is not allowed", exception.getMessage()); + assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } public void testDynamicDottedFieldNameLong() throws Exception { @@ -1009,7 +1009,7 @@ public void testDynamicStrictDottedFieldNameLong() throws Exception { .endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))); - assertEquals("mapping set to strict, dynamic introduction of [foo] within [_doc] is not allowed", exception.getMessage()); + assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } public void testDynamicDottedFieldNameObject() throws Exception { @@ -1136,7 +1136,7 @@ public void testDynamicStrictDottedFieldNameObject() throws Exception { .endObject().endObject()); StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, () -> mapper.parse(new SourceToParse("test", "1", bytes, XContentType.JSON))); - assertEquals("mapping set to strict, dynamic introduction of [foo] within [_doc] is not allowed", exception.getMessage()); + assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); } public void testDocumentContainsMetadataField() throws Exception { @@ -1175,7 +1175,7 @@ public void testParseToJsonAndParse() throws Exception { DocumentMapper docMapper = parser.parse("person", new CompressedXContent(mapping)); String builtMapping = docMapper.mappingSource().string(); // reparse it - DocumentMapper builtDocMapper = parser.parse("_doc", new CompressedXContent(builtMapping)); + DocumentMapper builtDocMapper = parser.parse("person", new CompressedXContent(builtMapping)); BytesReference json = new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/mapper/simple/test1.json")); Document doc = builtDocMapper.parse(new SourceToParse("test", "1", json, XContentType.JSON)).rootDoc(); assertThat(doc.getBinaryValue(docMapper.idFieldMapper().name()), equalTo(Uid.encodeId("1"))); @@ -1213,7 +1213,7 @@ public void testAttributes() throws Exception { assertThat((String) docMapper.meta().get("param1"), equalTo("value1")); String builtMapping = docMapper.mappingSource().string(); - DocumentMapper builtDocMapper = parser.parse("_doc", new CompressedXContent(builtMapping)); + DocumentMapper builtDocMapper = parser.parse("person", new CompressedXContent(builtMapping)); assertThat((String) builtDocMapper.meta().get("param1"), equalTo("value1")); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java index bb0a0af1b64a3..9e0d9155d43bd 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java @@ -123,7 +123,7 @@ public void testDynamicStrict() throws IOException { .field("field2", "value2") .endObject()), XContentType.JSON))); - assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [_doc] is not allowed")); + assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed")); e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse(new SourceToParse("test", "1", @@ -133,7 +133,7 @@ public void testDynamicStrict() throws IOException { .field("field2", (String) null) .endObject()), XContentType.JSON))); - assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [_doc] is not allowed")); + assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed")); } public void testDynamicFalseWithInnerObjectButDynamicSetOnRoot() throws IOException { @@ -234,10 +234,10 @@ public void testField() throws Exception { IndexService indexService = createIndex("test"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc").endObject() + .startObject("type").endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject().field("foo", "bar").endObject()); @@ -245,7 +245,7 @@ public void testField() throws Exception { // original mapping not modified assertEquals(mapping, serialize(mapper)); // but we have an update - assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties") + assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("foo") .field("type", "text") .startObject("fields") @@ -263,11 +263,11 @@ public void testIncremental() throws Exception { DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); // Make sure that mapping updates are incremental, this is important for performance otherwise // every new field introduction runs in linear time with the total number of fields - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("foo").field("type", "text").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject().field("foo", "bar") @@ -276,7 +276,7 @@ public void testIncremental() throws Exception { // original mapping not modified assertEquals(mapping, serialize(mapper)); // but we have an update - assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties") + assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") // foo is NOT in the update .startObject("bar").field("type", "text") .startObject("fields") @@ -293,10 +293,10 @@ public void testIntroduceTwoFields() throws Exception { IndexService indexService = createIndex("test"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc").endObject() + .startObject("type").endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject().field("foo", "bar") @@ -305,7 +305,7 @@ public void testIntroduceTwoFields() throws Exception { // original mapping not modified assertEquals(mapping, serialize(mapper)); // but we have an update - assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties") + assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("bar").field("type", "text") .startObject("fields") .startObject("keyword") @@ -329,10 +329,10 @@ public void testObject() throws Exception { IndexService indexService = createIndex("test"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc").endObject() + .startObject("type").endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject().startObject("foo").startObject("bar") @@ -341,7 +341,7 @@ public void testObject() throws Exception { // original mapping not modified assertEquals(mapping, serialize(mapper)); // but we have an update - assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties") + assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("foo").startObject("properties").startObject("bar").startObject("properties").startObject("baz") .field("type", "text") .startObject("fields").startObject("keyword").field("type", "keyword") @@ -354,10 +354,10 @@ public void testArray() throws Exception { IndexService indexService = createIndex("test"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc").endObject() + .startObject("type").endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject() @@ -366,7 +366,7 @@ public void testArray() throws Exception { // original mapping not modified assertEquals(mapping, serialize(mapper)); // but we have an update - assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties") + assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("foo") .field("type", "text") .startObject("fields") @@ -382,11 +382,11 @@ public void testArray() throws Exception { public void testInnerDynamicMapping() throws Exception { IndexService indexService = createIndex("test"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") .startObject("properties") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("foo").field("type", "object").endObject() .endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject().startObject("foo") @@ -395,7 +395,7 @@ public void testInnerDynamicMapping() throws Exception { // original mapping not modified assertEquals(mapping, serialize(mapper)); // but we have an update - assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties") + assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("foo").startObject("properties").startObject("bar").startObject("properties") .startObject("baz").field("type", "text").startObject("fields") .startObject("keyword").field("type", "keyword").field("ignore_above", 256).endObject() @@ -407,10 +407,10 @@ public void testComplexArray() throws Exception { IndexService indexService = createIndex("test"); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc").endObject() + .startObject("type").endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject().startArray("foo") @@ -418,7 +418,7 @@ public void testComplexArray() throws Exception { .startObject().field("baz", 3).endObject() .endArray().endObject()); assertEquals(mapping, serialize(mapper)); - assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties") + assertEquals(Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("foo").startObject("properties") .startObject("bar").field("type", "text") .startObject("fields") diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java index e09953d31abc8..9f87ad3d0390a 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java @@ -43,7 +43,7 @@ public void setup() { public void testParsing() throws IOException { String mapping = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("alias-field") .field("type", "alias") @@ -55,7 +55,7 @@ public void testParsing() throws IOException { .endObject() .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java index 1adc12548c090..a34adaca2f144 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java @@ -60,11 +60,11 @@ protected Collection> getPlugins() { } public void testDefaults() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "ip").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -89,11 +89,11 @@ public void testDefaults() throws Exception { } public void testNotIndexed() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "ip").field("index", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -111,11 +111,11 @@ public void testNotIndexed() throws Exception { } public void testNoDocValues() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "ip").field("doc_values", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -134,11 +134,11 @@ public void testNoDocValues() throws Exception { } public void testStore() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "ip").field("store", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -162,11 +162,11 @@ public void testStore() throws Exception { } public void testIgnoreMalformed() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "ip").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -199,7 +199,7 @@ public void testIgnoreMalformed() throws Exception { public void testNullValue() throws IOException { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "ip") @@ -207,7 +207,7 @@ public void testNullValue() throws IOException { .endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -219,7 +219,7 @@ public void testNullValue() throws IOException { assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "ip") @@ -228,7 +228,7 @@ public void testNullValue() throws IOException { .endObject() .endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); doc = mapper.parse(new SourceToParse("test", "1", BytesReference diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java index 0c4b11004b460..2f861ca6fc79c 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IpRangeFieldMapperTests.java @@ -48,11 +48,11 @@ public void setup() { } public void testStoreCidr() throws Exception { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "ip_range") .field("store", true); mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); final Map cases = new HashMap<>(); cases.put("192.168.0.0/15", "192.169.255.255"); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java index c2063d1478a9b..fd821f1170ce8 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java @@ -94,11 +94,11 @@ public void setup() { } public void testDefaults() throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -131,11 +131,11 @@ public void testDefaults() throws Exception { } public void testIgnoreAbove() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").field("ignore_above", 5).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -161,11 +161,11 @@ public void testIgnoreAbove() throws IOException { } public void testNullValue() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -176,11 +176,11 @@ public void testNullValue() throws IOException { XContentType.JSON)); assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").field("null_value", "uri").endObject().endObject() .endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -206,11 +206,11 @@ public void testNullValue() throws IOException { } public void testEnableStore() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").field("store", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -227,11 +227,11 @@ public void testEnableStore() throws IOException { } public void testDisableIndex() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").field("index", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -249,11 +249,11 @@ public void testDisableIndex() throws IOException { } public void testDisableDocValues() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").field("doc_values", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -270,12 +270,12 @@ public void testDisableDocValues() throws IOException { } public void testIndexOptions() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword") .field("index_options", "freqs").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -302,17 +302,17 @@ public void testIndexOptions() throws IOException { } public void testBoost() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "keyword").field("boost", 2f).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); } public void testEnableNorms() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "keyword") @@ -322,7 +322,7 @@ public void testEnableNorms() throws IOException { .endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -341,12 +341,12 @@ public void testEnableNorms() throws IOException { } public void testNormalizer() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "keyword").field("normalizer", "my_lowercase").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java index df6b43d041acf..d53eb0bcac134 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/LegacyGeoShapeFieldMapperTests.java @@ -53,7 +53,7 @@ protected Collection> getPlugins() { } public void testDefaultConfiguration() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties").startObject("location") .field("type", "geo_shape") .field("strategy", "recursive") @@ -61,7 +61,7 @@ public void testDefaultConfiguration() throws IOException { .endObject().endObject()); DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser() - .parse("_doc", new CompressedXContent(mapping)); + .parse("type1", new CompressedXContent(mapping)); Mapper fieldMapper = defaultMapper.mappers().getMapper("location"); assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class)); assertEquals(mapping, defaultMapper.mappingSource().toString()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java index d6dfe8054f4b5..f32608b53c79b 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java @@ -186,7 +186,7 @@ public void testMultiFieldsInConsistentOrder() throws Exception { XContentHelper.convertToMap(docMapper.mappingSource().compressedReference(), true, builder.contentType()).v2(); @SuppressWarnings("unchecked") Map multiFields = - (Map) XContentMapValues.extractValue("_doc.properties.my_field.fields", sourceAsMap); + (Map) XContentMapValues.extractValue("type.properties.my_field.fields", sourceAsMap); assertThat(multiFields.size(), equalTo(multiFieldNames.length)); int i = 0; diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java index 3181a92434121..a1322c6614456 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java @@ -53,11 +53,11 @@ protected void setTypeList() { @Override public void doTestDefaults(String type) throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -81,11 +81,11 @@ public void doTestDefaults(String type) throws Exception { @Override public void doTestNotIndexed(String type) throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("index", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -104,11 +104,11 @@ public void doTestNotIndexed(String type) throws Exception { @Override public void doTestNoDocValues(String type) throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("doc_values", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -128,11 +128,11 @@ public void doTestNoDocValues(String type) throws Exception { @Override public void doTestStore(String type) throws Exception { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("store", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -157,11 +157,11 @@ public void doTestStore(String type) throws Exception { @Override public void doTestCoerce(String type) throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -180,11 +180,11 @@ public void doTestCoerce(String type) throws IOException { IndexableField dvField = fields[1]; assertEquals(DocValuesType.SORTED_NUMERIC, dvField.fieldType().docValuesType()); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("coerce", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper2 = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper2.mappingSource().toString()); @@ -200,11 +200,11 @@ public void doTestCoerce(String type) throws IOException { @Override protected void doTestDecimalCoerce(String type) throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -223,10 +223,10 @@ protected void doTestDecimalCoerce(String type) throws IOException { public void testIgnoreMalformed() throws Exception { for (String type : TYPES) { for (Object malformedValue : new Object[] { "a", Boolean.FALSE }) { - String mapping = Strings.toString(jsonBuilder().startObject().startObject("_doc").startObject("properties") + String mapping = Strings.toString(jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("field").field("type", type).endObject().endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -240,10 +240,10 @@ public void testIgnoreMalformed() throws Exception { assertThat(e.getCause().getMessage(), containsString("not numeric, can not use numeric value accessors")); } - mapping = Strings.toString(jsonBuilder().startObject().startObject("_doc").startObject("properties").startObject("field") + mapping = Strings.toString(jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field") .field("type", type).field("ignore_malformed", true).endObject().endObject().endObject().endObject()); - DocumentMapper mapper2 = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(mapping)); ParsedDocument doc = mapper2.parse(new SourceToParse("test", "1", BytesReference.bytes(jsonBuilder().startObject().field("field", malformedValue).endObject()), XContentType.JSON)); @@ -268,9 +268,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws }; for (Boolean ignoreMalformed : new Boolean[] { true, false }) { String mapping = Strings.toString( - jsonBuilder().startObject().startObject("_doc").startObject("properties").startObject("field").field("type", type) + jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", type) .field("ignore_malformed", ignoreMalformed).endObject().endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); MapperParsingException e = expectThrows(MapperParsingException.class, @@ -287,7 +287,7 @@ public void testRejectNorms() throws IOException { // not supported as of 5.0 for (String type : TYPES) { DocumentMapperParser parser = createIndex("index-" + type).mapperService().documentMapperParser(); - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("foo") .field("type", type) @@ -295,7 +295,7 @@ public void testRejectNorms() throws IOException { .endObject() .endObject().endObject().endObject()); MapperParsingException e = expectThrows(MapperParsingException.class, - () -> parser.parse("_doc", new CompressedXContent(mapping))); + () -> parser.parse("type", new CompressedXContent(mapping))); assertThat(e.getMessage(), containsString("Mapping definition for [foo] has unsupported parameters: [norms")); } } @@ -322,7 +322,7 @@ public void testRejectIndexOptions() throws IOException { @Override protected void doTestNullValue(String type) throws IOException { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", type) @@ -330,7 +330,7 @@ protected void doTestNullValue(String type) throws IOException { .endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference @@ -348,7 +348,7 @@ protected void doTestNullValue(String type) throws IOException { missing = 123L; } mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", type) @@ -357,7 +357,7 @@ protected void doTestNullValue(String type) throws IOException { .endObject() .endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); doc = mapper.parse(new SourceToParse("test", "1", BytesReference diff --git a/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java index 154ebf30f5984..7672eb3df26b6 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/ObjectMapperTests.java @@ -181,6 +181,24 @@ public void testMerge() throws IOException { assertEquals(Dynamic.STRICT, mapper.root().dynamic()); } + public void testEmptyName() throws Exception { + String mapping = Strings.toString(XContentFactory.jsonBuilder() + .startObject() + .startObject("") + .startObject("properties") + .startObject("name") + .field("type", "text") + .endObject() + .endObject() + .endObject().endObject()); + + // Empty name not allowed in index created after 5.0 + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { + createIndex("test").mapperService().documentMapperParser().parse("", new CompressedXContent(mapping)); + }); + assertThat(e.getMessage(), containsString("name cannot be empty string")); + } + @Override protected Collection> getPlugins() { return pluginList(InternalSettingsPlugin.class); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java index 4c8b7c3794280..d713988e19197 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RangeFieldMapperTests.java @@ -111,14 +111,14 @@ private Object getMax(String type) { @Override public void doTestDefaults(String type) throws Exception { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type); if (type.equals("date_range")) { mapping = mapping.field("format", DATE_FORMAT); } mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(XContentFactory.jsonBuilder() @@ -142,14 +142,14 @@ public void doTestDefaults(String type) throws Exception { @Override protected void doTestNotIndexed(String type) throws Exception { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("index", false); if (type.equals("date_range")) { mapping = mapping.field("format", DATE_FORMAT); } mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(XContentFactory.jsonBuilder() @@ -167,13 +167,13 @@ protected void doTestNotIndexed(String type) throws Exception { @Override protected void doTestNoDocValues(String type) throws Exception { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("doc_values", false); if (type.equals("date_range")) { mapping = mapping.field("format", DATE_FORMAT); } mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(XContentFactory.jsonBuilder() @@ -193,13 +193,13 @@ protected void doTestNoDocValues(String type) throws Exception { @Override protected void doTestStore(String type) throws Exception { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("store", true); if (type.equals("date_range")) { mapping = mapping.field("format", DATE_FORMAT); } mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); ParsedDocument doc = mapper.parse(new SourceToParse("test", "1", BytesReference.bytes(XContentFactory.jsonBuilder() @@ -231,13 +231,13 @@ protected void doTestStore(String type) throws Exception { @Override public void doTestCoerce(String type) throws IOException { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type); if (type.equals("date_range")) { mapping = mapping.field("format", DATE_FORMAT); } mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); @@ -260,9 +260,9 @@ public void doTestCoerce(String type) throws IOException { // date_range ignores the coerce parameter and epoch_millis date format truncates floats (see issue: #14641) if (type.equals("date_range") == false) { - mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc").startObject("properties").startObject("field") + mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field") .field("type", type).field("coerce", false).endObject().endObject().endObject().endObject(); - DocumentMapper mapper2 = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper2 = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper2.mappingSource().toString()); @@ -279,11 +279,11 @@ public void doTestCoerce(String type) throws IOException { @Override protected void doTestDecimalCoerce(String type) throws IOException { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type); mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); @@ -313,14 +313,14 @@ protected void doTestDecimalCoerce(String type) throws IOException { @Override protected void doTestNullValue(String type) throws IOException { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("store", true); if (type.equals("date_range")) { mapping = mapping.field("format", DATE_FORMAT); } mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); // test null value for min and max @@ -383,14 +383,14 @@ public void testNoBounds() throws Exception { } public void doTestNoBounds(String type) throws IOException { - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("_doc") + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", type).field("store", true); if (type.equals("date_range")) { mapping = mapping.field("format", DATE_FORMAT); } mapping = mapping.endObject().endObject().endObject().endObject(); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(Strings.toString(mapping))); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(Strings.toString(mapping))); assertEquals(Strings.toString(mapping), mapper.mappingSource().toString()); // test no bounds specified diff --git a/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java index 8946d7a235420..0b805eb726646 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/RootObjectMapperTests.java @@ -32,99 +32,99 @@ public class RootObjectMapperTests extends ESSingleNodeTestCase { public void testNumericDetection() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .field("numeric_detection", false) .endObject() .endObject()); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // update with a different explicit value String mapping2 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .field("numeric_detection", true) .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); // update with an implicit value: no change String mapping3 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); } public void testDateDetection() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .field("date_detection", true) .endObject() .endObject()); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // update with a different explicit value String mapping2 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .field("date_detection", false) .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); // update with an implicit value: no change String mapping3 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping2, mapper.mappingSource().toString()); } public void testDateFormatters() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .field("dynamic_date_formats", Arrays.asList("yyyy-MM-dd")) .endObject() .endObject()); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // no update if formatters are not set explicitly String mapping2 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); String mapping3 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .field("dynamic_date_formats", Arrays.asList()) .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping3, mapper.mappingSource().toString()); } public void testDynamicTemplates() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .startArray("dynamic_templates") .startObject() .startObject("my_template") @@ -138,25 +138,25 @@ public void testDynamicTemplates() throws Exception { .endObject() .endObject()); MapperService mapperService = createIndex("test").mapperService(); - DocumentMapper mapper = mapperService.merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); + DocumentMapper mapper = mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); // no update if templates are not set explicitly String mapping2 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); String mapping3 = Strings.toString(XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") + .startObject("type") .field("dynamic_templates", Arrays.asList()) .endObject() .endObject()); - mapper = mapperService.merge("_doc", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); + mapper = mapperService.merge("type", new CompressedXContent(mapping3), MergeReason.MAPPING_UPDATE); assertEquals(mapping3, mapper.mappingSource().toString()); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java index 25c59fb26ddb1..cbfbb4a05c973 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java @@ -121,13 +121,13 @@ public void testExcludes() throws Exception { } private void assertConflicts(String mapping1, String mapping2, DocumentMapperParser parser, String... conflicts) throws IOException { - DocumentMapper docMapper = parser.parse("_doc", new CompressedXContent(mapping1)); - docMapper = parser.parse("_doc", docMapper.mappingSource()); + DocumentMapper docMapper = parser.parse("type", new CompressedXContent(mapping1)); + docMapper = parser.parse("type", docMapper.mappingSource()); if (conflicts.length == 0) { - docMapper.merge(parser.parse("_doc", new CompressedXContent(mapping2)).mapping()); + docMapper.merge(parser.parse("type", new CompressedXContent(mapping2)).mapping()); } else { try { - docMapper.merge(parser.parse("_doc", new CompressedXContent(mapping2)).mapping()); + docMapper.merge(parser.parse("type", new CompressedXContent(mapping2)).mapping()); fail(); } catch (IllegalArgumentException e) { for (String conflict : conflicts) { @@ -140,14 +140,14 @@ private void assertConflicts(String mapping1, String mapping2, DocumentMapperPar public void testEnabledNotUpdateable() throws Exception { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); // using default of true - String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject()); - String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject()); + String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").field("enabled", false).endObject() .endObject().endObject()); assertConflicts(mapping1, mapping2, parser, "Cannot update enabled setting for [_source]"); // not changing is ok - String mapping3 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping3 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").field("enabled", true).endObject() .endObject().endObject()); assertConflicts(mapping1, mapping3, parser); @@ -155,14 +155,14 @@ public void testEnabledNotUpdateable() throws Exception { public void testIncludesNotUpdateable() throws Exception { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); - String defaultMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject()); - String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String defaultMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject()); + String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("includes", "foo.*").endObject() .endObject().endObject()); assertConflicts(defaultMapping, mapping1, parser, "Cannot update includes setting for [_source]"); assertConflicts(mapping1, defaultMapping, parser, "Cannot update includes setting for [_source]"); - String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("includes", "foo.*", "bar.*").endObject() .endObject().endObject()); assertConflicts(mapping1, mapping2, parser, "Cannot update includes setting for [_source]"); @@ -173,14 +173,14 @@ public void testIncludesNotUpdateable() throws Exception { public void testExcludesNotUpdateable() throws Exception { DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); - String defaultMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject()); - String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String defaultMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject()); + String mapping1 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("excludes", "foo.*").endObject() .endObject().endObject()); assertConflicts(defaultMapping, mapping1, parser, "Cannot update excludes setting for [_source]"); assertConflicts(mapping1, defaultMapping, parser, "Cannot update excludes setting for [_source]"); - String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping2 = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_source").array("excludes", "foo.*", "bar.*").endObject() .endObject().endObject()); assertConflicts(mapping1, mapping2, parser, "Cannot update excludes setting for [_source]"); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java index 6d73ed8cfb1bc..539d8bbdeaf59 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java @@ -106,11 +106,11 @@ protected Collection> getPlugins() { } public void testDefaults() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "text").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -138,11 +138,11 @@ public void testDefaults() throws IOException { } public void testEnableStore() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "text").field("store", true).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -159,11 +159,11 @@ public void testEnableStore() throws IOException { } public void testDisableIndex() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "text").field("index", false).endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -179,14 +179,14 @@ public void testDisableIndex() throws IOException { } public void testDisableNorms() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("norms", false) .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); @@ -234,11 +234,11 @@ public void testIndexOptions() throws IOException { } public void testDefaultPositionIncrementGap() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field").field("type", "text").endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = indexService.mapperService().merge("_doc", + DocumentMapper mapper = indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); @@ -273,14 +273,14 @@ public void testDefaultPositionIncrementGap() throws IOException { public void testPositionIncrementGap() throws IOException { final int positionIncrementGap = randomIntBetween(1, 1000); - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("position_increment_gap", positionIncrementGap) .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = indexService.mapperService().merge("_doc", + DocumentMapper mapper = indexService.mapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); assertEquals(mapping, mapper.mappingSource().toString()); @@ -314,7 +314,7 @@ public void testPositionIncrementGap() throws IOException { } public void testSearchAnalyzerSerialization() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") @@ -323,11 +323,11 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); // special case: default index analyzer - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") @@ -336,10 +336,10 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") @@ -347,11 +347,11 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); // special case: default search analyzer - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") @@ -360,17 +360,17 @@ public void testSearchAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") .field("analyzer", "keyword") .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); @@ -384,7 +384,7 @@ public void testSearchAnalyzerSerialization() throws IOException { } public void testSearchQuoteAnalyzerSerialization() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") @@ -394,11 +394,11 @@ public void testSearchQuoteAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); // special case: default index/search analyzer - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") @@ -408,7 +408,7 @@ public void testSearchQuoteAnalyzerSerialization() throws IOException { .endObject() .endObject().endObject().endObject()); - mapper = parser.parse("_doc", new CompressedXContent(mapping)); + mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); } @@ -488,14 +488,14 @@ public void testTermVectors() throws IOException { } public void testEagerGlobalOrdinals() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("eager_global_ordinals", true) .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); FieldMapper fieldMapper = (FieldMapper) mapper.mappers().getMapper("field"); @@ -503,13 +503,13 @@ public void testEagerGlobalOrdinals() throws IOException { } public void testFielddata() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .endObject().endObject() .endObject().endObject()); - DocumentMapper disabledMapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper disabledMapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, disabledMapper.mappingSource().toString()); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { FieldMapper fieldMapper = (FieldMapper) disabledMapper.mappers().getMapper("field"); @@ -517,14 +517,14 @@ public void testFielddata() throws IOException { }); assertThat(e.getMessage(), containsString("Fielddata is disabled")); - mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("fielddata", true) .endObject().endObject() .endObject().endObject()); - DocumentMapper enabledMapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper enabledMapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, enabledMapper.mappingSource().toString()); @@ -544,7 +544,7 @@ public void testFielddata() throws IOException { } public void testFrequencyFilter() throws IOException { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("fielddata", true) @@ -555,7 +555,7 @@ public void testFrequencyFilter() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); TextFieldMapper fieldMapper = (TextFieldMapper) mapper.mappers().getMapper("field"); @@ -778,7 +778,7 @@ public void testFastPhraseMapping() throws IOException { throw new UnsupportedOperationException(); }, null); - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") .startObject("field") .field("type", "text") @@ -793,10 +793,10 @@ public void testFastPhraseMapping() throws IOException { .endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); - queryShardContext.getMapperService().merge("_doc", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); + queryShardContext.getMapperService().merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); Query q = new MatchPhraseQueryBuilder("field", "two words").toQuery(queryShardContext); assertThat(q, is(new PhraseQuery("field._index_phrase", "two words"))); @@ -862,7 +862,7 @@ protected TokenStreamComponents createComponents(String fieldName) { } { - String badConfigMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String badConfigMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("index", "false") @@ -870,13 +870,13 @@ protected TokenStreamComponents createComponents(String fieldName) { .endObject().endObject() .endObject().endObject()); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> parser.parse("_doc", new CompressedXContent(badConfigMapping)) + () -> parser.parse("type", new CompressedXContent(badConfigMapping)) ); assertThat(e.getMessage(), containsString("Cannot set index_phrases on unindexed field [field]")); } { - String badConfigMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String badConfigMapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("index_options", "freqs") @@ -884,7 +884,7 @@ protected TokenStreamComponents createComponents(String fieldName) { .endObject().endObject() .endObject().endObject()); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> parser.parse("_doc", new CompressedXContent(badConfigMapping)) + () -> parser.parse("type", new CompressedXContent(badConfigMapping)) ); assertThat(e.getMessage(), containsString("Cannot set index_phrases on field [field] if positions are not enabled")); } @@ -893,7 +893,7 @@ protected TokenStreamComponents createComponents(String fieldName) { public void testIndexPrefixMapping() throws IOException { { - String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("_doc") + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("field") .field("type", "text") .field("analyzer", "standard") @@ -904,7 +904,7 @@ public void testIndexPrefixMapping() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); assertThat(mapper.mappers().getMapper("field._index_prefix").toString(), containsString("prefixChars=2:10")); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java index 689dfbdcc872d..1ef68cf42d166 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java @@ -75,7 +75,7 @@ public static void testDocValues(Function createIndex) thr assertTrue(values.advanceExact(0)); assertEquals(0, values.nextOrd()); assertEquals(SortedSetDocValues.NO_MORE_ORDS, values.nextOrd()); - assertEquals(new BytesRef("_doc"), values.lookupOrd(0)); + assertEquals(new BytesRef("type"), values.lookupOrd(0)); r.close(); dir.close(); } diff --git a/x-pack/plugin/mapper-flattened/src/test/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapperTests.java b/x-pack/plugin/mapper-flattened/src/test/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapperTests.java index 44dfc11898016..aeb22c331b355 100644 --- a/x-pack/plugin/mapper-flattened/src/test/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapperTests.java +++ b/x-pack/plugin/mapper-flattened/src/test/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapperTests.java @@ -56,7 +56,7 @@ protected Collection> getPlugins() { public void testDefaults() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -65,7 +65,7 @@ public void testDefaults() throws Exception { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -111,7 +111,7 @@ public void testDefaults() throws Exception { public void testDisableIndex() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -121,7 +121,7 @@ public void testDisableIndex() throws Exception { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -143,7 +143,7 @@ public void testDisableIndex() throws Exception { public void testDisableDocValues() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -153,7 +153,7 @@ public void testDisableDocValues() throws Exception { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -195,7 +195,7 @@ public void testEnableStore() throws Exception { public void testIndexOptions() throws IOException { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -205,12 +205,12 @@ public void testIndexOptions() throws IOException { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); for (String indexOptions : Arrays.asList("positions", "offsets")) { String invalidMapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -220,14 +220,14 @@ public void testIndexOptions() throws IOException { .endObject() .endObject()); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> parser.parse("_doc", new CompressedXContent(invalidMapping))); + () -> parser.parse("type", new CompressedXContent(invalidMapping))); assertEquals("The [flattened] field does not support positions, got [index_options]=" + indexOptions, e.getMessage()); } } public void testNullField() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -236,7 +236,7 @@ public void testNullField() throws Exception { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -250,7 +250,7 @@ public void testNullField() throws Exception { public void testMalformedJson() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -259,7 +259,7 @@ public void testMalformedJson() throws Exception { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc1 = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -276,7 +276,7 @@ public void testMalformedJson() throws Exception { public void testFieldMultiplicity() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -285,7 +285,7 @@ public void testFieldMultiplicity() throws Exception { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -318,7 +318,7 @@ public void testFieldMultiplicity() throws Exception { public void testDepthLimit() throws IOException { // First verify the default behavior when depth_limit is not set. String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -327,7 +327,7 @@ public void testDepthLimit() throws IOException { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -344,7 +344,7 @@ public void testDepthLimit() throws IOException { // Set a lower value for depth_limit and check that the field is rejected. String newMapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -355,7 +355,7 @@ public void testDepthLimit() throws IOException { .endObject()); DocumentMapper newMapper = mapper.merge( - parser.parse("_doc", new CompressedXContent(newMapping)).mapping()); + parser.parse("type", new CompressedXContent(newMapping)).mapping()); expectThrows(MapperParsingException.class, () -> newMapper.parse(new SourceToParse("test", "1", doc, XContentType.JSON))); @@ -363,7 +363,7 @@ public void testDepthLimit() throws IOException { public void testEagerGlobalOrdinals() throws IOException { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -371,7 +371,7 @@ public void testEagerGlobalOrdinals() throws IOException { .endObject().endObject() .endObject().endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); FieldMapper fieldMapper = (FieldMapper) mapper.mappers().getMapper("field"); @@ -381,7 +381,7 @@ public void testEagerGlobalOrdinals() throws IOException { public void testIgnoreAbove() throws IOException { // First verify the default behavior when ignore_above is not set. String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -390,7 +390,7 @@ public void testIgnoreAbove() throws IOException { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject() @@ -427,7 +427,7 @@ public void testIgnoreAbove() throws IOException { public void testNullValues() throws Exception { String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() - .startObject("_doc") + .startObject("type") .startObject("properties") .startObject("field") .field("type", "flattened") @@ -440,7 +440,7 @@ public void testNullValues() throws Exception { .endObject() .endObject()); - DocumentMapper mapper = parser.parse("_doc", new CompressedXContent(mapping)); + DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, mapper.mappingSource().toString()); BytesReference doc = BytesReference.bytes(XContentFactory.jsonBuilder().startObject()