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

apoc.es.ElasticSearchConfig Maven / Gradle / Ivy

package apoc.es;

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

import static apoc.es.ElasticSearchHandler.Version;

public class ElasticSearchConfig {
    public static final String HEADERS_KEY = "headers";
    public static final String VERSION_KEY = "version";

    private final Map headers;
    private final ElasticSearchHandler version;

    public ElasticSearchConfig(Map config) {
        this(config, null);
    }
    
    public ElasticSearchConfig(Map config, String httpMethod) {
        if (config == null) {
            config = Collections.emptyMap();
        }
        
        Map headerConf = (Map) config.getOrDefault(HEADERS_KEY, new HashMap<>());
        headerConf.putIfAbsent("content-type", "application/json");
        if (httpMethod != null) {
            headerConf.putIfAbsent("method", httpMethod);
        }
        this.headers = headerConf;
        
        String versionConf = (String) config.getOrDefault(VERSION_KEY, Version.DEFAULT.name());
        this.version = Version.valueOf(versionConf).get();
    }

    public Map getHeaders() {
        return headers;
    }

    public ElasticSearchHandler getVersion() {
        return version;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy