@@ -284,7 +284,6 @@ private GetResult innerGetFetch(
284284 assert get .exists () : "method should only be called if document could be retrieved" ;
285285 // check first if stored fields to be loaded don't contain an object field
286286 MappingLookup mappingLookup = mapperService .mappingLookup ();
287- final IndexVersion indexVersion = indexSettings .getIndexVersionCreated ();
288287 final Set <String > storedFieldSet = new HashSet <>();
289288 boolean hasInferenceMetadataFields = false ;
290289 if (storedFields != null ) {
@@ -324,6 +323,9 @@ private GetResult innerGetFetch(
324323 throw new ElasticsearchException ("Failed to get id [" + id + "]" , e );
325324 }
326325
326+ final boolean supportDocValuesForIgnoredMetaField = indexSettings .getIndexVersionCreated ()
327+ .onOrAfter (IndexVersions .DOC_VALUES_FOR_IGNORED_META_FIELD );
328+
327329 // put stored fields into result objects
328330 if (leafStoredFieldLoader .storedFields ().isEmpty () == false ) {
329331 Set <String > needed = new HashSet <>();
@@ -337,8 +339,7 @@ private GetResult innerGetFetch(
337339 if (false == needed .contains (entry .getKey ())) {
338340 continue ;
339341 }
340- if (IgnoredFieldMapper .NAME .equals (entry .getKey ())
341- && indexVersion .onOrAfter (IndexVersions .DOC_VALUES_FOR_IGNORED_META_FIELD )) {
342+ if (IgnoredFieldMapper .NAME .equals (entry .getKey ()) && supportDocValuesForIgnoredMetaField ) {
342343 continue ;
343344 }
344345 MappedFieldType ft = mapperService .fieldType (entry .getKey ());
@@ -357,9 +358,7 @@ private GetResult innerGetFetch(
357358 // NOTE: when _ignored is requested via `stored_fields` we need to load it from doc values instead of loading it from stored fields.
358359 // The _ignored field used to be stored, but as a result of supporting aggregations on it, it moved from using a stored field to
359360 // using doc values.
360- if (indexVersion .onOrAfter (IndexVersions .DOC_VALUES_FOR_IGNORED_META_FIELD )
361- && storedFields != null
362- && Arrays .asList (storedFields ).contains (IgnoredFieldMapper .NAME )) {
361+ if (supportDocValuesForIgnoredMetaField && storedFields != null && Arrays .asList (storedFields ).contains (IgnoredFieldMapper .NAME )) {
363362 final DocumentField ignoredDocumentField = loadIgnoredMetadataField (docIdAndVersion );
364363 if (ignoredDocumentField != null ) {
365364 if (metadataFields == null ) {
0 commit comments