Java Code Examples for org.elasticsearch.index.mapper.MetadataFieldMapper#TypeParser

The following examples show how to use org.elasticsearch.index.mapper.MetadataFieldMapper#TypeParser . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 6 votes vote down vote up
public static DocumentMapperParser newDocumentMapperParser(Settings settings) {
    Settings forcedSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(settings)
            .build();
    SimilarityLookupService similarityLookupService = newSimilarityLookupService(forcedSettings);
    Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers();
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers();
    MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers);
    MapperService mapperService = new MapperService(new Index("test"),
            forcedSettings,
            newAnalysisService(forcedSettings),
            similarityLookupService,
            null,
            mapperRegistry);
    return new DocumentMapperParser(
            forcedSettings,
            mapperService,
            newAnalysisService(forcedSettings),
            similarityLookupService,
            null,
            mapperRegistry);
}
 
Example 2
Source File: IndicesModule.java    From crate with Apache License 2.0 6 votes vote down vote up
private static Map<String, MetadataFieldMapper.TypeParser> initBuiltInMetadataMappers() {
    Map<String, MetadataFieldMapper.TypeParser> builtInMetadataMappers;
    // Use a LinkedHashMap for metadataMappers because iteration order matters
    builtInMetadataMappers = new LinkedHashMap<>();
    // _ignored first so that we always load it, even if only _id is requested
    builtInMetadataMappers.put(IgnoredFieldMapper.NAME, new IgnoredFieldMapper.TypeParser());
    // UID second so it will be the first (if no ignored fields) stored field to load
    // (so will benefit from "fields: []" early termination
    builtInMetadataMappers.put(IdFieldMapper.NAME, new IdFieldMapper.TypeParser());
    builtInMetadataMappers.put(RoutingFieldMapper.NAME, new RoutingFieldMapper.TypeParser());
    builtInMetadataMappers.put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser());
    builtInMetadataMappers.put(VersionFieldMapper.NAME, new VersionFieldMapper.TypeParser());
    builtInMetadataMappers.put(SeqNoFieldMapper.NAME, new SeqNoFieldMapper.TypeParser());
    //_field_names must be added last so that it has a chance to see all the other mappers
    builtInMetadataMappers.put(FieldNamesFieldMapper.NAME, new FieldNamesFieldMapper.TypeParser());
    return Collections.unmodifiableMap(builtInMetadataMappers);
}
 
Example 3
Source File: ESTestCase.java    From crate with Apache License 2.0 6 votes vote down vote up
/** Creates an IndicesModule for testing with the given mappers and metadata mappers. */
public static IndicesModule newTestIndicesModule(Map<String, Mapper.TypeParser> extraMappers,
                                                 Map<String, MetadataFieldMapper.TypeParser> extraMetadataMappers) {
    return new IndicesModule(Collections.singletonList(
        new MapperPlugin() {
            @Override
            public Map<String, Mapper.TypeParser> getMappers() {
                return extraMappers;
            }
            @Override
            public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() {
                return extraMetadataMappers;
            }
        }
    ));
}
 
Example 4
Source File: IndicesModule.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Register a root mapper under the given name.
 */
public synchronized void registerMetadataMapper(String name, MetadataFieldMapper.TypeParser parser) {
    if (metadataMapperParsers.containsKey(name)) {
        throw new IllegalArgumentException("A mapper is already registered for metadata mapper [" + name + "]");
    }
    metadataMapperParsers.put(name, parser);
}
 
Example 5
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static MapperService newMapperService(Settings settings, Client client) {
    Settings indexSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("client.type", "node")
            .put(settings)
            .build();
    Index index = new Index("test");
    Injector parentInjector = new ModulesBuilder()
            .add(new SettingsModule(indexSettings),
            new EnvironmentModule(new Environment(indexSettings)))
            .createInjector();
    AnalysisModule analysisModule = new AnalysisModule(indexSettings,
            parentInjector.getInstance(IndicesAnalysisService.class));
    new AnalysisBaseformPlugin(settings).onModule(analysisModule);
    Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings),
            new IndexNameModule(index),
            analysisModule)
            .createChildInjector(parentInjector);
    AnalysisService analysisService = injector.getInstance(AnalysisService.class);
    SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings);
    Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers();
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers();
    MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers);
    return new MapperService(new Index("test"),
            indexSettings,
            analysisService,
            similarityLookupService,
            null,
            mapperRegistry);
}
 
Example 6
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
private static Map<String, MetadataFieldMapper.TypeParser> registerBuiltInMetadataMappers() {
    Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers = new LinkedHashMap<>();
    metadataMapperParsers.put(UidFieldMapper.NAME, new UidFieldMapper.TypeParser());
    metadataMapperParsers.put(IdFieldMapper.NAME, new IdFieldMapper.TypeParser());
    metadataMapperParsers.put(RoutingFieldMapper.NAME, new RoutingFieldMapper.TypeParser());
    metadataMapperParsers.put(IndexFieldMapper.NAME, new IndexFieldMapper.TypeParser());
    metadataMapperParsers.put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser());
    metadataMapperParsers.put(TypeFieldMapper.NAME, new TypeFieldMapper.TypeParser());
    metadataMapperParsers.put(AllFieldMapper.NAME, new AllFieldMapper.TypeParser());
    metadataMapperParsers.put(TimestampFieldMapper.NAME, new TimestampFieldMapper.TypeParser());
    metadataMapperParsers.put(TTLFieldMapper.NAME, new TTLFieldMapper.TypeParser());
    metadataMapperParsers.put(VersionFieldMapper.NAME, new VersionFieldMapper.TypeParser());
    metadataMapperParsers.put(ParentFieldMapper.NAME, new ParentFieldMapper.TypeParser());
    return metadataMapperParsers;
}
 
Example 7
Source File: IndicesModule.java    From crate with Apache License 2.0 5 votes vote down vote up
private 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 : BUILT_IN_METADATA_MAPPERS.entrySet()) {
        if (i < BUILT_IN_METADATA_MAPPERS.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);
}
 
Example 8
Source File: MapperRegistry.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public MapperRegistry(Map<String, Mapper.TypeParser> mapperParsers,
        Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers) {
    this.mapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(mapperParsers));
    this.metadataMapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(metadataMapperParsers));
}
 
Example 9
Source File: MapperRegistry.java    From crate with Apache License 2.0 4 votes vote down vote up
public MapperRegistry(Map<String, Mapper.TypeParser> mapperParsers,
        Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers, Function<String, Predicate<String>> fieldFilter) {
    this.mapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(mapperParsers));
    this.metadataMapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(metadataMapperParsers));
    this.fieldFilter = fieldFilter;
}
 
Example 10
Source File: MapperRegistry.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Return a map of the meta mappers that have been registered. The
 * returned map uses the name of the field as a key.
 */
public Map<String, MetadataFieldMapper.TypeParser> getMetadataMapperParsers() {
    return metadataMapperParsers;
}
 
Example 11
Source File: MapperRegistry.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Return a map of the meta mappers that have been registered. The
 * returned map uses the name of the field as a key.
 */
public Map<String, MetadataFieldMapper.TypeParser> getMetadataMapperParsers() {
    return metadataMapperParsers;
}
 
Example 12
Source File: MapperPlugin.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Returns additional metadata mapper implementations added by this plugin.
 * <p>
 * The key of the returned {@link Map} is the unique name for the metadata mapper, which
 * is used in the mapping json to configure the metadata mapper, and the value is a
 * {@link MetadataFieldMapper.TypeParser} to parse the mapper settings into a
 * {@link MetadataFieldMapper}.
 */
default Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() {
    return Collections.emptyMap();
}