Search in sources :

Example 1 with Configuration

use of play.api.Configuration in project play2-elasticsearch by cleverage.

the class IndexConfig method loadMappingFromConfig.

/**
     * Load additional mappings from config entry "elasticsearch.index.mapping"
     * @param indexName
     */
private void loadMappingFromConfig(String indexName) {
    Configuration mappingConfig = (configuration.getConfig("elasticsearch." + indexName + ".mappings") == Option.apply((Configuration) null)) ? null : configuration.getConfig("elasticsearch." + indexName + ".mappings").get();
    if (mappingConfig != null) {
        Iterator<Tuple2<String, ConfigValue>> iter = mappingConfig.entrySet().iterator();
        while (iter.hasNext()) {
            Tuple2<String, ConfigValue> mapping = iter.next();
            String indexType = mapping._1();
            IndexQueryPath indexQueryPath = new IndexQueryPath(indexName, indexType);
            if (mapping._2().unwrapped() instanceof String) {
                indexMappings.put(indexQueryPath, (String) mapping._2().unwrapped());
            } else {
                try {
                    indexMappings.put(indexQueryPath, Json.toJson(mapping._2().unwrapped()).toString());
                } catch (Exception e) {
                    Logger.warn("Incorrect value in elasticsearch.index.mappings", e);
                }
            }
        }
    }
}
Also used : ConfigValue(com.typesafe.config.ConfigValue) Configuration(play.api.Configuration) Tuple2(scala.Tuple2)

Aggregations

ConfigValue (com.typesafe.config.ConfigValue)1 Configuration (play.api.Configuration)1 Tuple2 (scala.Tuple2)1