Skip to content

Commit 798d91f

Browse files
committed
Renamed ignore source function for clarity
1 parent 2b08acd commit 798d91f

File tree

7 files changed

+23
-61
lines changed

7 files changed

+23
-61
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private MatchOnlyTextFieldType buildFieldType(MapperBuilderContext context, Mult
153153
}
154154

155155
/**
156-
* This is more of a helper function that's useful in TextFieldMapper.SyntheticSourceHelper.syntheticSourceDelegate()
156+
* This is a helper function that's useful in TextFieldMapper.SyntheticSourceHelper.syntheticSourceDelegate()
157157
*/
158158
private FieldType getFieldType() {
159159
FieldType fieldType = new FieldType();
160-
// by definition, match_only_text are not stored
160+
// by definition, match_only_text fields are not stored
161161
fieldType.setStored(false);
162162
return fieldType;
163163
}

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapperTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ public void testStoreParameterDefaultsSyntheticSourceWithKeywordMultiField() thr
327327
}
328328
}
329329

330-
// TODO: add tests when string length is exceeding, same for TextFieldMapper
331-
332330
public void testStoreParameterDefaultsSyntheticSourceTextFieldIsMultiField() throws IOException {
333331
var indexSettingsBuilder = getIndexSettingsBuilder();
334332
indexSettingsBuilder.put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic");

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,20 @@ public final void addIgnoredField(IgnoredSourceFieldMapper.NameValue values) {
335335
}
336336
}
337337

338+
/**
339+
* This function acts as a more "readable" wrapper around adding ignored fields.
340+
*
341+
* This is useful when we want to reuse the existing logic that {@link IgnoredSourceFieldMapper} provides for synthetic source, without
342+
* explicitly calling addIgnoredField(). Without this, it's a bit confusing why fields that are not meant to be ignored, are being
343+
* added to ignored source.
344+
*/
345+
public final void storeFieldForSyntheticSource(String fullPath, String leafName, BytesRef valueBytes, LuceneDocument doc) {
346+
if (canAddIgnoredField()) {
347+
var fieldData = new IgnoredSourceFieldMapper.NameValue(fullPath, fullPath.lastIndexOf(leafName), valueBytes, doc);
348+
ignoredFieldValues.add(fieldData);
349+
}
350+
}
351+
338352
final void removeLastIgnoredField(String name) {
339353
if (ignoredFieldValues.isEmpty() == false && ignoredFieldValues.getLast().name().equals(name)) {
340354
ignoredFieldValues.removeLast();

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ public static final class Builder extends FieldMapper.DimensionBuilder {
214214
private final SourceKeepMode indexSourceKeepMode;
215215
private final boolean isWithinMultiField;
216216

217-
private boolean isSyntheticSourceEnabled;
218-
219217
public Builder(final String name, final MappingParserContext mappingParserContext) {
220218
this(
221219
name,
@@ -461,8 +459,6 @@ private KeywordFieldType buildFieldType(MapperBuilderContext context, FieldType
461459

462460
@Override
463461
public KeywordFieldMapper build(MapperBuilderContext context) {
464-
this.isSyntheticSourceEnabled = context.isSourceSynthetic();
465-
466462
FieldType fieldtype = resolveFieldType(
467463
enableDocValuesSkipper,
468464
forceDocValuesSkipper,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ protected TextFamilyFieldMapper(
4141
*/
4242
protected boolean needsToSupportSyntheticSource() {
4343
if (multiFieldsNotStoredByDefaultIndexVersionCheck()) {
44-
// if we're within a multi field, then supporting synthetic source isn't necessary as that's the
45-
// responsibility of the parent field
44+
// if we're within a multi field, then supporting synthetic source isn't necessary as that's the responsibility of the parent
4645
return isSyntheticSourceEnabled && isWithinMultiField == false;
4746
}
4847
return isSyntheticSourceEnabled;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,21 +1424,19 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
14241424
if (phraseFieldInfo != null) {
14251425
context.doc().add(new Field(phraseFieldInfo.field, value, phraseFieldInfo.fieldType));
14261426
}
1427-
} else if (needsToSupportSyntheticSource() && fieldType.stored() == false) {
1428-
// if synthetic source needs to be supported, yet the field isn't stored, then we need to rely on something
1429-
// else to support synthetic source
1427+
}
14301428

1431-
// if we can rely on the synthetic source delegate for synthetic source, then return
1429+
// if synthetic source needs to be supported, yet the field isn't stored, then we need to rely on something else
1430+
if (needsToSupportSyntheticSource() && fieldType.stored() == false) {
1431+
// if we can rely on the synthetic source delegate for synthetic source, then exit as there is nothing to do
14321432
if (fieldType().canUseSyntheticSourceDelegateForSyntheticSource(value)) {
14331433
return;
14341434
}
14351435

1436-
// record this field's value in _ignored_source - synthetic source will fallback to it automatically
1436+
// otherwise, store this field in Lucene so that synthetic source can load it
14371437
var utfBytes = context.parser().optimizedTextOrNull().bytes();
14381438
var valuesBytesRef = new BytesRef(utfBytes.bytes(), utfBytes.offset(), utfBytes.length());
1439-
context.addIgnoredField(
1440-
new IgnoredSourceFieldMapper.NameValue(fullPath(), fullPath().lastIndexOf(leafName()), valuesBytesRef, context.doc())
1441-
);
1439+
context.storeFieldForSyntheticSource(fullPath(), leafName(), valuesBytesRef, context.doc());
14421440
// final String fieldName = fieldType().syntheticSourceFallbackFieldName();
14431441
// context.doc().add(new StoredField(fieldName, value));
14441442
}

server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsTests.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)