@@ -261,8 +261,6 @@ private class AsyncBulkShardInferenceAction implements Runnable {
261261 private final AtomicArray <FieldInferenceResponseAccumulator > inferenceResults ;
262262 private final CoordinatingIndexingPressureWrapper coordinatingWrapper ;
263263
264- private long estimatedInferenceRequestMemoryUsageInBytes = 0 ; // Estimated memory used by requests that perform inference
265-
266264 private AsyncBulkShardInferenceAction (
267265 boolean useLegacyFormat ,
268266 Map <String , InferenceFieldMetadata > fieldInferenceMap ,
@@ -492,8 +490,22 @@ private long addFieldInferenceRequests(BulkItemRequest item, int itemIndex, Map<
492490 String inferenceId = entry .getInferenceId ();
493491 ChunkingSettings chunkingSettings = ChunkingSettingsBuilder .fromMap (entry .getChunkingSettings (), false );
494492
495- if (isInferenceRequired (entry , docMap ) == false ) {
496- continue ;
493+ if (useLegacyFormat ) {
494+ var originalFieldValue = XContentMapValues .extractValue (field , docMap );
495+ if (originalFieldValue instanceof Map || (originalFieldValue == null && entry .getSourceFields ().length == 1 )) {
496+ // Inference has already been computed, or there is no inference required.
497+ continue ;
498+ }
499+ } else {
500+ var inferenceMetadataFieldsValue = XContentMapValues .extractValue (
501+ InferenceMetadataFieldsMapper .NAME + "." + field ,
502+ docMap ,
503+ EXPLICIT_NULL
504+ );
505+ if (inferenceMetadataFieldsValue != null ) {
506+ // Inference has already been computed
507+ continue ;
508+ }
497509 }
498510
499511 int order = 0 ;
@@ -623,32 +635,6 @@ private boolean incrementIndexingPressure(IndexRequestWithIndexingPressure index
623635 return success ;
624636 }
625637
626- private boolean isInferenceRequired (InferenceFieldMetadata inferenceFieldMetadata , Map <String , Object > docMap ) {
627- String field = inferenceFieldMetadata .getName ();
628-
629- boolean inferenceRequired = true ;
630- if (useLegacyFormat ) {
631- var originalFieldValue = XContentMapValues .extractValue (field , docMap );
632- if (originalFieldValue instanceof Map
633- || (originalFieldValue == null && inferenceFieldMetadata .getSourceFields ().length == 1 )) {
634- // Inference has already been computed, or there is no inference required.
635- inferenceRequired = false ;
636- }
637- } else {
638- var inferenceMetadataFieldsValue = XContentMapValues .extractValue (
639- InferenceMetadataFieldsMapper .NAME + "." + field ,
640- docMap ,
641- EXPLICIT_NULL
642- );
643- if (inferenceMetadataFieldsValue != null ) {
644- // Inference has already been computed
645- inferenceRequired = false ;
646- }
647- }
648-
649- return inferenceRequired ;
650- }
651-
652638 private FieldInferenceResponseAccumulator ensureResponseAccumulatorSlot (int id ) {
653639 FieldInferenceResponseAccumulator acc = inferenceResults .get (id );
654640 if (acc == null ) {
0 commit comments