Search in sources :

Example 6 with MapperRegistry

use of org.opensearch.indices.mapper.MapperRegistry in project OpenSearch by opensearch-project.

the class MapperServiceTestCase method createMapperService.

/**
 * Create a {@link MapperService} like we would for an index.
 */
protected final MapperService createMapperService(Version version, XContentBuilder mapping) throws IOException {
    IndexMetadata meta = IndexMetadata.builder("index").settings(Settings.builder().put("index.version.created", version)).numberOfReplicas(0).numberOfShards(1).build();
    IndexSettings indexSettings = new IndexSettings(meta, getIndexSettings());
    MapperRegistry mapperRegistry = new IndicesModule(getPlugins().stream().filter(p -> p instanceof MapperPlugin).map(p -> (MapperPlugin) p).collect(toList())).getMapperRegistry();
    ScriptModule scriptModule = new ScriptModule(Settings.EMPTY, getPlugins().stream().filter(p -> p instanceof ScriptPlugin).map(p -> (ScriptPlugin) p).collect(toList()));
    ScriptService scriptService = new ScriptService(getIndexSettings(), scriptModule.engines, scriptModule.contexts);
    SimilarityService similarityService = new SimilarityService(indexSettings, scriptService, emptyMap());
    MapperService mapperService = new MapperService(indexSettings, createIndexAnalyzers(indexSettings), xContentRegistry(), similarityService, mapperRegistry, () -> {
        throw new UnsupportedOperationException();
    }, () -> true, scriptService);
    merge(mapperService, mapping);
    return mapperService;
}
Also used : IndicesModule(org.opensearch.indices.IndicesModule) BytesReference(org.opensearch.common.bytes.BytesReference) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ScriptModule(org.opensearch.script.ScriptModule) SimilarityService(org.opensearch.index.similarity.SimilarityService) ToXContent(org.opensearch.common.xcontent.ToXContent) CheckedConsumer(org.opensearch.common.CheckedConsumer) CompressedXContent(org.opensearch.common.compress.CompressedXContent) MapperPlugin(org.opensearch.plugins.MapperPlugin) Version(org.opensearch.Version) AnalyzerScope(org.opensearch.index.analysis.AnalyzerScope) MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) Directory(org.apache.lucene.store.Directory) XContentFactory(org.opensearch.common.xcontent.XContentFactory) Collections.singletonMap(java.util.Collections.singletonMap) Mockito.anyString(org.mockito.Mockito.anyString) ScriptService(org.opensearch.script.ScriptService) Collections.emptyMap(java.util.Collections.emptyMap) NamedAnalyzer(org.opensearch.index.analysis.NamedAnalyzer) ScriptPlugin(org.opensearch.plugins.ScriptPlugin) Collections.emptyList(java.util.Collections.emptyList) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Collection(java.util.Collection) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Plugin(org.opensearch.plugins.Plugin) SearchLookup(org.opensearch.search.lookup.SearchLookup) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) Collectors.toList(java.util.stream.Collectors.toList) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) RandomIndexWriter(org.apache.lucene.tests.index.RandomIndexWriter) BytesArray(org.opensearch.common.bytes.BytesArray) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) IndexSettings(org.opensearch.index.IndexSettings) QueryShardContext(org.opensearch.index.query.QueryShardContext) XContentType(org.opensearch.common.xcontent.XContentType) Mockito.any(org.mockito.Mockito.any) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Collections(java.util.Collections) IndexReader(org.apache.lucene.index.IndexReader) IndexAnalyzers(org.opensearch.index.analysis.IndexAnalyzers) Mockito.mock(org.mockito.Mockito.mock) ScriptService(org.opensearch.script.ScriptService) ScriptModule(org.opensearch.script.ScriptModule) IndicesModule(org.opensearch.indices.IndicesModule) MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) MapperPlugin(org.opensearch.plugins.MapperPlugin) IndexSettings(org.opensearch.index.IndexSettings) SimilarityService(org.opensearch.index.similarity.SimilarityService) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ScriptPlugin(org.opensearch.plugins.ScriptPlugin)

Example 7 with MapperRegistry

use of org.opensearch.indices.mapper.MapperRegistry in project OpenSearch by opensearch-project.

the class MapperTestUtils method newMapperService.

