use of io.searchbox.indices.CreateIndex in project jmxtrans by jmxtrans.
the class ElasticWriter method createMappingIfNeeded.
private static void createMappingIfNeeded(JestClient jestClient, String indexName, String typeName) throws ElasticWriterException, IOException {
synchronized (CREATE_MAPPING_LOCK) {
IndicesExists indicesExists = new IndicesExists.Builder(indexName).build();
boolean indexExists = jestClient.execute(indicesExists).isSucceeded();
if (!indexExists) {
CreateIndex createIndex = new CreateIndex.Builder(indexName).build();
jestClient.execute(createIndex);
URL url = ElasticWriter.class.getResource("/elastic-mapping.json");
String mapping = Resources.toString(url, Charsets.UTF_8);
PutMapping putMapping = new PutMapping.Builder(indexName, typeName, mapping).build();
JestResult result = jestClient.execute(putMapping);
if (!result.isSucceeded()) {
throw new ElasticWriterException(String.format("Failed to create mapping: %s", result.getErrorMessage()));
} else {
log.info("Created mapping for index {}", indexName);
}
}
}
}
use of io.searchbox.indices.CreateIndex in project opennms by OpenNMS.
the class EventToIndex method createIndex.
private static void createIndex(JestClient client, String name, String type) throws IOException {
// create new index
CreateIndex createIndex = new CreateIndex.Builder(name).build();
JestResult result = new OnmsJestResult(client.execute(createIndex));
if (LOG.isDebugEnabled()) {
LOG.debug("created new alarm index: {} type: {}" + "\n received search result: {}" + "\n response code: {}" + "\n error message: {}", name, type, result.getJsonString(), result.getResponseCode(), result.getErrorMessage());
}
}
Aggregations