org.elasticsearch.index.mapper.MetadataFieldMapper Java Examples

The following examples show how to use org.elasticsearch.index.mapper.MetadataFieldMapper. 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: 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 #2
Source File: ParentFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.type());
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("type")) {
            builder.type(fieldNode.toString());
            iterator.remove();
        } else if (fieldName.equals("postings_format") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            // ignore before 2.0, reject on and after 2.0
            iterator.remove();
        } else if (fieldName.equals("fielddata")) {
            // Only take over `loading`, since that is the only option now that is configurable:
            Map<String, String> fieldDataSettings = SettingsLoader.Helper.loadNestedFromMap(nodeMapValue(fieldNode, "fielddata"));
            if (fieldDataSettings.containsKey(MappedFieldType.Loading.KEY)) {
                Settings settings = settingsBuilder().put(MappedFieldType.Loading.KEY, fieldDataSettings.get(MappedFieldType.Loading.KEY)).build();
                builder.fieldDataSettings(settings);
            }
            iterator.remove();
        }
    }
    return builder;
}
 
Example #3
Source File: IdFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) {
        throw new MapperParsingException(NAME + " is not configurable");
    }
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    parseField(builder, builder.name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("path")) {
            builder.path(fieldNode.toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example #4
Source File: FieldNamesFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    if (parserContext.indexVersionCreated().before(Version.V_1_3_0)) {
        throw new IllegalArgumentException("type="+CONTENT_TYPE+" is not supported on indices created before version 1.3.0. Is your cluster running multiple datanode versions?");
    }
    
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
        parseField(builder, builder.name, node, parserContext);
    }

    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            builder.enabled(nodeBooleanValue(fieldNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #5
Source File: RoutingFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
        parseField(builder, builder.name, node, parserContext);
    }
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("required")) {
            builder.required(nodeBooleanValue(fieldNode));
            iterator.remove();
        } else if (fieldName.equals("path") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            builder.path(fieldNode.toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example #6
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 #7
Source File: IndexFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) {
        return builder;
    }

    parseField(builder, builder.name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            EnabledAttributeMapper mapper = nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED;
            builder.enabled(mapper);
            iterator.remove();
        }
    }
    return builder;
}
 
Example #8
Source File: VersionFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder();
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        if (fieldName.equals("doc_values_format") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            // ignore in 1.x, reject in 2.x
            iterator.remove();
        } else if (fieldName.equals("path")) {
            builder.path(entry.getValue().toString());
            iterator.remove();
        } else if (fieldName.equals("version_type")) {
            builder.versionType(entry.getValue().toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example #9
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 #10
Source File: TTLFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder();
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            EnabledAttributeMapper enabledState = nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED;
            builder.enabled(enabledState);
            iterator.remove();
        } else if (fieldName.equals("default")) {
            TimeValue ttlTimeValue = nodeTimeValue(fieldNode, null);
            if (ttlTimeValue != null) {
                builder.defaultTTL(ttlTimeValue.millis());
            }
            iterator.remove();
        }
    }
    return builder;
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
Source File: UidFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public MetadataFieldMapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) {
        throw new MapperParsingException(NAME + " is not configurable");
    }
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    parseField(builder, builder.name, node, parserContext);
    return builder;
}
 
Example #16
Source File: MappingVersionFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public MetadataFieldMapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder();
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        if (fieldName.equals("doc_values_format") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            // ignore in 1.x, reject in 2.x
            iterator.remove();
        }
    }
    return builder;
}
 
Example #17
Source File: AllFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    
    // parseField below will happily parse the doc_values setting, but it is then never passed to
    // the AllFieldMapper ctor in the builder since it is not valid. Here we validate
    // the doc values settings (old and new) are rejected
    Object docValues = node.get("doc_values");
    if (docValues != null && nodeBooleanValue(docValues)) {
        throw new MapperParsingException("Field [" + name + "] is always tokenized and cannot have doc values");
    }
    // convoluted way of specifying doc values
    Object fielddata = node.get("fielddata");
    if (fielddata != null) {
        Map<String, Object> fielddataMap = nodeMapValue(fielddata, "fielddata");
        Object format = fielddataMap.get("format");
        if ("doc_values".equals(format)) {
            throw new MapperParsingException("Field [" + name + "] is always tokenized and cannot have doc values");
        }
    }
    
    parseTextField(builder, builder.name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            builder.enabled(nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED);
            iterator.remove();
        } else if (fieldName.equals("auto_boost") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            // Old 1.x setting which is now ignored
            iterator.remove();
        }
    }
    return builder;
}
 
Example #18
Source File: TypeFieldMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) {
        throw new MapperParsingException(NAME + " is not configurable");
    }
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    parseField(builder, builder.name, node, parserContext);
    return builder;
}
 
