Skip to content

Commit 42d4193

Browse files
committed
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 bd32191 commit 42d4193

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
@@ -376,8 +376,7 @@ static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbFi
376376
try (OutputStreamStreamOutput out = new OutputStreamStreamOutput(stream)) {
377377
out.setVersion(indexVersion);
378378
out.writeNamedWriteable(queryBuilder);
379-
byte[] queryBuilderAsBytes = stream.toByteArray();
380-
qbField.parse(context.createExternalValueContext(queryBuilderAsBytes));
379+
qbField.indexValue(context, stream.toByteArray());
381380
}
382381
}
383382
} else {

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

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

0 commit comments

Comments
 (0)