Java Code Examples for org.elasticsearch.common.Strings#toUnderscoreCase()

The following examples show how to use org.elasticsearch.common.Strings#toUnderscoreCase() . 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: 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 2
Source File: TypeParsers.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void parseNumberField(NumberFieldMapper.Builder builder, String name, Map<String, Object> numberNode, Mapper.TypeParser.ParserContext parserContext) {
    parseField(builder, name, numberNode, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = numberNode.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("precision_step")) {
            builder.precisionStep(nodeIntegerValue(propNode));
            iterator.remove();
        } else if (propName.equals("ignore_malformed")) {
            builder.ignoreMalformed(nodeBooleanValue(propNode));
            iterator.remove();
        } else if (propName.equals("coerce")) {
            builder.coerce(nodeBooleanValue(propNode));
            iterator.remove();
        } else if (propName.equals("omit_norms")) {
            builder.omitNorms(nodeBooleanValue(propNode));
            iterator.remove();
        } else if (propName.equals("similarity")) {
            builder.similarity(parserContext.similarityLookupService().similarity(propNode.toString()));
            iterator.remove();
        } else if (parseMultiField(builder, name, parserContext, propName, propNode)) {
            iterator.remove();
        }
    }
}
 
Example 3
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 4
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 5
Source File: LongFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    LongFieldMapper.Builder builder = longField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeLongValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example 6
Source File: IpFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    IpFieldMapper.Builder builder = ipField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(propNode.toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example 7
Source File: TypeParsers.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void parseTermVector(String fieldName, String termVector, FieldMapper.Builder builder) throws MapperParsingException {
    termVector = Strings.toUnderscoreCase(termVector);
    if ("no".equals(termVector)) {
        builder.storeTermVectors(false);
    } else if ("yes".equals(termVector)) {
        builder.storeTermVectors(true);
    } else if ("with_offsets".equals(termVector)) {
        builder.storeTermVectorOffsets(true);
    } else if ("with_positions".equals(termVector)) {
        builder.storeTermVectorPositions(true);
    } else if ("with_positions_offsets".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorOffsets(true);
    } else if ("with_positions_payloads".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorPayloads(true);
    } else if ("with_positions_offsets_payloads".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorOffsets(true);
        builder.storeTermVectorPayloads(true);
    } else {
        throw new MapperParsingException("wrong value for termVector [" + termVector + "] for field [" + fieldName + "]");
    }
}
 
Example 8
Source File: BooleanFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    BooleanFieldMapper.Builder builder = booleanField(name);
    parseField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeBooleanValue(propNode));
            iterator.remove();
        } else if (parseMultiField(builder, name, parserContext, propName, propNode)) {
            iterator.remove();
        }
    }
    return builder;
}
 
Example 9
Source File: ByteFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    ByteFieldMapper.Builder builder = byteField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeByteValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example 10
Source File: Settings.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
Settings(Map<String, String> settings) {
    // we use a sorted map for consistent serialization when using getAsMap()
    // TODO: use Collections.unmodifiableMap with a TreeMap
    this.settings = ImmutableSortedMap.copyOf(settings);
    Map<String, String> forcedUnderscoreSettings = null;
    for (Map.Entry<String, String> entry : settings.entrySet()) {
        String toUnderscoreCase = Strings.toUnderscoreCase(entry.getKey());
        if (!toUnderscoreCase.equals(entry.getKey())) {
            if (forcedUnderscoreSettings == null) {
                forcedUnderscoreSettings = new HashMap<>();
            }
            forcedUnderscoreSettings.put(toUnderscoreCase, entry.getValue());
        }
    }
    this.forcedUnderscoreSettings = forcedUnderscoreSettings == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(forcedUnderscoreSettings);
}
 
