All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.phoboslabs.illuminati.elasticsearch.infra.param.mapping.EsIndexMapping Maven / Gradle / Ivy

/*
 * Copyright 2017 Phoboslabs.me
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package me.phoboslabs.illuminati.elasticsearch.infra.param.mapping;

import me.phoboslabs.illuminati.common.util.StringObjectUtils;

import java.util.HashMap;
import java.util.Map;

public class EsIndexMapping {

    private final Map> rootMappingIndex = new HashMap<>();
    private final Map mappingIndex = new HashMap<>();

    private final static String TYPE_KEY = "type";
    private final static String FIELD_DATE_KEY = "fielddata";
    private final static String PROPERTIES_KEY = "properties";

    public EsIndexMapping () {
    }

    public void setMappingIndexByField (String rootField, final String field, final String type) {
        rootField = StringObjectUtils.convertFirstLetterToLowerlize(rootField);
        Map fieldTypeMap = new HashMap<>();
        fieldTypeMap.put(TYPE_KEY, type);
        if ("text".equalsIgnoreCase(type)) {
            fieldTypeMap.put(FIELD_DATE_KEY, true);
        }

        Map targetMap = null;
        if (this.rootMappingIndex.containsKey(rootField)) {
            targetMap = this.rootMappingIndex.get(rootField);
            Map fieldMap = (Map) targetMap.get(PROPERTIES_KEY);
            fieldMap.put(field, fieldTypeMap);
            targetMap.put(PROPERTIES_KEY, fieldMap);
        } else {
            Map fieldMap = new HashMap<>();
            fieldMap.put(field, fieldTypeMap);

            targetMap = new HashMap<>();
            targetMap.put(PROPERTIES_KEY, fieldMap);
        }

        this.rootMappingIndex.put(rootField, targetMap);
    }

    public Map> getMappingIndex () {
        return this.rootMappingIndex;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy