use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse in project pancm_project by xuwujing.
the class EsScriptSearchTest method putApi.
private static void putApi() throws IOException {
PutStoredScriptRequest request = new PutStoredScriptRequest();
request.id("calculate-score");
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
{
builder.startObject("script");
{
builder.field("lang", "mustache");
builder.field("source", "{\"query\":{\"match\":{\"title\":\"{{query_string}}\"}}}");
}
builder.endObject();
}
builder.endObject();
request.content(BytesReference.bytes(builder), XContentType.JSON);
AcknowledgedResponse putStoredScriptResponse = client.putScript(request, RequestOptions.DEFAULT);
System.out.println("==" + putStoredScriptResponse.isAcknowledged());
System.out.println("==" + putStoredScriptResponse.isFragment());
}
use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse in project logging-log4j2 by apache.
the class LogstashIT method createClient.
private static RestHighLevelClient createClient() throws IOException {
// Instantiate the client.
LOGGER.info("instantiating the ES client");
final HttpHost httpHost = new HttpHost(HOST_NAME, MavenHardcodedConstants.ES_PORT);
final RestClientBuilder clientBuilder = RestClient.builder(httpHost);
final RestHighLevelClient client = new RestHighLevelClient(clientBuilder);
// Verify the connection.
LOGGER.info("verifying the ES connection");
final ClusterHealthResponse healthResponse = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT);
Assertions.assertThat(healthResponse.getStatus()).isNotEqualTo(ClusterHealthStatus.RED);
// Delete the index.
LOGGER.info("deleting the ES index");
final DeleteIndexRequest deleteRequest = new DeleteIndexRequest(MavenHardcodedConstants.ES_INDEX_NAME);
try {
final AcknowledgedResponse deleteResponse = client.indices().delete(deleteRequest, RequestOptions.DEFAULT);
Assertions.assertThat(deleteResponse.isAcknowledged()).isTrue();
} catch (ElasticsearchStatusException error) {
Assertions.assertThat(error).satisfies(ignored -> Assertions.assertThat(error.status()).isEqualTo(RestStatus.NOT_FOUND));
}
return client;
}
Aggregations