2626import org .elasticsearch .index .query .SearchExecutionContext ;
2727import org .elasticsearch .indices .breaker .NoneCircuitBreakerService ;
2828import org .elasticsearch .plugins .internal .XContentMeteringParserDecorator ;
29+ import org .elasticsearch .search .lookup .LeafFieldLookupProvider ;
2930import org .elasticsearch .search .lookup .SearchLookup ;
3031import org .elasticsearch .search .lookup .Source ;
3132import org .elasticsearch .xcontent .XContentBuilder ;
@@ -171,6 +172,7 @@ private static void executeIndexTimeScripts(DocumentParserContext context) {
171172 }
172173 SearchLookup searchLookup = new SearchLookup (
173174 context .mappingLookup ().indexTimeLookup ()::get ,
175+ fieldName -> context .mappingLookup ().getMapper (fieldName ) == null ,
174176 (ft , lookup , fto ) -> ft .fielddataBuilder (
175177 new FieldDataContext (
176178 context .indexSettings ().getIndex ().getName (),
@@ -180,7 +182,8 @@ private static void executeIndexTimeScripts(DocumentParserContext context) {
180182 fto
181183 )
182184 ).build (new IndexFieldDataCache .None (), new NoneCircuitBreakerService ()),
183- (ctx , doc ) -> Source .fromBytes (context .sourceToParse ().source ())
185+ (ctx , doc ) -> Source .fromBytes (context .sourceToParse ().source ()),
186+ LeafFieldLookupProvider .fromStoredFields ()
184187 );
185188 // field scripts can be called both by the loop at the end of this method and via
186189 // the document reader, so to ensure that we don't run them multiple times we
0 commit comments