Skip to content

Commit f2ac4f9

Browse files
authored
Avoid using external values in parent-join and percolator mappers (#71834)
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
1 parent 7cd0bdc commit f2ac4f9

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentIdFieldMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ protected ParentIdFieldMapper(String name, boolean eagerGlobalOrdinals) {
9292

9393
@Override
9494
protected void parseCreateField(ParseContext context) {
95-
if (context.externalValueSet() == false) {
96-
throw new IllegalStateException("external value not set");
97-
}
98-
String refId = (String) context.externalValue();
95+
throw new UnsupportedOperationException("Cannot directly call parse() on a ParentIdFieldMapper");
96+
}
97+
98+
public void indexValue(ParseContext context, String refId) {
9999
BytesRef binaryValue = new BytesRef(refId);
100100
Field field = new Field(fieldType().name(), binaryValue, Defaults.FIELD_TYPE);
101101
context.doc().add(field);

modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,13 @@ public void parse(ParseContext context) throws IOException {
254254
if (context.sourceToParse().routing() == null) {
255255
throw new IllegalArgumentException("[routing] is missing for join field [" + name() + "]");
256256
}
257-
ParseContext externalContext = context.createExternalValueContext(parent);
258257
String fieldName = fieldType().joiner.parentJoinField(name);
259-
parentIdFields.get(fieldName).parse(externalContext);
258+
parentIdFields.get(fieldName).indexValue(context, parent);
260259
}
261260
if (fieldType().joiner.parentTypeExists(name)) {
262261
// Index the document as a parent
263-
ParseContext externalContext = context.createExternalValueContext(context.sourceToParse().id());
264262
String fieldName = fieldType().joiner.childJoinField(name);
265-
parentIdFields.get(fieldName).parse(externalContext);
263+
parentIdFields.get(fieldName).indexValue(context, context.sourceToParse().id());
266264
}
267265

268266
BytesRef binaryValue = new BytesRef(name);

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbFi
366366
try (OutputStreamStreamOutput out = new OutputStreamStreamOutput(stream)) {
367367
out.setVersion(indexVersion);
368368
out.writeNamedWriteable(queryBuilder);
369-
byte[] queryBuilderAsBytes = stream.toByteArray();
370-
qbField.parse(context.createExternalValueContext(queryBuilderAsBytes));
369+
qbField.indexValue(context, stream.toByteArray());
371370
}
372371
}
373372
}

server/src/main/java/org/elasticsearch/index/mapper/BinaryFieldMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ protected void parseCreateField(ParseContext context) throws IOException {
149149
value = context.parser().binaryValue();
150150
}
151151
}
152+
indexValue(context, value);
153+
}
154+
155+
public void indexValue(ParseContext context, byte[] value) {
152156
if (value == null) {
153157
return;
154158
}

0 commit comments

Comments
 (0)