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