Search in sources :

Example 1 with ElasticsearchMappingBuilder

use of org.apache.gora.elasticsearch.mapping.ElasticsearchMappingBuilder in project gora by apache.

the class ElasticsearchStore method initialize.

@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
    try {
        LOG.debug("Initializing Elasticsearch store");
        ElasticsearchParameters parameters = ElasticsearchParameters.load(properties, getConf());
        super.initialize(keyClass, persistentClass, properties);
        ElasticsearchMappingBuilder<K, T> builder = new ElasticsearchMappingBuilder<>(this);
        InputStream mappingStream;
        if (properties.containsKey(XML_MAPPING_DEFINITION)) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("{} = {}", XML_MAPPING_DEFINITION, properties.getProperty(XML_MAPPING_DEFINITION));
            }
            mappingStream = org.apache.commons.io.IOUtils.toInputStream(properties.getProperty(XML_MAPPING_DEFINITION), (Charset) null);
        } else {
            mappingStream = getClass().getClassLoader().getResourceAsStream(properties.getProperty(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE));
        }
        String xsdValidation = properties.getProperty(XSD_VALIDATION, "false");
        builder.readMappingFile(mappingStream, Boolean.parseBoolean(xsdValidation));
        elasticsearchMapping = builder.getElasticsearchMapping();
        client = createClient(parameters);
        LOG.info("Elasticsearch store was successfully initialized.");
    } catch (Exception ex) {
        LOG.error("Error while initializing Elasticsearch store", ex);
        throw new GoraException(ex);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) InputStream(java.io.InputStream) Charset(java.nio.charset.Charset) ElasticsearchParameters(org.apache.gora.elasticsearch.utils.ElasticsearchParameters) ElasticsearchMappingBuilder(org.apache.gora.elasticsearch.mapping.ElasticsearchMappingBuilder) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 ElasticsearchMappingBuilder (org.apache.gora.elasticsearch.mapping.ElasticsearchMappingBuilder)1 ElasticsearchParameters (org.apache.gora.elasticsearch.utils.ElasticsearchParameters)1 GoraException (org.apache.gora.util.GoraException)1