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);
}
}
Aggregations