Skip to content

Commit

Permalink
Avoid using external values in parent-join and percolator mappers (#7…
Browse files Browse the repository at this point in the history
…1834)

We would like to remove the use of 'external values' in document parsing.
This commit simplifies two of the four places it is currently used, by adding
direct indexValue methods to BinaryFieldMapper and ParentIdFieldMapper.

Relates to #56063
  • Loading branch information
romseygeek authored Apr 20, 2021
1 parent 7cd0bdc commit f2ac4f9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ protected ParentIdFieldMapper(String name, boolean eagerGlobalOrdinals) {

@Override
protected void parseCreateField(ParseContext context) {
if (context.externalValueSet() == false) {
throw new IllegalStateException("external value not set");
}
String refId = (String) context.externalValue();
throw new UnsupportedOperationException("Cannot directly call parse() on a ParentIdFieldMapper");
}

public void indexValue(ParseContext context, String refId) {
BytesRef binaryValue = new BytesRef(refId);
Field field = new Field(fieldType().name(), binaryValue, Defaults.FIELD_TYPE);
context.doc().add(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,13 @@ public void parse(ParseContext context) throws IOException {
if (context.sourceToParse().routing() == null) {
throw new IllegalArgumentException("[routing] is missing for join field [" + name() + "]");
}
ParseContext externalContext = context.createExternalValueContext(parent);
String fieldName = fieldType().joiner.parentJoinField(name);
parentIdFields.get(fieldName).parse(externalContext);
parentIdFields.get(fieldName).indexValue(context, parent);
}
if (fieldType().joiner.parentTypeExists(name)) {
// Index the document as a parent
ParseContext externalContext = context.createExternalValueContext(context.sourceToParse().id());
String fieldName = fieldType().joiner.childJoinField(name);
parentIdFields.get(fieldName).parse(externalContext);
parentIdFields.get(fieldName).indexValue(context, context.sourceToParse().id());
}

BytesRef binaryValue = new BytesRef(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,7 @@ static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbFi
try (OutputStreamStreamOutput out = new OutputStreamStreamOutput(stream)) {
out.setVersion(indexVersion);
out.writeNamedWriteable(queryBuilder);
byte[] queryBuilderAsBytes = stream.toByteArray();
qbField.parse(context.createExternalValueContext(queryBuilderAsBytes));
qbField.indexValue(context, stream.toByteArray());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ protected void parseCreateField(ParseContext context) throws IOException {
value = context.parser().binaryValue();
}
}
indexValue(context, value);
}

public void indexValue(ParseContext context, byte[] value) {
if (value == null) {
return;
}
Expand Down

0 comments on commit f2ac4f9

Please sign in to comment.