Search in sources :

Example 86 with MapperService

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));
}
Also used : BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) Similarity(org.apache.lucene.search.similarities.Similarity) NonNegativeScoresSimilarity(org.opensearch.index.similarity.NonNegativeScoresSimilarity) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) Index(org.opensearch.index.Index) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) MapperService(org.opensearch.index.mapper.MapperService) NonNegativeScoresSimilarity(org.opensearch.index.similarity.NonNegativeScoresSimilarity)

Example 87 with MapperService

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;
}
Also used : DocumentMapper(org.opensearch.index.mapper.DocumentMapper) Text(org.opensearch.common.text.Text) MapperService(org.opensearch.index.mapper.MapperService)

Aggregations

MapperService (org.opensearch.index.mapper.MapperService)87 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)36 Settings (org.opensearch.common.settings.Settings)27 IndexSettings (org.opensearch.index.IndexSettings)23 IOException (java.io.IOException)19 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)19 DocumentMapper (org.opensearch.index.mapper.DocumentMapper)18 ParsedDocument (org.opensearch.index.mapper.ParsedDocument)18 DocumentField (org.opensearch.common.document.DocumentField)16 Collections (java.util.Collections)15 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)15 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)14 Map (java.util.Map)14 IndexService (org.opensearch.index.IndexService)13 Matchers.containsString (org.hamcrest.Matchers.containsString)12 Set (java.util.Set)11 IndexableField (org.apache.lucene.index.IndexableField)11 Store (org.opensearch.index.store.Store)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)9