5353import  org .elasticsearch .index .mapper .MapperBuilderContext ;
5454import  org .elasticsearch .index .mapper .SourceLoader ;
5555import  org .elasticsearch .index .mapper .SourceValueFetcher ;
56- import  org .elasticsearch .index .mapper .StringFieldType ;
5756import  org .elasticsearch .index .mapper .TextFamilyFieldMapper ;
5857import  org .elasticsearch .index .mapper .TextFieldMapper ;
5958import  org .elasticsearch .index .mapper .TextFieldMapper .TextFieldType ;
@@ -141,14 +140,15 @@ private MatchOnlyTextFieldType buildFieldType(MapperBuilderContext context, Mult
141140            NamedAnalyzer  indexAnalyzer  = analyzers .getIndexAnalyzer ();
142141            TextSearchInfo  tsi  = new  TextSearchInfo (Defaults .FIELD_TYPE , null , searchAnalyzer , searchQuoteAnalyzer );
143142            return  new  MatchOnlyTextFieldType (
144-                     context .buildFullName (leafName ()),
145-                     tsi ,
146-                     indexAnalyzer ,
147-                     context .isSourceSynthetic (),
148-                     meta .getValue (),
149-                     isWithinMultiField ,
150-                     storedFieldInBinaryFormat ,
151-                     TextFieldMapper .SyntheticSourceHelper .syntheticSourceDelegate (getFieldType (), multiFields ));
143+                 context .buildFullName (leafName ()),
144+                 tsi ,
145+                 indexAnalyzer ,
146+                 context .isSourceSynthetic (),
147+                 meta .getValue (),
148+                 isWithinMultiField ,
149+                 storedFieldInBinaryFormat ,
150+                 TextFieldMapper .SyntheticSourceHelper .syntheticSourceDelegate (getFieldType (), multiFields )
151+             );
152152        }
153153
154154        /** 
@@ -189,12 +189,10 @@ private static boolean isSyntheticSourceStoredFieldInBinaryFormat(IndexVersion i
189189        )
190190    );
191191
192-     public  static  class  MatchOnlyTextFieldType  extends  StringFieldType  {
192+     public  static  class  MatchOnlyTextFieldType  extends  TextFamilyFieldType  {
193193
194194        private  final  Analyzer  indexAnalyzer ;
195195        private  final  TextFieldType  textFieldType ;
196- 
197-         private  final  boolean  withinMultiField ;
198196        private  final  boolean  storedFieldInBinaryFormat ;
199197
200198        public  MatchOnlyTextFieldType (
@@ -207,11 +205,9 @@ public MatchOnlyTextFieldType(
207205            boolean  storedFieldInBinaryFormat ,
208206            KeywordFieldMapper .KeywordFieldType  syntheticSourceDelegate 
209207        ) {
210-             super (name , true , false , false , tsi , meta );
208+             super (name , true , false , false , tsi , meta ,  isSyntheticSource ,  withinMultiField );
211209            this .indexAnalyzer  = Objects .requireNonNull (indexAnalyzer );
212-             // TODO: need to set synthetic source delegate correctly 
213-             this .textFieldType  = new  TextFieldType (name , isSyntheticSource , syntheticSourceDelegate );
214-             this .withinMultiField  = withinMultiField ;
210+             this .textFieldType  = new  TextFieldType (name , isSyntheticSource , withinMultiField , syntheticSourceDelegate );
215211            this .storedFieldInBinaryFormat  = storedFieldInBinaryFormat ;
216212        }
217213
@@ -254,15 +250,15 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
254250
255251            // if synthetic source is enabled, then fetch the value from one of the valid source providers 
256252            if  (searchExecutionContext .isSourceSynthetic ()) {
257-                 if  (withinMultiField ) {
253+                 if  (isWithinMultiField ) {
258254                    // fetch the value from parent 
259255                    return  parentFieldValueFetcher (searchExecutionContext );
260256                } else  if  (textFieldType .syntheticSourceDelegate ().isPresent ()) {
261257                    // otherwise, if there is a delegate field, fetch the value from it 
262258                    return  delegateFieldValueFetcher (searchExecutionContext , textFieldType .syntheticSourceDelegate ().get ());
263259                } else  {
264260                    // otherwise, fetch the value from self 
265-                     return  storedFieldFetcher (name (), syntheticSourceFallbackFieldName (true ));
261+                     return  storedFieldFetcher (name (), syntheticSourceFallbackFieldName ());
266262                }
267263            }
268264
@@ -302,7 +298,7 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
302298            var  parent  = searchExecutionContext .lookup ().fieldType (parentField );
303299
304300            if  (parent  instanceof  KeywordFieldMapper .KeywordFieldType  keywordParent  && keywordParent .isIgnoreAboveSet ()) {
305-                 final  String  parentFieldName  = keywordParent .syntheticSourceFallbackFieldName (searchExecutionContext . isSourceSynthetic () );
301+                 final  String  parentFieldName  = keywordParent .syntheticSourceFallbackFieldName ();
306302                if  (parent .isStored ()) {
307303                    return  storedFieldFetcher (parentField , parentFieldName );
308304                } else  if  (parent .hasDocValues ()) {
@@ -331,18 +327,20 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
331327        ) {
332328            // because we don't know whether the delegate field will be ignored during parsing, we must also check the current field 
333329            String  fieldName  = name ();
334-             String  fallbackName  = syntheticSourceFallbackFieldName (true );
330+             String  fallbackName  = syntheticSourceFallbackFieldName ();
335331
336332            // delegate field names 
337333            String  delegateFieldName  = keywordDelegate .name ();
338-             String  delegateFieldFallbackName  = keywordDelegate .syntheticSourceFallbackFieldName (true );
334+             String  delegateFieldFallbackName  = keywordDelegate .syntheticSourceFallbackFieldName ();
339335
340336            if  (keywordDelegate .isStored ()) {
341337                return  storedFieldFetcher (delegateFieldName , delegateFieldFallbackName , fieldName , fallbackName );
342338            } else  if  (keywordDelegate .hasDocValues ()) {
343339                var  ifd  = searchExecutionContext .getForField (keywordDelegate , MappedFieldType .FielddataOperation .SEARCH );
344-                 return  combineFieldFetchers (docValuesFieldFetcher (ifd ),
345-                                             storedFieldFetcher (delegateFieldFallbackName , fieldName , fallbackName ));
340+                 return  combineFieldFetchers (
341+                     docValuesFieldFetcher (ifd ),
342+                     storedFieldFetcher (delegateFieldFallbackName , fieldName , fallbackName )
343+                 );
346344            } else  {
347345                assert  false  : "multi field should either be stored or have doc values" ;
348346                return  sourceFieldValueFetcher (searchExecutionContext );
@@ -576,8 +574,8 @@ protected BytesRef toBytesRef(Object v) {
576574
577575        @ Override 
578576        public  BlockLoader  blockLoader (BlockLoaderContext  blContext ) {
579-             if  (textFieldType .isSyntheticSource ()) {
580-                 final  String  fieldName  = syntheticSourceFallbackFieldName (true );
577+             if  (textFieldType .isSyntheticSourceEnabled ()) {
578+                 final  String  fieldName  = syntheticSourceFallbackFieldName ();
581579                if  (storedFieldInBinaryFormat ) {
582580                    return  new  BlockStoredFieldsReader .BytesFromBytesRefsBlockLoader (fieldName );
583581                } else  {
@@ -595,9 +593,9 @@ public IndexFieldData.Builder fielddataBuilder(FieldDataContext fieldDataContext
595593            if  (fieldDataContext .fielddataOperation () != FielddataOperation .SCRIPT ) {
596594                throw  new  IllegalArgumentException (CONTENT_TYPE  + " fields do not support sorting and aggregations" );
597595            }
598-             if  (textFieldType .isSyntheticSource ()) {
596+             if  (textFieldType .isSyntheticSourceEnabled ()) {
599597                return  (cache , breaker ) -> new  StoredFieldSortedBinaryIndexFieldData (
600-                     syntheticSourceFallbackFieldName (true ),
598+                     syntheticSourceFallbackFieldName (),
601599                    CoreValuesSourceType .KEYWORD ,
602600                    TextDocValuesField ::new 
603601                ) {
@@ -684,7 +682,7 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
684682            // if the delegate can't support synthetic source for the given value, then store a copy of said value so 
685683            // that synthetic source can load it 
686684            if  (fieldType ().textFieldType .canUseSyntheticSourceDelegateForSyntheticSource (value .string ()) == false ) {
687-                 final  String  fieldName  = fieldType ().syntheticSourceFallbackFieldName (fieldType (). textFieldType . isSyntheticSource () );
685+                 final  String  fieldName  = fieldType ().syntheticSourceFallbackFieldName ();
688686                if  (storedFieldInBinaryFormat ) {
689687                    final  var  bytesRef  = new  BytesRef (utfBytes .bytes (), utfBytes .offset (), utfBytes .length ());
690688                    context .doc ().add (new  StoredField (fieldName , bytesRef ));
@@ -716,7 +714,7 @@ private SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldN
716714        // on a delegate field if one exists. Because of this uncertainty, we need multiple field loaders. 
717715
718716        // first field loader, representing this field 
719-         final  String  fieldName  = fieldType ().syntheticSourceFallbackFieldName (fieldType (). textFieldType . isSyntheticSource () );
717+         final  String  fieldName  = fieldType ().syntheticSourceFallbackFieldName ();
720718        final  var  thisFieldLayer  = new  CompositeSyntheticFieldLoader .StoredFieldLayer (fieldName ) {
721719            @ Override 
722720            protected  void  writeValue (Object  value , XContentBuilder  b ) throws  IOException  {
0 commit comments