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

The following examples show how to use org.elasticsearch.index.mapper.MetadataFieldMapper#Builder . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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;
}