Example #19
Source File: ObjectMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public void toXContent(XContentBuilder builder, Params params, ToXContent custom) throws IOException {
    builder.startObject(simpleName());
    if (nested.isNested()) {
        builder.field("type", NESTED_CONTENT_TYPE);
        if (nested.isIncludeInParent()) {
            builder.field("include_in_parent", true);
        }
        if (nested.isIncludeInRoot()) {
            builder.field("include_in_root", true);
        }
    } else if (mappers.isEmpty() && custom == null) { // only write the object content type if there are no properties, otherwise, it is automatically detected
        builder.field("type", CONTENT_TYPE);
    }
    if (dynamic != null) {
        builder.field("dynamic", dynamic.name().toLowerCase(Locale.ROOT));
    }
    if (enabled != Defaults.ENABLED) {
        builder.field("enabled", enabled);
    }
    if (pathType != Defaults.PATH_TYPE) {
        builder.field("path", pathType.name().toLowerCase(Locale.ROOT));
    }
    if (includeInAll != null) {
        builder.field("include_in_all", includeInAll);
    }

    if (custom != null) {
        custom.toXContent(builder, params);
    }

    doXContent(builder, params);

    // sort the mappers so we get consistent serialization format
    Mapper[] sortedMappers = Iterables.toArray(mappers.values(), Mapper.class);
    Arrays.sort(sortedMappers, new Comparator<Mapper>() {
        @Override
        public int compare(Mapper o1, Mapper o2) {
            return o1.name().compareTo(o2.name());
        }
    });

    int count = 0;
    for (Mapper mapper : sortedMappers) {
        if (!(mapper instanceof MetadataFieldMapper)) {
            if (count++ == 0) {
                builder.startObject("properties");
            }
            mapper.toXContent(builder, params);
        }
    }
    if (count > 0) {
        builder.endObject();
    }
    builder.endObject();
}
 
Example #20
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 #21
Source File: UidFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new UidFieldMapper(indexSettings, fieldType);
}
 
Example #22
Source File: ParentFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String parentType) {
    return new ParentFieldMapper(indexSettings, fieldType, parentType);
}
 
Example #23
Source File: AllFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new AllFieldMapper(indexSettings, fieldType);
}
 
Example #24
Source File: TypeFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new TypeFieldMapper(indexSettings, fieldType);
}
 
Example #25
Source File: TimestampFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new TimestampFieldMapper(indexSettings, fieldType);
}
 
Example #26
Source File: TimestampFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME), parserContext.mapperService().indexSettings());
    if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
        parseField(builder, builder.name, node, parserContext);
    }
    boolean defaultSet = false;
    Boolean ignoreMissing = null;
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            EnabledAttributeMapper enabledState = nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED;
            builder.enabled(enabledState);
            iterator.remove();
        } else if (fieldName.equals("path") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            builder.path(fieldNode.toString());
            iterator.remove();
        } else if (fieldName.equals("format")) {
            builder.dateTimeFormatter(parseDateTimeFormatter(fieldNode.toString()));
            iterator.remove();
        } else if (fieldName.equals("default")) {
            if (fieldNode == null) {
                if (parserContext.indexVersionCreated().onOrAfter(Version.V_1_4_0_Beta1) &&
                        parserContext.indexVersionCreated().before(Version.V_1_5_0)) {
                    // We are reading an index created in 1.4 with feature #7036
                    // `default: null` was explicitly set. We need to change this index to
                    // `ignore_missing: false`
                    builder.ignoreMissing(false);
                } else {
                    throw new TimestampParsingException("default timestamp can not be set to null");
                }
            } else {
                builder.defaultTimestamp(fieldNode.toString());
                defaultSet = true;
            }
            iterator.remove();
        } else if (fieldName.equals("ignore_missing")) {
            ignoreMissing = nodeBooleanValue(fieldNode);
            builder.ignoreMissing(ignoreMissing);
            iterator.remove();
        }
    }

    // We can not accept a default value and rejecting null values at the same time
    if (defaultSet && (ignoreMissing != null && ignoreMissing == false)) {
        throw new TimestampParsingException("default timestamp can not be set with ignore_missing set to false");
    }

    return builder;
}
 
Example #27
Source File: IdFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new IdFieldMapper(indexSettings, fieldType);
}
 
Example #28
Source File: FieldNamesFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new FieldNamesFieldMapper(indexSettings, fieldType);
}
 
Example #29
Source File: RoutingFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new RoutingFieldMapper(indexSettings, fieldType);
}
 
Example #30
Source File: IndexFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public MetadataFieldMapper getDefault(Settings indexSettings, MappedFieldType fieldType, String typeName) {
    return new IndexFieldMapper(indexSettings, fieldType);
}