public static MapperService newMapperService(NamedXContentRegistry xContentRegistry, Path tempDir, Settings settings, IndicesModule indicesModule, String indexName) throws IOException {
    Settings.Builder settingsBuilder = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), tempDir).put(settings);
    if (settings.get(IndexMetadata.SETTING_VERSION_CREATED) == null) {
        settingsBuilder.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT);
    }
    Settings finalSettings = settingsBuilder.build();
    MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexName, finalSettings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(indexSettings, finalSettings).indexAnalyzers;
    SimilarityService similarityService = new SimilarityService(indexSettings, null, Collections.emptyMap());
    return new MapperService(indexSettings, indexAnalyzers, xContentRegistry, similarityService, mapperRegistry, () -> null, () -> false, null);
}
Also used : MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) SimilarityService(org.opensearch.index.similarity.SimilarityService) IndexAnalyzers(org.opensearch.index.analysis.IndexAnalyzers) Settings(org.opensearch.common.settings.Settings) MapperService(org.opensearch.index.mapper.MapperService)

Example 8 with MapperRegistry

use of org.opensearch.indices.mapper.MapperRegistry in project OpenSearch by opensearch-project.

the class IndicesModuleTests method testNoOpFieldPredicate.

public void testNoOpFieldPredicate() {
    List<MapperPlugin> mapperPlugins = Arrays.asList(new MapperPlugin() {

        @Override
        public Function<String, Predicate<String>> getFieldFilter() {
            return MapperPlugin.NOOP_FIELD_FILTER;
        }
    }, new MapperPlugin() {

        @Override
        public Function<String, Predicate<String>> getFieldFilter() {
            return index -> index.equals("hidden_index") ? field -> false : MapperPlugin.NOOP_FIELD_PREDICATE;
        }
    }, new MapperPlugin() {

        @Override
        public Function<String, Predicate<String>> getFieldFilter() {
            return index -> index.equals("filtered") ? field -> field.equals("visible") : MapperPlugin.NOOP_FIELD_PREDICATE;
        }
    });
    IndicesModule indicesModule = new IndicesModule(mapperPlugins);
    MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
    Function<String, Predicate<String>> fieldFilter = mapperRegistry.getFieldFilter();
    assertSame(MapperPlugin.NOOP_FIELD_PREDICATE, fieldFilter.apply(randomAlphaOfLengthBetween(3, 7)));
    assertNotSame(MapperPlugin.NOOP_FIELD_PREDICATE, fieldFilter.apply("hidden_index"));
    assertNotSame(MapperPlugin.NOOP_FIELD_PREDICATE, fieldFilter.apply("filtered"));
}
Also used : IdFieldMapper(org.opensearch.index.mapper.IdFieldMapper) Arrays(java.util.Arrays) IgnoredFieldMapper(org.opensearch.index.mapper.IgnoredFieldMapper) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) MapperPlugin(org.opensearch.plugins.MapperPlugin) Version(org.opensearch.Version) NestedPathFieldMapper(org.opensearch.index.mapper.NestedPathFieldMapper) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DataStreamFieldMapper(org.opensearch.index.mapper.DataStreamFieldMapper) MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) VersionUtils(org.opensearch.test.VersionUtils) Map(java.util.Map) VersionFieldMapper(org.opensearch.index.mapper.VersionFieldMapper) IndexFieldMapper(org.opensearch.index.mapper.IndexFieldMapper) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) FieldNamesFieldMapper(org.opensearch.index.mapper.FieldNamesFieldMapper) Mapper(org.opensearch.index.mapper.Mapper) SourceFieldMapper(org.opensearch.index.mapper.SourceFieldMapper) List(java.util.List) TextFieldMapper(org.opensearch.index.mapper.TextFieldMapper) MetadataFieldMapper(org.opensearch.index.mapper.MetadataFieldMapper) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) RoutingFieldMapper(org.opensearch.index.mapper.RoutingFieldMapper) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) SeqNoFieldMapper(org.opensearch.index.mapper.SeqNoFieldMapper) Function(java.util.function.Function) MapperPlugin(org.opensearch.plugins.MapperPlugin) MapperRegistry(org.opensearch.indices.mapper.MapperRegistry) Matchers.containsString(org.hamcrest.Matchers.containsString) Predicate(java.util.function.Predicate)

Aggregations

MapperRegistry (org.opensearch.indices.mapper.MapperRegistry)8 Settings (org.opensearch.common.settings.Settings)5 Collections (java.util.Collections)4 Map (java.util.Map)4 Version (org.opensearch.Version)4 IndexSettings (org.opensearch.index.IndexSettings)4 IndexAnalyzers (org.opensearch.index.analysis.IndexAnalyzers)4 SimilarityService (org.opensearch.index.similarity.SimilarityService)4 Set (java.util.Set)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 MapperService (org.opensearch.index.mapper.MapperService)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.singletonMap (java.util.Collections.singletonMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2