Example 11
Source File: AnalysisService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public TokenizerFactory tokenizer(String name) {
    TokenizerFactory tokenizerFactory = tokenizers.get(name);
    if (tokenizerFactory != null) {
        return tokenizerFactory;
    }
    String underscoreName = Strings.toUnderscoreCase(name);
    tokenizerFactory = tokenizers.get(underscoreName);
    if (tokenizerFactory != null) {
        DEPRECATION_LOGGER.deprecated("Deprecated tokenizer name [" + name + "], use [" + underscoreName + "] instead");
    }
    return tokenizerFactory;
}
 
Example 12
Source File: DynamicTemplate.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static DynamicTemplate parse(String name, Map<String, Object> conf) throws MapperParsingException {
    String match = null;
    String pathMatch = null;
    String unmatch = null;
    String pathUnmatch = null;
    Map<String, Object> mapping = null;
    String matchMappingType = null;
    String matchPattern = "simple";

    for (Map.Entry<String, Object> entry : conf.entrySet()) {
        String propName = Strings.toUnderscoreCase(entry.getKey());
        if ("match".equals(propName)) {
            match = entry.getValue().toString();
        } else if ("path_match".equals(propName)) {
            pathMatch = entry.getValue().toString();
        } else if ("unmatch".equals(propName)) {
            unmatch = entry.getValue().toString();
        } else if ("path_unmatch".equals(propName)) {
            pathUnmatch = entry.getValue().toString();
        } else if ("match_mapping_type".equals(propName)) {
            matchMappingType = entry.getValue().toString();
        } else if ("match_pattern".equals(propName)) {
            matchPattern = entry.getValue().toString();
        } else if ("mapping".equals(propName)) {
            mapping = (Map<String, Object>) entry.getValue();
        }
    }

    if (match == null && pathMatch == null && matchMappingType == null) {
        throw new MapperParsingException("template must have match, path_match or match_mapping_type set");
    }
    if (mapping == null) {
        throw new MapperParsingException("template must have mapping set");
    }
    return new DynamicTemplate(name, conf, pathMatch, pathUnmatch, match, unmatch, matchMappingType, MatchType.fromString(matchPattern), mapping);
}
 
Example 13
Source File: TypeParsers.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static ContentPath.Type parsePathType(String name, String path) throws MapperParsingException {
    path = Strings.toUnderscoreCase(path);
    if ("just_name".equals(path)) {
        return ContentPath.Type.JUST_NAME;
    } else if ("full".equals(path)) {
        return ContentPath.Type.FULL;
    } else {
        throw new MapperParsingException("wrong value for pathType [" + path + "] for object [" + name + "]");
    }
}
 
Example 14
Source File: XmlXContentBuilder.java    From elasticsearch-xml with Apache License 2.0 5 votes vote down vote up
public XmlXContentBuilder field(String name, FieldCaseConversion conversion) throws IOException {
    if (conversion == FieldCaseConversion.UNDERSCORE) {
        if (cachedStringBuilder == null) {
            cachedStringBuilder = new StringBuilder();
        }
        name = Strings.toUnderscoreCase(name, cachedStringBuilder);
    } else if (conversion == FieldCaseConversion.CAMELCASE) {
        if (cachedStringBuilder == null) {
            cachedStringBuilder = new StringBuilder();
        }
        name = Strings.toCamelCase(name, cachedStringBuilder);
    }
    generator.writeFieldName(name);
    return this;
}
 
Example 15
Source File: ObjectMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    ObjectMapper.Builder builder = createBuilder(name);
    parseNested(name, node, 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 (parseObjectOrDocumentTypeProperties(fieldName, fieldNode, parserContext, builder) || parseObjectProperties(name, fieldName,  fieldNode, parserContext, builder)) {
            iterator.remove();
        }
    }
    return builder;
}
 
