Search in sources :

Example 11 with MapperPlugin

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

the class IndicesModule method getMetadataMappers.

public static Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers(List<MapperPlugin> mapperPlugins) {
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = new LinkedHashMap<>();
    int i = 0;
    Map.Entry<String, MetadataFieldMapper.TypeParser> fieldNamesEntry = null;
    for (Map.Entry<String, MetadataFieldMapper.TypeParser> entry : builtInMetadataMappers.entrySet()) {
        if (i < builtInMetadataMappers.size() - 1) {
            metadataMappers.put(entry.getKey(), entry.getValue());
        } else {
            assert entry.getKey().equals(FieldNamesFieldMapper.NAME) : "_field_names must be the last registered mapper, order counts";
            fieldNamesEntry = entry;
        }
        i++;
    }
    assert fieldNamesEntry != null;
    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 the other mappers, including from plugins
    metadataMappers.put(fieldNamesEntry.getKey(), fieldNamesEntry.getValue());
    return Collections.unmodifiableMap(metadataMappers);
}
Also used : MapperPlugin(org.opensearch.plugins.MapperPlugin) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

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 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 NestedPathFieldMapper (org.opensearch.index.mapper.NestedPathFieldMapper)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 VersionFieldMapper (org.opensearch.index.mapper.VersionFieldMapper)3