|
@@ -50,10 +50,15 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
|
|
import org.elasticsearch.index.fielddata.LeafFieldData;
|
|
import org.elasticsearch.index.fielddata.LeafFieldData;
|
|
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
|
import org.elasticsearch.index.fielddata.ScriptDocValues;
|
|
import org.elasticsearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData;
|
|
import org.elasticsearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData;
|
|
|
|
+import org.elasticsearch.index.mapper.DocumentMapperParser;
|
|
import org.elasticsearch.index.mapper.IndexFieldMapper;
|
|
import org.elasticsearch.index.mapper.IndexFieldMapper;
|
|
|
|
+import org.elasticsearch.index.mapper.KeywordFieldMapper;
|
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
|
|
|
+import org.elasticsearch.index.mapper.Mapper;
|
|
import org.elasticsearch.index.mapper.MapperService;
|
|
import org.elasticsearch.index.mapper.MapperService;
|
|
|
|
+import org.elasticsearch.index.mapper.NumberFieldMapper;
|
|
import org.elasticsearch.index.mapper.TextFieldMapper;
|
|
import org.elasticsearch.index.mapper.TextFieldMapper;
|
|
|
|
+import org.elasticsearch.indices.IndicesModule;
|
|
import org.elasticsearch.search.lookup.LeafDocLookup;
|
|
import org.elasticsearch.search.lookup.LeafDocLookup;
|
|
import org.elasticsearch.search.lookup.LeafSearchLookup;
|
|
import org.elasticsearch.search.lookup.LeafSearchLookup;
|
|
import org.elasticsearch.search.lookup.SearchLookup;
|
|
import org.elasticsearch.search.lookup.SearchLookup;
|
|
@@ -63,6 +68,7 @@ import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.function.BiFunction;
|
|
import java.util.function.BiFunction;
|
|
import java.util.function.Supplier;
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
@@ -102,6 +108,12 @@ public class QueryShardContextTests extends ESTestCase {
|
|
assertThat(result.name(), equalTo("name"));
|
|
assertThat(result.name(), equalTo("name"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testBuildAnonymousFieldType() {
|
|
|
|
+ QueryShardContext context = createQueryShardContext("uuid", null);
|
|
|
|
+ assertThat(context.buildAnonymousFieldType("keyword"), instanceOf(KeywordFieldMapper.KeywordFieldType.class));
|
|
|
|
+ assertThat(context.buildAnonymousFieldType("long"), instanceOf(NumberFieldMapper.NumberFieldType.class));
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testToQueryFails() {
|
|
public void testToQueryFails() {
|
|
QueryShardContext context = createQueryShardContext(IndexMetadata.INDEX_UUID_NA_VALUE, null);
|
|
QueryShardContext context = createQueryShardContext(IndexMetadata.INDEX_UUID_NA_VALUE, null);
|
|
Exception exc = expectThrows(Exception.class,
|
|
Exception exc = expectThrows(Exception.class,
|
|
@@ -300,6 +312,12 @@ public class QueryShardContextTests extends ESTestCase {
|
|
when(mapperService.getIndexSettings()).thenReturn(indexSettings);
|
|
when(mapperService.getIndexSettings()).thenReturn(indexSettings);
|
|
when(mapperService.index()).thenReturn(indexMetadata.getIndex());
|
|
when(mapperService.index()).thenReturn(indexMetadata.getIndex());
|
|
when(mapperService.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
|
when(mapperService.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
|
|
|
+ DocumentMapperParser documentMapperParser = mock(DocumentMapperParser.class);
|
|
|
|
+ Map<String, Mapper.TypeParser> typeParserMap = IndicesModule.getMappers(Collections.emptyList());
|
|
|
|
+ Mapper.TypeParser.ParserContext parserContext = new Mapper.TypeParser.ParserContext(name -> null, mapperService,
|
|
|
|
+ typeParserMap::get, Version.CURRENT, () -> null, null, null);
|
|
|
|
+ when(documentMapperParser.parserContext()).thenReturn(parserContext);
|
|
|
|
+ when(mapperService.documentMapperParser()).thenReturn(documentMapperParser);
|
|
if (runtimeDocValues != null) {
|
|
if (runtimeDocValues != null) {
|
|
when(mapperService.fieldType(any())).thenAnswer(fieldTypeInv -> {
|
|
when(mapperService.fieldType(any())).thenAnswer(fieldTypeInv -> {
|
|
String fieldName = (String)fieldTypeInv.getArguments()[0];
|
|
String fieldName = (String)fieldTypeInv.getArguments()[0];
|