Example 16
Source File: BaseGeoPointFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder;
    if (parserContext.indexVersionCreated().before(Version.V_2_2_0)) {
        builder = new GeoPointFieldMapperLegacy.Builder(name);
    } else {
        builder = new GeoPointFieldMapper.Builder(name);
    }
    parseField(builder, name, node, parserContext);

    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("lat_lon")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " lat_lon parameter is deprecated and will be removed "
                + "in the next major release");
            builder.enableLatLon(XContentMapValues.nodeBooleanValue(propNode));
            iterator.remove();
        } else if (propName.equals("precision_step")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " precision_step parameter is deprecated and will be removed "
                + "in the next major release");
            builder.precisionStep(XContentMapValues.nodeIntegerValue(propNode));
            iterator.remove();
        } else if (propName.equals("geohash")) {
            builder.enableGeoHash(XContentMapValues.nodeBooleanValue(propNode));
            iterator.remove();
        } else if (propName.equals("geohash_prefix")) {
            builder.geoHashPrefix(XContentMapValues.nodeBooleanValue(propNode));
            if (XContentMapValues.nodeBooleanValue(propNode)) {
                builder.enableGeoHash(true);
            }
            iterator.remove();
        } else if (propName.equals("geohash_precision")) {
            if (propNode instanceof Integer) {
                builder.geoHashPrecision(XContentMapValues.nodeIntegerValue(propNode));
            } else {
                builder.geoHashPrecision(GeoUtils.geoHashLevelsForPrecision(propNode.toString()));
            }
            iterator.remove();
        } else if (propName.equals(Names.IGNORE_MALFORMED)) {
            builder.ignoreMalformed(XContentMapValues.nodeBooleanValue(propNode));
            iterator.remove();
        } else if (parseMultiField(builder, name, parserContext, propName, propNode)) {
            iterator.remove();
        }
    }

    if (builder instanceof GeoPointFieldMapperLegacy.Builder) {
        return GeoPointFieldMapperLegacy.parse((GeoPointFieldMapperLegacy.Builder) builder, node, parserContext);
    }

    return (GeoPointFieldMapper.Builder) builder;
}
 
Example 17
Source File: StringFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    StringFieldMapper.Builder builder = stringField(name);
    parseTextField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(propNode.toString());
            iterator.remove();
        } else if (propName.equals("search_quote_analyzer")) {
            NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString());
            if (analyzer == null) {
                throw new MapperParsingException("Analyzer [" + propNode.toString() + "] not found for field [" + name + "]");
            }
            builder.searchQuotedAnalyzer(analyzer);
            iterator.remove();
        } else if (propName.equals("position_increment_gap") ||
                parserContext.indexVersionCreated().before(Version.V_2_0_0) && propName.equals("position_offset_gap")) {
            int newPositionIncrementGap = XContentMapValues.nodeIntegerValue(propNode, -1);
            if (newPositionIncrementGap < 0) {
                throw new MapperParsingException("positions_increment_gap less than 0 aren't allowed.");
            }
            builder.positionIncrementGap(newPositionIncrementGap);
            // we need to update to actual analyzers if they are not set in this case...
            // so we can inject the position increment gap...
            if (builder.fieldType().indexAnalyzer() == null) {
                builder.fieldType().setIndexAnalyzer(parserContext.analysisService().defaultIndexAnalyzer());
            }
            if (builder.fieldType().searchAnalyzer() == null) {
                builder.fieldType().setSearchAnalyzer(parserContext.analysisService().defaultSearchAnalyzer());
            }
            if (builder.fieldType().searchQuoteAnalyzer() == null) {
                builder.fieldType().setSearchQuoteAnalyzer(parserContext.analysisService().defaultSearchQuoteAnalyzer());
            }
            iterator.remove();
        } else if (propName.equals("ignore_above")) {
            builder.ignoreAbove(XContentMapValues.nodeIntegerValue(propNode, -1));
            iterator.remove();
        } else if (parseMultiField(builder, name, parserContext, propName, propNode)) {
            iterator.remove();
        }
    }
    return builder;
}
 
