Search in sources :

Example 6 with MapperPlugin

use of org.opensearch.plugins.MapperPlugin 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) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AllFieldMapper(org.opensearch.index.mapper.AllFieldMapper) 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) TypeFieldMapper(org.opensearch.index.mapper.TypeFieldMapper) 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)

Example 7 with MapperPlugin

use of org.opensearch.plugins.MapperPlugin in project OpenSearch by opensearch-project.

the class IndicesModuleTests method testDuplicateOtherPluginMetadataMapper.

public void testDuplicateOtherPluginMetadataMapper() {
    MapperPlugin plugin = new MapperPlugin() {

        @Override
        public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() {
            return Collections.singletonMap("foo", PARSER);
        }
    };
    List<MapperPlugin> plugins = Arrays.asList(plugin, plugin);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new IndicesModule(plugins));
    assertThat(e.getMessage(), containsString("already registered"));
}
Also used : MapperPlugin(org.opensearch.plugins.MapperPlugin) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 8 with MapperPlugin

use of org.opensearch.plugins.MapperPlugin in project OpenSearch by opensearch-project.

the class IndicesModuleTests method testDuplicateOtherPluginMapper.

public void testDuplicateOtherPluginMapper() {
    MapperPlugin plugin = new MapperPlugin() {

        @Override
        public Map<String, Mapper.TypeParser> getMappers() {
            return Collections.singletonMap("foo", new FakeMapperParser());
        }
    };
    List<MapperPlugin> plugins = Arrays.asList(plugin, plugin);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new IndicesModule(plugins));
    assertThat(e.getMessage(), containsString("already registered"));
}
Also used : MapperPlugin(org.opensearch.plugins.MapperPlugin) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 9 with MapperPlugin

use of org.opensearch.plugins.MapperPlugin in project OpenSearch by opensearch-project.

the class IndicesModuleTests method testDefaultFieldFilterIsNoOp.

public void testDefaultFieldFilterIsNoOp() {
    int numPlugins = randomIntBetween(0, 10);
    List<MapperPlugin> mapperPlugins = new ArrayList<>(numPlugins);
    for (int i = 0; i < numPlugins; i++) {
        mapperPlugins.add(new MapperPlugin() {
        });
    }
    IndicesModule indicesModule = new IndicesModule(mapperPlugins);
    Function<String, Predicate<String>> fieldFilter = indicesModule.getMapperRegistry().getFieldFilter();
    assertSame(MapperPlugin.NOOP_FIELD_FILTER, fieldFilter);
}
Also used : MapperPlugin(org.opensearch.plugins.MapperPlugin) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Predicate(java.util.function.Predicate)

Example 10 with MapperPlugin

use of org.opensearch.plugins.MapperPlugin in project OpenSearch by opensearch-project.

the class IndicesModuleTests method testDuplicateBuiltinMapper.

public void testDuplicateBuiltinMapper() {
    List<MapperPlugin> plugins = Arrays.asList(new MapperPlugin() {

        @Override
        public Map<String, Mapper.TypeParser> getMappers() {
            return Collections.singletonMap(TextFieldMapper.CONTENT_TYPE, new FakeMapperParser());
        }
    });
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new IndicesModule(plugins));
    assertThat(e.getMessage(), containsString("already registered"));
}
Also used : IdFieldMapper(org.opensearch.index.mapper.IdFieldMapper) IgnoredFieldMapper(org.opensearch.index.mapper.IgnoredFieldMapper) AllFieldMapper(org.opensearch.index.mapper.AllFieldMapper) DataStreamFieldMapper(org.opensearch.index.mapper.DataStreamFieldMapper) VersionFieldMapper(org.opensearch.index.mapper.VersionFieldMapper) IndexFieldMapper(org.opensearch.index.mapper.IndexFieldMapper) FieldNamesFieldMapper(org.opensearch.index.mapper.FieldNamesFieldMapper) Mapper(org.opensearch.index.mapper.Mapper) SourceFieldMapper(org.opensearch.index.mapper.SourceFieldMapper) TypeFieldMapper(org.opensearch.index.mapper.TypeFieldMapper) TextFieldMapper(org.opensearch.index.mapper.TextFieldMapper) MetadataFieldMapper(org.opensearch.index.mapper.MetadataFieldMapper) RoutingFieldMapper(org.opensearch.index.mapper.RoutingFieldMapper) SeqNoFieldMapper(org.opensearch.index.mapper.SeqNoFieldMapper) MapperPlugin(org.opensearch.plugins.MapperPlugin) Map(java.util.Map)

Aggregations

MapperPlugin (org.opensearch.plugins.MapperPlugin)11 Map (java.util.Map)7 Matchers.containsString (org.hamcrest.Matchers.containsString)5 MetadataFieldMapper (org.opensearch.index.mapper.MetadataFieldMapper)5 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Predicate (java.util.function.Predicate)3 Version (org.opensearch.Version)3 AllFieldMapper (org.opensearch.index.mapper.AllFieldMapper)3 DataStreamFieldMapper (org.opensearch.index.mapper.DataStreamFieldMapper)3 FieldNamesFieldMapper (org.opensearch.index.mapper.FieldNamesFieldMapper)3 IdFieldMapper (org.opensearch.index.mapper.IdFieldMapper)3 IgnoredFieldMapper (org.opensearch.index.mapper.IgnoredFieldMapper)3 IndexFieldMapper (org.opensearch.index.mapper.IndexFieldMapper)3 Mapper (org.opensearch.index.mapper.Mapper)3 RoutingFieldMapper (org.opensearch.index.mapper.RoutingFieldMapper)3 SeqNoFieldMapper (org.opensearch.index.mapper.SeqNoFieldMapper)3 SourceFieldMapper (org.opensearch.index.mapper.SourceFieldMapper)3 TextFieldMapper (org.opensearch.index.mapper.TextFieldMapper)3 TypeFieldMapper (org.opensearch.index.mapper.TypeFieldMapper)3