|
31 | 31 |
|
32 | 32 | package org.opensearch.index.query;
|
33 | 33 |
|
| 34 | +import org.apache.lucene.analysis.standard.StandardAnalyzer; |
34 | 35 | import org.apache.lucene.document.Field;
|
35 | 36 | import org.apache.lucene.document.StringField;
|
36 | 37 | import org.apache.lucene.index.DirectoryReader;
|
|
63 | 64 | import org.opensearch.index.fielddata.LeafFieldData;
|
64 | 65 | import org.opensearch.index.fielddata.ScriptDocValues;
|
65 | 66 | import org.opensearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData;
|
| 67 | +import org.opensearch.index.mapper.ContentPath; |
| 68 | +import org.opensearch.index.mapper.DerivedFieldMapper; |
| 69 | +import org.opensearch.index.mapper.DocumentMapper; |
66 | 70 | import org.opensearch.index.mapper.IndexFieldMapper;
|
67 | 71 | import org.opensearch.index.mapper.MappedFieldType;
|
| 72 | +import org.opensearch.index.mapper.Mapper; |
68 | 73 | import org.opensearch.index.mapper.MapperService;
|
| 74 | +import org.opensearch.index.mapper.MappingLookup; |
69 | 75 | import org.opensearch.index.mapper.TextFieldMapper;
|
70 | 76 | import org.opensearch.search.lookup.LeafDocLookup;
|
71 | 77 | import org.opensearch.search.lookup.LeafSearchLookup;
|
@@ -118,6 +124,25 @@ public void testFailIfFieldMappingNotFound() {
|
118 | 124 | assertThat(result.name(), equalTo("name"));
|
119 | 125 | }
|
120 | 126 |
|
| 127 | + public void testDerivedFieldMapping() { |
| 128 | + QueryShardContext context = createQueryShardContext(IndexMetadata.INDEX_UUID_NA_VALUE, null); |
| 129 | + assertNull(context.failIfFieldMappingNotFound("test_derived", null)); |
| 130 | + DocumentMapper documentMapper = mock(DocumentMapper.class); |
| 131 | + Mapper.BuilderContext builderContext = new Mapper.BuilderContext(Settings.EMPTY, new ContentPath(0)); |
| 132 | + DerivedFieldMapper derivedFieldMapper = new DerivedFieldMapper.Builder("test_derived").build(builderContext); |
| 133 | + MappingLookup mappingLookup = new MappingLookup( |
| 134 | + Collections.singletonList(derivedFieldMapper), |
| 135 | + Collections.emptyList(), |
| 136 | + Collections.emptyList(), |
| 137 | + 0, |
| 138 | + new StandardAnalyzer() |
| 139 | + ); |
| 140 | + when(documentMapper.mappers()).thenReturn(mappingLookup); |
| 141 | + context.setDerivedFieldMappers(documentMapper); |
| 142 | + context.setAllowUnmappedFields(false); |
| 143 | + assertEquals(derivedFieldMapper.fieldType(), context.failIfFieldMappingNotFound("test_derived", null)); |
| 144 | + } |
| 145 | + |
121 | 146 | public void testToQueryFails() {
|
122 | 147 | QueryShardContext context = createQueryShardContext(IndexMetadata.INDEX_UUID_NA_VALUE, null);
|
123 | 148 | Exception exc = expectThrows(Exception.class, () -> context.toQuery(new AbstractQueryBuilder() {
|
|
0 commit comments