Search in sources :

Example 1 with MapperPlugin

use of org.elasticsearch.plugins.MapperPlugin in project elasticsearch by elastic.

the class IndicesModuleTests method testDuplicateOtherPluginMetadataMapper.

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

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

Example 2 with MapperPlugin

use of org.elasticsearch.plugins.MapperPlugin in project elasticsearch by elastic.

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(), Matchers.containsString("already registered"));
}
Also used : MapperPlugin(org.elasticsearch.plugins.MapperPlugin)

Example 3 with MapperPlugin

use of org.elasticsearch.plugins.MapperPlugin in project elasticsearch by elastic.

the class IndicesModule method getMetadataMappers.

private Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers(List<MapperPlugin> mapperPlugins) {
    // Use a LinkedHashMap for metadataMappers because iteration order matters
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = new LinkedHashMap<>();
    // builtin metadata mappers
    // UID first so it will be the first stored field to load (so will benefit from "fields: []" early termination
    metadataMappers.put(UidFieldMapper.NAME, new UidFieldMapper.TypeParser());
    metadataMappers.put(IdFieldMapper.NAME, new IdFieldMapper.TypeParser());
    metadataMappers.put(RoutingFieldMapper.NAME, new RoutingFieldMapper.TypeParser());
    metadataMappers.put(IndexFieldMapper.NAME, new IndexFieldMapper.TypeParser());
    metadataMappers.put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser());
    metadataMappers.put(TypeFieldMapper.NAME, new TypeFieldMapper.TypeParser());
    metadataMappers.put(AllFieldMapper.NAME, new AllFieldMapper.TypeParser());
    metadataMappers.put(VersionFieldMapper.NAME, new VersionFieldMapper.TypeParser());
    metadataMappers.put(ParentFieldMapper.NAME, new ParentFieldMapper.TypeParser());
    metadataMappers.put(SeqNoFieldMapper.NAME, new SeqNoFieldMapper.TypeParser());
    for (MapperPlugin mapperPlugin : mapperPlugins) {
        for (Map.Entry<String, MetadataFieldMapper.TypeParser> entry : mapperPlugin.getMetadataMappers().entrySet()) {
            if (entry.getKey().equals(FieldNamesFieldMapper.NAME)) {
                throw new IllegalArgumentException("Plugin cannot contain metadata mapper [" + FieldNamesFieldMapper.NAME + "]");
            }
            if (metadataMappers.put(entry.getKey(), entry.getValue()) != null) {
                throw new IllegalArgumentException("MetadataFieldMapper [" + entry.getKey() + "] is already registered");
            }
        }
    }
    // we register _field_names here so that it has a chance to see all other mappers, including from plugins
    metadataMappers.put(FieldNamesFieldMapper.NAME, new FieldNamesFieldMapper.TypeParser());
    return Collections.unmodifiableMap(metadataMappers);
}
Also used : MapperPlugin(org.elasticsearch.plugins.MapperPlugin) UidFieldMapper(org.elasticsearch.index.mapper.UidFieldMapper) SourceFieldMapper(org.elasticsearch.index.mapper.SourceFieldMapper) IndexFieldMapper(org.elasticsearch.index.mapper.IndexFieldMapper) LinkedHashMap(java.util.LinkedHashMap) ParentFieldMapper(org.elasticsearch.index.mapper.ParentFieldMapper) AllFieldMapper(org.elasticsearch.index.mapper.AllFieldMapper) SeqNoFieldMapper(org.elasticsearch.index.mapper.SeqNoFieldMapper) TypeFieldMapper(org.elasticsearch.index.mapper.TypeFieldMapper) IdFieldMapper(org.elasticsearch.index.mapper.IdFieldMapper) RoutingFieldMapper(org.elasticsearch.index.mapper.RoutingFieldMapper) VersionFieldMapper(org.elasticsearch.index.mapper.VersionFieldMapper) FieldNamesFieldMapper(org.elasticsearch.index.mapper.FieldNamesFieldMapper) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with MapperPlugin

use of org.elasticsearch.plugins.MapperPlugin in project elasticsearch by elastic.

the class IndicesModule method getMappers.

