Search in sources :

Example 1 with AcknowledgedResponse

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());
}
Also used : PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with AcknowledgedResponse

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);
        }
    }
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) IOException(java.io.IOException)

Example 3 with AcknowledgedResponse

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);
}
Also used : Maps.newHashMap(com.google.common.collect.Maps.newHashMap) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) IOException(java.io.IOException) DocumentMapping(com.b2international.index.mapping.DocumentMapping)

Example 4 with AcknowledgedResponse

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());
}
Also used : UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) IOException(java.io.IOException)

Example 5 with AcknowledgedResponse

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;
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Arrays(java.util.Arrays) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Level(org.apache.logging.log4j.Level) LogEvent(org.apache.logging.log4j.core.LogEvent) Duration(java.time.Duration) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) RequestOptions(org.elasticsearch.client.RequestOptions) Assertions(org.assertj.core.api.Assertions) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SearchHit(org.elasticsearch.search.SearchHit) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ThreadLocalRecyclerFactory(org.apache.logging.log4j.layout.template.json.util.ThreadLocalRecyclerFactory) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) GelfLayout(org.apache.logging.log4j.core.layout.GelfLayout) RestStatus(org.elasticsearch.rest.RestStatus) Layout(org.apache.logging.log4j.core.Layout) Awaitility(org.awaitility.Awaitility) RestClient(org.elasticsearch.client.RestClient) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Appender(org.apache.logging.log4j.core.Appender) SearchRequest(org.elasticsearch.action.search.SearchRequest) Function(java.util.function.Function) EventTemplateAdditionalField(org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.EventTemplateAdditionalField) NetUtils(org.apache.logging.log4j.core.util.NetUtils) Charset(java.nio.charset.Charset) SocketAppender(org.apache.logging.log4j.core.appender.SocketAppender) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) PrintStream(java.io.PrintStream) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) EcsLayout(co.elastic.logging.log4j2.EcsLayout) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) StatusLogger(org.apache.logging.log4j.status.StatusLogger) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) Execution(org.junit.jupiter.api.parallel.Execution) HttpHost(org.apache.http.HttpHost) Collections(java.util.Collections) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) HttpHost(org.apache.http.HttpHost) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException)

Aggregations

AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)37 IOException (java.io.IOException)11 FutureActionListener (io.crate.action.FutureActionListener)9 ClusterState (org.elasticsearch.cluster.ClusterState)7 Row1 (io.crate.data.Row1)6 Map (java.util.Map)6 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)6 Metadata (org.elasticsearch.cluster.metadata.Metadata)6 Row (io.crate.data.Row)5 RelationName (io.crate.metadata.RelationName)5 Arrays (java.util.Arrays)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Reference (io.crate.metadata.Reference)4 DataType (io.crate.types.DataType)4 ArrayList (java.util.ArrayList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 StreamSupport (java.util.stream.StreamSupport)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4