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());
|
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
|
// will result in START_OBJECT
|
||||||
int countDownTokens = 0;
|
int countDownTokens = 0;
|
||||||
|
@ -602,13 +602,12 @@ public class DocumentMapper implements ToXContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parentFieldMapper != null) {
|
if (parentFieldMapper != null) {
|
||||||
context.externalValue(source.parent());
|
|
||||||
parentFieldMapper.parse(context);
|
parentFieldMapper.parse(context);
|
||||||
}
|
}
|
||||||
analyzerMapper.parse(context);
|
analyzerMapper.parse(context);
|
||||||
allFieldMapper.parse(context);
|
allFieldMapper.parse(context);
|
||||||
// validate aggregated mappers (TODO: need to be added as a phase to any field mapper)
|
// 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) {
|
} catch (IOException e) {
|
||||||
throw new MapperParsingException("Failed to parse", e);
|
throw new MapperParsingException("Failed to parse", e);
|
||||||
} finally {
|
} 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(),
|
ParsedDocument doc = new ParsedDocument(context.uid(), context.id(), context.type(), source.routing(), context.docs(), context.analyzer(),
|
||||||
context.source(), context.mappersAdded()).parent(source.parent());
|
context.source(), context.mappersAdded()).parent(source.parent());
|
||||||
// reset the context to free up memory
|
// reset the context to free up memory
|
||||||
context.reset(null, null, null, null, false, null);
|
context.reset(null, null, null, null);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,11 @@ public class ParseContext {
|
||||||
|
|
||||||
private String index;
|
private String index;
|
||||||
|
|
||||||
private String type;
|
private SourceToParse sourceToParse;
|
||||||
|
|
||||||
private byte[] source;
|
private byte[] source;
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private boolean flyweight;
|
|
||||||
|
|
||||||
private DocumentMapper.ParseListener listener;
|
private DocumentMapper.ParseListener listener;
|
||||||
|
|
||||||
private String uid;
|
private String uid;
|
||||||
|
@ -87,7 +84,7 @@ public class ParseContext {
|
||||||
this.path = path;
|
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.parser = parser;
|
||||||
this.document = document;
|
this.document = document;
|
||||||
if (document != null) {
|
if (document != null) {
|
||||||
|
@ -99,9 +96,8 @@ public class ParseContext {
|
||||||
this.analyzer = null;
|
this.analyzer = null;
|
||||||
this.uid = null;
|
this.uid = null;
|
||||||
this.id = null;
|
this.id = null;
|
||||||
this.type = type;
|
this.sourceToParse = source;
|
||||||
this.source = source;
|
this.source = source == null ? null : sourceToParse.source();
|
||||||
this.flyweight = flyweight;
|
|
||||||
this.path.reset();
|
this.path.reset();
|
||||||
this.parsedIdState = ParsedIdState.NO;
|
this.parsedIdState = ParsedIdState.NO;
|
||||||
this.mappersAdded = false;
|
this.mappersAdded = false;
|
||||||
|
@ -111,7 +107,7 @@ public class ParseContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean flyweight() {
|
public boolean flyweight() {
|
||||||
return this.flyweight;
|
return sourceToParse.flyweight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DocumentMapperParser docMapperParser() {
|
public DocumentMapperParser docMapperParser() {
|
||||||
|
@ -131,11 +127,15 @@ public class ParseContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String type() {
|
public String type() {
|
||||||
return this.type;
|
return sourceToParse.type();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SourceToParse sourceToParse() {
|
||||||
|
return this.sourceToParse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] source() {
|
public byte[] source() {
|
||||||
return this.source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only should be used by SourceFieldMapper to update with a compressed 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
|
// otherwise, we are running it post processing of the xcontent
|
||||||
String parsedParentId = context.doc().get(Defaults.NAME);
|
String parsedParentId = context.doc().get(Defaults.NAME);
|
||||||
if (context.externalValueSet()) {
|
if (context.sourceToParse().parent() != null) {
|
||||||
String parentId = (String) context.externalValue();
|
String parentId = context.sourceToParse().parent();
|
||||||
if (parsedParentId == null) {
|
if (parsedParentId == null) {
|
||||||
if (parentId == null) {
|
if (parentId == null) {
|
||||||
throw new MapperParsingException("No parent id provided, not within the document, and not externally");
|
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;
|
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) {
|
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...
|
// 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);
|
String value = context.doc().get(path);
|
||||||
|
|
Loading…
Reference in New Issue