tanjok
October 1, 2017, 12:04pm
1
Hi, is it possible to do something like this with RestHighLevelClient?
public void createMapping() {
Client client = transportClientFactory.getTransportClient();
CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(newIndexName);
createIndexRequestBuilder.setSource(getIndexSettingsMappings());
CreateIndexResponse createIndexResponse = createIndexRequestBuilder.execute().actionGet();
if (!createIndexResponse.isAcknowledged()) {
logger.error("Settings and mapping wasn't created for " + newIndexName);
}
}
Thank you in advance
dadoonet
(David Pilato)
October 1, 2017, 12:46pm
2
No. You need to use the Low Level one (which you can get from the HL Client). For example:
public void createIndex(String index, boolean ignoreErrors, String indexSettings) throws IOException {
logger.debug("create index [{}]", index);
logger.trace("index settings: [{}]", indexSettings);
try {
StringEntity entity = null;
if (!Strings.isNullOrEmpty(indexSettings)) {
entity = new StringEntity(indexSettings, ContentType.APPLICATION_JSON);
}
Response response = getLowLevelClient().performRequest("PUT", "/" + index, Collections.emptyMap(), entity);
logger.trace("create index response: {}", JsonUtil.asMap(response));
} catch (ResponseException e) {
if (e.getResponse().getStatusLine().getStatusCode() == 400 &&
(e.getMessage().contains("index_already_exists_exception") || // ES 5.x
e.getMessage().contains("resource_already_exists_exception") || // ES 6.x
e.getMessage().contains("IndexAlreadyExistsException") )) { // ES 1.x and 2.x
if (!ignoreErrors) {
throw new RuntimeException("index already exists");
}
logger.trace("index already exists. Ignoring error...");
return;
This file has been truncated. show original
1 Like
system
(system)
Closed
October 29, 2017, 12:46pm
3
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.