private Map<String, Mapper.TypeParser> getMappers(List<MapperPlugin> mapperPlugins) {
    Map<String, Mapper.TypeParser> mappers = new LinkedHashMap<>();
    // builtin mappers
    for (NumberFieldMapper.NumberType type : NumberFieldMapper.NumberType.values()) {
        mappers.put(type.typeName(), new NumberFieldMapper.TypeParser(type));
    }
    for (RangeFieldMapper.RangeType type : RangeFieldMapper.RangeType.values()) {
        mappers.put(type.typeName(), new RangeFieldMapper.TypeParser(type));
    }
    mappers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser());
    mappers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser());
    mappers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser());
    mappers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser());
    mappers.put(ScaledFloatFieldMapper.CONTENT_TYPE, new ScaledFloatFieldMapper.TypeParser());
    mappers.put(TextFieldMapper.CONTENT_TYPE, new TextFieldMapper.TypeParser());
    mappers.put(KeywordFieldMapper.CONTENT_TYPE, new KeywordFieldMapper.TypeParser());
    mappers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser());
    mappers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser());
    mappers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser());
    mappers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser());
    mappers.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser());
    if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) {
        mappers.put(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser());
    }
    for (MapperPlugin mapperPlugin : mapperPlugins) {
        for (Map.Entry<String, Mapper.TypeParser> entry : mapperPlugin.getMappers().entrySet()) {
            if (mappers.put(entry.getKey(), entry.getValue()) != null) {
                throw new IllegalArgumentException("Mapper [" + entry.getKey() + "] is already registered");
            }
        }
    }
    return Collections.unmodifiableMap(mappers);
}
Also used : RangeFieldMapper(org.elasticsearch.index.mapper.RangeFieldMapper) GeoPointFieldMapper(org.elasticsearch.index.mapper.GeoPointFieldMapper) MapperPlugin(org.elasticsearch.plugins.MapperPlugin) IpFieldMapper(org.elasticsearch.index.mapper.IpFieldMapper) LinkedHashMap(java.util.LinkedHashMap) GeoShapeFieldMapper(org.elasticsearch.index.mapper.GeoShapeFieldMapper) TokenCountFieldMapper(org.elasticsearch.index.mapper.TokenCountFieldMapper) ScaledFloatFieldMapper(org.elasticsearch.index.mapper.ScaledFloatFieldMapper) ObjectMapper(org.elasticsearch.index.mapper.ObjectMapper) DateFieldMapper(org.elasticsearch.index.mapper.DateFieldMapper) NumberFieldMapper(org.elasticsearch.index.mapper.NumberFieldMapper) BooleanFieldMapper(org.elasticsearch.index.mapper.BooleanFieldMapper) CompletionFieldMapper(org.elasticsearch.index.mapper.CompletionFieldMapper) KeywordFieldMapper(org.elasticsearch.index.mapper.KeywordFieldMapper) BinaryFieldMapper(org.elasticsearch.index.mapper.BinaryFieldMapper) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TextFieldMapper(org.elasticsearch.index.mapper.TextFieldMapper)

Example 5 with MapperPlugin

use of org.elasticsearch.plugins.MapperPlugin in project elasticsearch by elastic.

the class IndicesModuleTests method testDuplicateBuiltinMetadataMapper.

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

        @Override
        public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() {
            return Collections.singletonMap(IdFieldMapper.NAME, new FakeMetadataMapperParser());
        }
    });
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new IndicesModule(plugins));
    assertThat(e.getMessage(), Matchers.containsString("already registered"));
}
Also used : MetadataFieldMapper(org.elasticsearch.index.mapper.MetadataFieldMapper) MapperPlugin(org.elasticsearch.plugins.MapperPlugin) Map(java.util.Map)

Aggregations

MapperPlugin (org.elasticsearch.plugins.MapperPlugin)7 Map (java.util.Map)5 MetadataFieldMapper (org.elasticsearch.index.mapper.MetadataFieldMapper)3 LinkedHashMap (java.util.LinkedHashMap)2 FieldNamesFieldMapper (org.elasticsearch.index.mapper.FieldNamesFieldMapper)2 IdFieldMapper (org.elasticsearch.index.mapper.IdFieldMapper)2 TextFieldMapper (org.elasticsearch.index.mapper.TextFieldMapper)2 AllFieldMapper (org.elasticsearch.index.mapper.AllFieldMapper)1 BinaryFieldMapper (org.elasticsearch.index.mapper.BinaryFieldMapper)1 BooleanFieldMapper (org.elasticsearch.index.mapper.BooleanFieldMapper)1 CompletionFieldMapper (org.elasticsearch.index.mapper.CompletionFieldMapper)1 DateFieldMapper (org.elasticsearch.index.mapper.DateFieldMapper)1 GeoPointFieldMapper (org.elasticsearch.index.mapper.GeoPointFieldMapper)1 GeoShapeFieldMapper (org.elasticsearch.index.mapper.GeoShapeFieldMapper)1 IndexFieldMapper (org.elasticsearch.index.mapper.IndexFieldMapper)1 IpFieldMapper (org.elasticsearch.index.mapper.IpFieldMapper)1 KeywordFieldMapper (org.elasticsearch.index.mapper.KeywordFieldMapper)1 Mapper (org.elasticsearch.index.mapper.Mapper)1 NumberFieldMapper (org.elasticsearch.index.mapper.NumberFieldMapper)1 ObjectMapper (org.elasticsearch.index.mapper.ObjectMapper)1