Skip to content

Commit 24c41f2

Browse files
committed
Reverted ignore source changes
1 parent a77be70 commit 24c41f2

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.lucene.analysis.TokenStream;
1414
import org.apache.lucene.document.Field;
1515
import org.apache.lucene.document.FieldType;
16+
import org.apache.lucene.document.StoredField;
1617
import org.apache.lucene.index.IndexOptions;
1718
import org.apache.lucene.index.LeafReaderContext;
1819
import org.apache.lucene.index.Term;
@@ -682,11 +683,13 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
682683
// if the delegate can't support synthetic source for the given value, then store a copy of said value so
683684
// that synthetic source can load it
684685
if (fieldType().textFieldType.canUseSyntheticSourceDelegateForSyntheticSource(value.string()) == false) {
686+
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
685687
if (storedFieldInBinaryFormat) {
686688
final var bytesRef = new BytesRef(utfBytes.bytes(), utfBytes.offset(), utfBytes.length());
687-
context.storeFieldForSyntheticSource(fullPath(), leafName(), bytesRef, context.doc());
689+
context.doc().add(new StoredField(fieldName, bytesRef));
688690
} else {
689-
context.storeFieldForSyntheticSource(fullPath(), leafName(), context.encodeFlattenedToken(), context.doc());
691+
692+
context.doc().add(new StoredField(fieldName, value.string()));
690693
}
691694
}
692695
}
@@ -704,13 +707,7 @@ public MatchOnlyTextFieldType fieldType() {
704707

705708
@Override
706709
protected SyntheticSourceSupport syntheticSourceSupport() {
707-
var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
708-
if (kwd != null) {
709-
// merge the two field loaders into one
710-
return new SyntheticSourceSupport.Native(() -> kwd.syntheticFieldLoader(fullPath(), leafName()));
711-
}
712-
713-
return super.syntheticSourceSupport();
710+
return new SyntheticSourceSupport.Native(() -> syntheticFieldLoader(fullPath(), leafName()));
714711
}
715712

716713
private SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldName, String leafFieldName) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public final DocumentParserContext addIgnoredFieldFromContext(IgnoredSourceField
385385
* For instance: { "a.b": "b", "a.c": "c" } => { "a": { "b": "b" }, "a": { "c": "c" } }
386386
* This can happen when storing parts of document source that are not indexed (e.g. disabled objects).
387387
*/
388-
public BytesRef encodeFlattenedToken() throws IOException {
388+
BytesRef encodeFlattenedToken() throws IOException {
389389
boolean old = path().isWithinLeafObject();
390390
path().setWithinLeafObject(true);
391391
BytesRef encoded = XContentDataHelper.encodeToken(parser());

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
2222
import org.apache.lucene.document.Field;
2323
import org.apache.lucene.document.FieldType;
24+
import org.apache.lucene.document.StoredField;
2425
import org.apache.lucene.index.IndexOptions;
2526
import org.apache.lucene.index.Term;
2627
import org.apache.lucene.queries.intervals.Intervals;
@@ -1459,7 +1460,8 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
14591460
}
14601461

14611462
// otherwise, store this field in Lucene so that synthetic source can load it
1462-
context.storeFieldForSyntheticSource(fullPath(), leafName(), context.encodeFlattenedToken(), context.doc());
1463+
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
1464+
context.doc().add(new StoredField(fieldName, value));
14631465
}
14641466
}
14651467

@@ -1637,15 +1639,32 @@ protected void write(XContentBuilder b, Object value) throws IOException {
16371639
});
16381640
}
16391641

1640-
// otherwise, use the delegate
1641-
// note, the delegate itself might not be stored in Lucene due to various reasons (ex. it tripped ignore_above), in such cases, we
1642-
// should've added this field to ignored_source
1642+
return new SyntheticSourceSupport.Native(() -> syntheticFieldLoader(fullPath(), leafName()));
1643+
}
1644+
1645+
private SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldName, String leafFieldName) {
1646+
// since we don't know whether the delegate field loader can be used for synthetic source until parsing, we
1647+
// need to check both this field and the delegate
1648+
1649+
// first field loader, representing this field
1650+
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
1651+
final var thisFieldLayer = new CompositeSyntheticFieldLoader.StoredFieldLayer(fieldName) {
1652+
@Override
1653+
protected void writeValue(Object value, XContentBuilder b) throws IOException {
1654+
b.value(value.toString());
1655+
}
1656+
};
1657+
1658+
final CompositeSyntheticFieldLoader fieldLoader = new CompositeSyntheticFieldLoader(leafFieldName, fullFieldName, thisFieldLayer);
1659+
1660+
// second loader, representing a delegate field, if one exists
16431661
var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
16441662
if (kwd != null) {
1645-
return new SyntheticSourceSupport.Native(() -> kwd.syntheticFieldLoader(fullPath(), leafName()));
1663+
// merge the two field loaders into one
1664+
return fieldLoader.mergedWith(kwd.syntheticFieldLoader(fullPath(), leafName()));
16461665
}
16471666

1648-
return super.syntheticSourceSupport();
1667+
return fieldLoader;
16491668
}
16501669

16511670
public static class SyntheticSourceHelper {

0 commit comments

Comments
 (0)