use of io.searchbox.indices.mapping.PutMapping in project graylog2-server by Graylog2.
the class IndicesAdapterES6 method updateIndexMapping.
@Override
public void updateIndexMapping(@Nonnull String indexName, @Nonnull String mappingType, @Nonnull Map<String, Object> mapping) {
final PutMapping request = new PutMapping.Builder(indexName, mappingType, mapping).build();
final JestResult jestResult;
try {
jestResult = jestClient.execute(request);
} catch (IOException e) {
throw new ElasticsearchException("Couldn't update index mapping " + indexName + "/" + mappingType, e);
}
if (!jestResult.isSucceeded()) {
throw new ElasticsearchException(jestResult.getErrorMessage());
}
}
use of io.searchbox.indices.mapping.PutMapping 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();
JestResult result = jestClient.execute(createIndex);
if (!result.isSucceeded()) {
throw new ElasticWriterException(String.format("Failed to create index: %s", result.getErrorMessage()));
} else {
log.info("Created index {}", indexName);
}
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();
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.mapping.PutMapping in project xwiki-platform by xwiki.
the class DefaultPingSender method sendPing.
@Override
public void sendPing() throws Exception {
JestClient client = this.jestClientManager.getClient();
// Step 1: Create index (if already exists then it'll just be ignored)
client.execute(new CreateIndex.Builder(JestClientManager.INDEX).build());
// Step 2: Create a mapping so that we can search distribution versions containing hyphens (otherwise they
// are removed by the default tokenizer/analyzer). If mapping already exists then it'll just be ignored.
PutMapping putMapping = new PutMapping.Builder(JestClientManager.INDEX, JestClientManager.TYPE, constructJSONMapping()).build();
client.execute(putMapping);
// Step 3: Index the data
Index index = new Index.Builder(constructIndexJSON()).index(JestClientManager.INDEX).type(JestClientManager.TYPE).build();
JestResult result = client.execute(index);
if (!result.isSucceeded()) {
throw new Exception(result.getErrorMessage());
}
}
use of io.searchbox.indices.mapping.PutMapping in project herd by FINRAOS.
the class IndexFunctionsDaoImpl method createIndex.
/**
* The create index function will take as arguments the index name, document type, and mapping and will create a new index.
*/
@Override
public final void createIndex(String indexName, String documentType, String mapping, String settings, String alias) {
LOGGER.info("Creating Elasticsearch index, indexName={}, documentType={}.", indexName, documentType);
CreateIndex createIndex = new CreateIndex.Builder(indexName).settings(Settings.builder().loadFromSource(settings).build()).build();
PutMapping putMapping = new PutMapping.Builder(indexName, documentType, mapping).build();
ModifyAliases modifyAliases = new ModifyAliases.Builder(new AddAliasMapping.Builder(indexName, alias).build()).build();
JestResult jestResult = jestClientHelper.executeAction(createIndex);
LOGGER.info("Creating Elasticsearch index, indexName={}, documentType={} successful={}", indexName, documentType, jestResult.isSucceeded());
jestResult = jestClientHelper.executeAction(putMapping);
LOGGER.info("Creating Elasticsearch index put mappings, indexName={}, documentType={} successful={}", indexName, documentType, jestResult.isSucceeded());
jestResult = jestClientHelper.executeAction(modifyAliases);
LOGGER.info("Creating Elasticsearch index alias, indexName={}, alias={}", indexName, alias, jestResult.isSucceeded());
// If there are failures log them
if (!jestResult.isSucceeded()) {
LOGGER.error("Error in index creation= {}", jestResult.getErrorMessage());
}
}
use of io.searchbox.indices.mapping.PutMapping in project unipop by unipop-graph.
the class ElasticClient method validateIndex.
public void validateIndex(String indexName) {
try {
IndicesExists indicesExistsRequest = new IndicesExists.Builder(indexName).build();
logger.debug("created indexExistsRequests: {}", indicesExistsRequest);
JestResult existsResult = client.execute(indicesExistsRequest);
logger.debug("indexExistsRequests result: {}", existsResult);
if (!existsResult.isSucceeded()) {
Settings settings = Settings.builder().put("index.store.type", "mmapfs").build();
CreateIndex createIndexRequest = new CreateIndex.Builder(indexName).settings(settings).build();
execute(createIndexRequest);
// TODO: Make this work. Using the above "keyword" configuration in the meantime.
PutMapping putMapping = new PutMapping.Builder(indexName, "_default_", STRING_NOT_ANALYZED).build();
execute(putMapping);
logger.info("created index with settings: {}, indexName: {}, putMapping: {}", settings, indexName, putMapping);
}
} catch (IOException e) {
logger.error("failed to connect to elastic cluster", e);
}
}
Aggregations