simplify a bit doc mapper parsing to make it more generic
This commit is contained in:
parent
8a7b20597d
commit
4395202ebc
|
@ -512,7 +512,7 @@ public class DocumentMapper implements ToXContent {
|
|||
parser = XContentFactory.xContent(source.source()).createParser(source.source());
|
||||
}
|
||||
}
|
||||
context.reset(parser, new Document(), type, source.source(), source.flyweight(), listener);
|
||||
context.reset(parser, new Document(), source, listener);
|
||||
|
||||
// will result in START_OBJECT
|
||||
int countDownTokens = 0;
|
||||
|
@ -602,13 +602,12 @@ public class DocumentMapper implements ToXContent {
|
|||
}
|
||||
}
|
||||
if (parentFieldMapper != null) {
|
||||
context.externalValue(source.parent());
|
||||
parentFieldMapper.parse(context);
|
||||
}
|
||||
analyzerMapper.parse(context);
|
||||
allFieldMapper.parse(context);
|
||||
// validate aggregated mappers (TODO: need to be added as a phase to any field mapper)
|
||||
routingFieldMapper.validate(context, source.routing());
|
||||
routingFieldMapper.validate(context);
|
||||
} catch (IOException e) {
|
||||
throw new MapperParsingException("Failed to parse", e);
|
||||
} finally {
|
||||
|
@ -624,7 +623,7 @@ public class DocumentMapper implements ToXContent {
|
|||
ParsedDocument doc = new ParsedDocument(context.uid(), context.id(), context.type(), source.routing(), context.docs(), context.analyzer(),
|
||||
context.source(), context.mappersAdded()).parent(source.parent());
|
||||
// reset the context to free up memory
|
||||
context.reset(null, null, null, null, false, null);
|
||||
context.reset(null, null, null, null);
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,14 +54,11 @@ public class ParseContext {
|
|||
|
||||
private String index;
|
||||
|
||||
private String type;
|
||||
|
||||
private SourceToParse sourceToParse;
|
||||
private byte[] source;
|
||||
|
||||
private String id;
|
||||
|
||||
private boolean flyweight;
|
||||
|
||||
private DocumentMapper.ParseListener listener;
|
||||
|
||||
private String uid;
|
||||
|
@ -87,7 +84,7 @@ public class ParseContext {
|
|||
this.path = path;
|
||||
}
|
||||
|
||||
public void reset(XContentParser parser, Document document, String type, byte[] source, boolean flyweight, DocumentMapper.ParseListener listener) {
|
||||
public void reset(XContentParser parser, Document document, SourceToParse source, DocumentMapper.ParseListener listener) {
|
||||
this.parser = parser;
|
||||
this.document = document;
|
||||
if (document != null) {
|
||||
|
@ -99,9 +96,8 @@ public class ParseContext {
|
|||
this.analyzer = null;
|
||||
this.uid = null;
|
||||
this.id = null;
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
this.flyweight = flyweight;
|
||||
this.sourceToParse = source;
|
||||
this.source = source == null ? null : sourceToParse.source();
|
||||
this.path.reset();
|
||||
this.parsedIdState = ParsedIdState.NO;
|
||||
this.mappersAdded = false;
|
||||
|
@ -111,7 +107,7 @@ public class ParseContext {
|
|||
}
|
||||
|
||||
public boolean flyweight() {
|
||||
return this.flyweight;
|
||||
return sourceToParse.flyweight();
|
||||
}
|
||||
|
||||
public DocumentMapperParser docMapperParser() {
|
||||
|
@ -131,11 +127,15 @@ public class ParseContext {
|
|||
}
|
||||
|
||||
public String type() {
|
||||
return this.type;
|
||||
return sourceToParse.type();
|
||||
}
|
||||
|
||||
public SourceToParse sourceToParse() {
|
||||
return this.sourceToParse;
|
||||
}
|
||||
|
||||
public byte[] source() {
|
||||
return this.source;
|
||||
return source;
|
||||
}
|
||||
|
||||
// only should be used by SourceFieldMapper to update with a compressed source
|
||||
|
|
|
@ -95,8 +95,8 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
|
|||
}
|
||||
// otherwise, we are running it post processing of the xcontent
|
||||
String parsedParentId = context.doc().get(Defaults.NAME);
|
||||
if (context.externalValueSet()) {
|
||||
String parentId = (String) context.externalValue();
|
||||
if (context.sourceToParse().parent() != null) {
|
||||
String parentId = context.sourceToParse().parent();
|
||||
if (parsedParentId == null) {
|
||||
if (parentId == null) {
|
||||
throw new MapperParsingException("No parent id provided, not within the document, and not externally");
|
||||
|
|
|
@ -126,7 +126,8 @@ public class RoutingFieldMapper extends AbstractFieldMapper<String> implements I
|
|||
return value;
|
||||
}
|
||||
|
||||
public void validate(ParseContext context, String routing) throws MapperParsingException {
|
||||
public void validate(ParseContext context) throws MapperParsingException {
|
||||
String routing = context.sourceToParse().routing();
|
||||
if (path != null && routing != null) {
|
||||
// we have a path, check if we can validate we have the same routing value as the one in the doc...
|
||||
String value = context.doc().get(path);
|
||||
|
|
Loading…
Reference in New Issue