Mappings: Fix doc parser to still pre/post process metadata fields on disabled type
closes #13017
This commit is contained in:
parent
9bd4a7b72e
commit
a5bae3bdd8
|
@ -104,8 +104,9 @@ class DocumentParser implements Closeable {
|
|||
if (token != XContentParser.Token.START_OBJECT) {
|
||||
throw new MapperParsingException("Malformed content, must start with an object");
|
||||
}
|
||||
if (mapping.root.isEnabled()) {
|
||||
|
||||
boolean emptyDoc = false;
|
||||
if (mapping.root.isEnabled()) {
|
||||
token = parser.nextToken();
|
||||
if (token == XContentParser.Token.END_OBJECT) {
|
||||
// empty doc, we can handle it...
|
||||
|
@ -113,25 +114,26 @@ class DocumentParser implements Closeable {
|
|||
} else if (token != XContentParser.Token.FIELD_NAME) {
|
||||
throw new MapperParsingException("Malformed content, after first object, either the type field or the actual properties should exist");
|
||||
}
|
||||
}
|
||||
|
||||
for (MetadataFieldMapper metadataMapper : mapping.metadataMappers) {
|
||||
metadataMapper.preParse(context);
|
||||
}
|
||||
if (emptyDoc == false) {
|
||||
|
||||
if (mapping.root.isEnabled() == false) {
|
||||
// entire type is disabled
|
||||
parser.skipChildren();
|
||||
} else if (emptyDoc == false) {
|
||||
Mapper update = parseObject(context, mapping.root);
|
||||
if (update != null) {
|
||||
context.addDynamicMappingsUpdate(update);
|
||||
}
|
||||
}
|
||||
|
||||
for (MetadataFieldMapper metadataMapper : mapping.metadataMappers) {
|
||||
metadataMapper.postParse(context);
|
||||
}
|
||||
|
||||
} else {
|
||||
// entire type is disabled
|
||||
parser.skipChildren();
|
||||
}
|
||||
|
||||
// try to parse the next token, this should be null if the object is ended properly
|
||||
// but will throw a JSON exception if the extra tokens is not valid JSON (this will be handled by the catch)
|
||||
if (Version.indexCreated(indexSettings).onOrAfter(Version.V_2_0_0_beta1)
|
||||
|
|
|
@ -19,12 +19,9 @@
|
|||
|
||||
package org.elasticsearch.index.mapper;
|
||||
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContentParser;
|
||||
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
||||
// TODO: make this a real unit test
|
||||
|
@ -37,11 +34,12 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
DocumentMapper mapper = mapperParser.parse(mapping);
|
||||
|
||||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject().startObject("foo")
|
||||
.field("field", "1234")
|
||||
.endObject().bytes();
|
||||
.endObject().endObject().bytes();
|
||||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
assertNull(doc.rootDoc().getField("field"));
|
||||
assertNotNull(doc.rootDoc().getField(UidFieldMapper.NAME));
|
||||
}
|
||||
|
||||
public void testFieldDisabled() throws Exception {
|
||||
|
@ -60,5 +58,6 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
|
||||
assertNull(doc.rootDoc().getField("foo"));
|
||||
assertNotNull(doc.rootDoc().getField("bar"));
|
||||
assertNotNull(doc.rootDoc().getField(UidFieldMapper.NAME));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue