use of org.opensearch.index.mapper.MapperService in project OpenSearch by opensearch-project.
the class IndicesServiceTests method testStandAloneMapperServiceWithPlugins.
/**
* Tests that teh {@link MapperService} created by {@link IndicesService#createIndexMapperService(IndexMetadata)} contains
* custom types and similarities registered by plugins
*/
public void testStandAloneMapperServiceWithPlugins() throws IOException {
final String indexName = "test";
final Index index = new Index(indexName, UUIDs.randomBase64UUID());
final IndicesService indicesService = getIndicesService();
final Settings idxSettings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetadata.SETTING_INDEX_UUID, index.getUUID()).put(IndexModule.SIMILARITY_SETTINGS_PREFIX + ".test.type", "fake-similarity").build();
final IndexMetadata indexMetadata = new IndexMetadata.Builder(index.getName()).settings(idxSettings).numberOfShards(1).numberOfReplicas(0).build();
MapperService mapperService = indicesService.createIndexMapperService(indexMetadata);
assertNotNull(mapperService.documentMapperParser().parserContext().typeParser("fake-mapper"));
Similarity sim = mapperService.documentMapperParser().parserContext().getSimilarity("test").get();
assertThat(sim, instanceOf(NonNegativeScoresSimilarity.class));
sim = ((NonNegativeScoresSimilarity) sim).getDelegate();
assertThat(sim, instanceOf(BM25Similarity.class));
}
use of org.opensearch.index.mapper.MapperService in project OpenSearch by opensearch-project.
the class RareTermsAggregatorTests method mapperServiceMock.
@Override
protected MapperService mapperServiceMock() {
MapperService mapperService = mock(MapperService.class);
DocumentMapper mapper = mock(DocumentMapper.class);
when(mapper.typeText()).thenReturn(new Text("_doc"));
when(mapper.type()).thenReturn("_doc");
when(mapperService.documentMapper()).thenReturn(mapper);
return mapperService;
}
Aggregations