1313import org .apache .lucene .analysis .TokenStream ;
1414import org .apache .lucene .document .Field ;
1515import org .apache .lucene .document .FieldType ;
16- import org .apache .lucene .document .StoredField ;
1716import org .apache .lucene .index .IndexOptions ;
1817import org .apache .lucene .index .LeafReaderContext ;
1918import 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 ) {
0 commit comments