Example 18
Source File: CreateAnalyzerStatementAnalyzer.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public CreateAnalyzerAnalyzedStatement visitCharFilters(CharFilters charFilters, Context context) {
    for (NamedProperties charFilterNode : charFilters.charFilters()) {

        String name = charFilterNode.ident();
        Optional<GenericProperties> properties = charFilterNode.properties();

        String underscoreName = Strings.toUnderscoreCase(name);
        if (!underscoreName.equalsIgnoreCase(name)) {
            deprecationLogger.deprecated("Deprecated char_filter name [{}], use [{}] instead", name, underscoreName);
        }

        // use a builtin char-filter without parameters
        if (!properties.isPresent()) {
            // validate
            if (!context.statement.analyzerService().hasBuiltInCharFilter(name)) {
                throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "Non-existing built-in char-filter '%s'", name));
            }
            // build
            context.statement.addCharFilter(name, Settings.EMPTY);
        } else {
            String type = extractType(properties.get(), context.analysis.parameterContext());
            if (!context.statement.analyzerService().hasBuiltInCharFilter(type)) {
                // only builtin char-filters can be extended, for now
                throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "Non-existing built-in char-filter" +
                    " type '%s'", type));
            }

            // build
            // transform name as char-filter is not publicly available
            name = String.format(Locale.ENGLISH, "%s_%s", context.statement.ident(), name);
            Settings.Builder builder = Settings.builder();
            for (Map.Entry<String, Expression> charFilterProperty : properties.get().properties().entrySet()) {
                GenericPropertiesConverter.genericPropertyToSetting(builder,
                    context.statement.getSettingsKey("index.analysis.char_filter.%s.%s", name, charFilterProperty.getKey()),
                    charFilterProperty.getValue(),
                    context.analysis.parameterContext());
            }
            context.statement.addCharFilter(name, builder.build());
        }
    }
    return null;
}
 
Example 19
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 20
Source File: CreateAnalyzerStatementAnalyzer.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public CreateAnalyzerAnalyzedStatement visitTokenizer(Tokenizer tokenizer, Context context) {
    String name = tokenizer.ident();
    Optional<io.crate.sql.tree.GenericProperties> properties = tokenizer.properties();

    String underscoreName = Strings.toUnderscoreCase(name);
    if (!underscoreName.equalsIgnoreCase(name)) {
        deprecationLogger.deprecated("Deprecated tokenizer name [{}], use [{}] instead", name, underscoreName);
    }

    if (!properties.isPresent()) {
        // use a builtin tokenizer without parameters

        // validate
        if (!context.statement.analyzerService().hasBuiltInTokenizer(name)) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Non-existing tokenizer '%s'", name));
        }
        // build
        context.statement.tokenDefinition(name, Settings.EMPTY);
    } else {
        // validate
        if (!context.statement.analyzerService().hasBuiltInTokenizer(name)) {
            // type mandatory
            String evaluatedType = extractType(properties.get(), context.analysis.parameterContext());
            if (!context.statement.analyzerService().hasBuiltInTokenizer(evaluatedType)) {
                // only builtin tokenizers can be extended, for now
                throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "Non-existing built-in tokenizer type '%s'", evaluatedType));
            }
        } else {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH, "tokenizer name '%s' is reserved", name));
        }
        // build
        // transform name as tokenizer is not publicly available
        name = String.format(Locale.ENGLISH, "%s_%s", context.statement.ident(), name);

        Settings.Builder builder = Settings.builder();
        for (Map.Entry<String, Expression> tokenizerProperty : properties.get().properties().entrySet()) {
            GenericPropertiesConverter.genericPropertyToSetting(builder,
                context.statement.getSettingsKey("index.analysis.tokenizer.%s.%s", name, tokenizerProperty.getKey()),
                tokenizerProperty.getValue(),
                context.analysis.parameterContext());
        }
        context.statement.tokenDefinition(name, builder.build());
    }

    return null;
}