use of org.elasticsearch.action.support.master.AcknowledgedResponse in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method ensureIndexTemplate.
@Override
public boolean ensureIndexTemplate(String templateName, Map<String, Object> template) {
final PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).source(template);
final AcknowledgedResponse result = client.execute((c, requestOptions) -> c.indices().putTemplate(request, requestOptions), "Unable to create index template " + templateName);
return result.isAcknowledged();
}
use of org.elasticsearch.action.support.master.AcknowledgedResponse in project snow-owl by b2ihealthcare.
the class EsIndexAdmin method delete.
@Override
public void delete() {
if (exists()) {
final DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(name + "*");
try {
final AcknowledgedResponse deleteIndexResponse = client().indices().delete(deleteIndexRequest);
checkState(deleteIndexResponse.isAcknowledged(), "Failed to delete all ES indices for '%s'.", name);
} catch (Exception e) {
throw new IndexException(String.format("Failed to delete all ES indices for '%s'.", name), e);
}
}
}
use of org.elasticsearch.action.support.master.AcknowledgedResponse in project snow-owl by b2ihealthcare.
the class EsIndexAdmin method updateSettings.
@Override
public void updateSettings(Map<String, Object> newSettings) {
if (CompareUtils.isEmpty(newSettings)) {
return;
}
// ignore local and/or dynamic settings
final Set<String> unsupportedDynamicSettings = Sets.difference(Sets.difference(newSettings.keySet(), DYNAMIC_SETTINGS), LOCAL_SETTINGS);
if (!unsupportedDynamicSettings.isEmpty()) {
throw new IndexException(String.format("Settings [%s] are not dynamically updateable settings.", unsupportedDynamicSettings), null);
}
boolean shouldUpdate = false;
for (String settingKey : newSettings.keySet()) {
Object currentValue = settings.get(settingKey);
Object newValue = newSettings.get(settingKey);
if (!Objects.equals(currentValue, newValue)) {
shouldUpdate = true;
}
}
if (!shouldUpdate) {
return;
}
Map<String, Object> esSettings = new HashMap<>(newSettings);
// remove any local settings from esSettings
esSettings.keySet().removeAll(LOCAL_SETTINGS);
for (DocumentMapping mapping : mappings.getMappings()) {
final String index = getTypeIndex(mapping);
// if any index exists, then update the settings based on the new settings
if (exists(mapping)) {
try {
log.info("Applying settings '{}' changes in index {}...", esSettings, index);
AcknowledgedResponse response = client.indices().updateSettings(new UpdateSettingsRequest().indices(index).settings(esSettings));
checkState(response.isAcknowledged(), "Failed to update index settings '%s'.", index);
} catch (IOException e) {
throw new IndexException(String.format("Couldn't update settings of index '%s'", index), e);
}
}
}
// update both local and es settings
settings.putAll(newSettings);
}
use of org.elasticsearch.action.support.master.AcknowledgedResponse in project sonarqube by SonarSource.
the class EsTester method setIndexSettings.
private void setIndexSettings(String index, Map<String, Object> settings) {
AcknowledgedResponse response = null;
try {
response = ES_REST_CLIENT.nativeClient().indices().putSettings(new UpdateSettingsRequest(index).settings(settings), RequestOptions.DEFAULT);
} catch (IOException e) {
throw new IllegalStateException("Could not update index settings", e);
}
checkState(response.isAcknowledged());
}
use of org.elasticsearch.action.support.master.AcknowledgedResponse in project sonarqube by SonarSource.
the class EsTester method deleteIndexIfExists.
private static void deleteIndexIfExists(String name) {
try {
AcknowledgedResponse response = ES_REST_CLIENT.nativeClient().indices().delete(new DeleteIndexRequest(name), RequestOptions.DEFAULT);
checkState(response.isAcknowledged(), "Fail to drop the index " + name);
} catch (ElasticsearchStatusException e) {
if (e.status().getStatus() == 404) {
// ignore, index not found
} else {
throw e;
}
} catch (IOException e) {
throw new IllegalStateException("Could not delete index", e);
}
}
Aggregations