Skip to content

Commit 5ad94fd

Browse files
committed
Use ignore source in match only text
1 parent ec91a34 commit 5ad94fd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
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;
1716
import org.apache.lucene.index.IndexOptions;
1817
import org.apache.lucene.index.LeafReaderContext;
1918
import org.apache.lucene.index.Term;
@@ -683,12 +682,11 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
683682
// if the delegate can't support synthetic source for the given value, then store a copy of said value so
684683
// that synthetic source can load it
685684
if (fieldType().textFieldType.canUseSyntheticSourceDelegateForSyntheticSource(value.string()) == false) {
686-
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
687685
if (storedFieldInBinaryFormat) {
688686
final var bytesRef = new BytesRef(utfBytes.bytes(), utfBytes.offset(), utfBytes.length());
689-
context.doc().add(new StoredField(fieldName, bytesRef));
687+
context.storeFieldForSyntheticSource(fullPath(), leafName(), bytesRef, context.doc());
690688
} else {
691-
context.doc().add(new StoredField(fieldName, value.string()));
689+
context.storeFieldForSyntheticSource(fullPath(), leafName(), context.encodeFlattenedToken(), context.doc());
692690
}
693691
}
694692
}
@@ -706,7 +704,13 @@ public MatchOnlyTextFieldType fieldType() {
706704

707705
@Override
708706
protected SyntheticSourceSupport syntheticSourceSupport() {
709-
return new SyntheticSourceSupport.Native(() -> syntheticFieldLoader(fullPath(), leafName()));
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();
710714
}
711715

712716
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
@@ -391,7 +391,7 @@ public final DocumentParserContext addIgnoredFieldFromContext(IgnoredSourceField
391391
* For instance: { "a.b": "b", "a.c": "c" } => { "a": { "b": "b" }, "a": { "c": "c" } }
392392
* This can happen when storing parts of document source that are not indexed (e.g. disabled objects).
393393
*/
394-
BytesRef encodeFlattenedToken() throws IOException {
394+
public BytesRef encodeFlattenedToken() throws IOException {
395395
boolean old = path().isWithinLeafObject();
396396
path().setWithinLeafObject(true);
397397
BytesRef encoded = XContentDataHelper.encodeToken(parser());

0 commit comments

Comments
 (0)