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"));
}
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"));
}
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);
}
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);
}
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"));
}
Aggregations