|  | @@ -8,12 +8,22 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  package org.elasticsearch.index.mapper;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import org.apache.lucene.index.LeafReaderContext;
 | 
	
		
			
				|  |  | +import org.apache.lucene.search.IndexSearcher;
 | 
	
		
			
				|  |  |  import org.elasticsearch.Version;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.Strings;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.settings.Settings;
 | 
	
		
			
				|  |  | +import org.elasticsearch.index.query.SearchExecutionContext;
 | 
	
		
			
				|  |  | +import org.elasticsearch.search.lookup.SearchLookup;
 | 
	
		
			
				|  |  |  import org.elasticsearch.xcontent.XContentBuilder;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.util.ArrayList;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Set;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  import static org.hamcrest.Matchers.instanceOf;
 | 
	
		
			
				|  |  | +import static org.mockito.Mockito.mock;
 | 
	
		
			
				|  |  | +import static org.mockito.Mockito.when;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  public class PlaceHolderFieldMapperTests extends MapperServiceTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -40,4 +50,26 @@ public class PlaceHolderFieldMapperTests extends MapperServiceTestCase {
 | 
	
		
			
				|  |  |          assertThat(service.fieldType("myfield"), instanceOf(PlaceHolderFieldMapper.PlaceHolderFieldType.class));
 | 
	
		
			
				|  |  |          assertEquals(Strings.toString(mapping), Strings.toString(service.documentMapper().mapping()));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void testFetchValue() throws Exception {
 | 
	
		
			
				|  |  | +        MapperService mapperService = createMapperService(Version.fromString("5.0.0"), fieldMapping(b -> b.field("type", "unknown")));
 | 
	
		
			
				|  |  | +        withLuceneIndex(mapperService, iw -> {
 | 
	
		
			
				|  |  | +            iw.addDocument(
 | 
	
		
			
				|  |  | +                createMapperService(fieldMapping(b -> b.field("type", "keyword"))).documentMapper()
 | 
	
		
			
				|  |  | +                    .parse(source(b -> b.field("field", "value")))
 | 
	
		
			
				|  |  | +                    .rootDoc()
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +        }, iw -> {
 | 
	
		
			
				|  |  | +            SearchLookup lookup = new SearchLookup(mapperService::fieldType, fieldDataLookup());
 | 
	
		
			
				|  |  | +            SearchExecutionContext searchExecutionContext = mock(SearchExecutionContext.class);
 | 
	
		
			
				|  |  | +            when(searchExecutionContext.lookup()).thenReturn(lookup);
 | 
	
		
			
				|  |  | +            when(searchExecutionContext.sourcePath("field")).thenReturn(Set.of("field"));
 | 
	
		
			
				|  |  | +            ValueFetcher valueFetcher = mapperService.fieldType("field").valueFetcher(searchExecutionContext, null);
 | 
	
		
			
				|  |  | +            IndexSearcher searcher = newSearcher(iw);
 | 
	
		
			
				|  |  | +            LeafReaderContext context = searcher.getIndexReader().leaves().get(0);
 | 
	
		
			
				|  |  | +            lookup.source().setSegmentAndDocument(context, 0);
 | 
	
		
			
				|  |  | +            valueFetcher.setNextReader(context);
 | 
	
		
			
				|  |  | +            assertEquals(List.of("value"), valueFetcher.fetchValues(lookup.source(), new ArrayList<>()));
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |