Skip to content

Commit

Permalink
Revert "Don't use user-supplied type when building DocumentMapper (el…
Browse files Browse the repository at this point in the history
…astic#50960)" (elastic#51214)

Reverts elastic#50960

This commit has been causing test failures during upgrade tests: specifically, an upgraded
node becomes master and sends a cluster state update to a 7.x node; this node sees that the
mapping version of its .tasks index is the same as the master, so asserts that the serialized
mappings are the same; however, because the master has rewritten the mapping to use
_docinstead oftasks`, we get an assertion failure. The logical fix is for the master to
increment its mapping version when it rewrites the mapping, but there isn't a simple way to
do that currently.

This reverts commit 774bfb5.
  • Loading branch information
romseygeek authored and SivagurunathanV committed Jan 21, 2020
1 parent 7b41175 commit d607690
Show file tree
Hide file tree
Showing 28 changed files with 367 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public void setup() {
protected Collection<Class<? extends Plugin>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ protected Collection<Class<? extends Plugin>> 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());

Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ protected Collection<Class<? extends Plugin>> 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());

Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down
Loading

0 comments on commit d607690

Please sign in to comment.