Search in sources :

Example 26 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class ClientES7 method putTemplate.

@Override
public void putTemplate(String templateName, Map<String, Object> source) {
    final PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).source(source);
    client.execute((c, requestOptions) -> c.indices().putTemplate(request, requestOptions), "Unable to put template " + templateName);
}
Also used : PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)

Example 27 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class ClientES7 method resetIndexBlock.

@Override
public void resetIndexBlock(String index) {
    final UpdateSettingsRequest request = new UpdateSettingsRequest(index).settings(Collections.singletonMap("index.blocks.read_only_allow_delete", null));
    client.execute((c, requestOptions) -> c.indices().putSettings(request, requestOptions), "Unable to reset index block for " + index);
}
Also used : UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ClusterUpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Example 28 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method searchTypeWithoutStreamsDefaultsToQueriesStreams.

@Test
public void searchTypeWithoutStreamsDefaultsToQueriesStreams() throws IOException {
    final Query query = queryFor(Pivot.builder().id("pivot1").series(Collections.singletonList(Average.builder().field("field1").build())).rollup(true).build());
    final List<SearchRequest> request = run(query);
    assertThat(indicesOf(request).get(0)).isEqualTo("index1,index2");
}
Also used : SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) Query(org.graylog.plugins.views.search.Query) Test(org.junit.Test)

Example 29 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class ClusterAdapterES7 method clusterStats.

@Override
public ClusterStats clusterStats() {
    final Request request = new Request("GET", "/_cluster/stats/nodes/*");
    final JsonNode clusterStatsResponseJson = jsonApi.perform(request, "Couldn't read Elasticsearch cluster stats");
    final String clusterName = clusterStatsResponseJson.path("cluster_name").asText();
    String clusterVersion = null;
    if (clusterStatsResponseJson.path("nodes").path("versions").isArray()) {
        final ArrayNode versions = (ArrayNode) clusterStatsResponseJson.path("nodes").path("versions");
        // We just use the first version in the "versions" array. This is not correct if there are different
        // versions running in the cluster, but that is not recommended anyway.
        final JsonNode versionNode = versions.path(0);
        if (versionNode.getNodeType() != JsonNodeType.MISSING) {
            clusterVersion = versionNode.asText();
        }
    }
    final JsonNode countStats = clusterStatsResponseJson.path("nodes").path("count");
    final NodesStats nodesStats = NodesStats.create(countStats.path("total").asInt(-1), countStats.path("master_only").asInt(-1), countStats.path("data_only").asInt(-1), countStats.path("master_data").asInt(-1), countStats.path("client").asInt(-1));
    final JsonNode clusterIndicesStats = clusterStatsResponseJson.path("indices");
    final IndicesStats indicesStats = IndicesStats.create(clusterIndicesStats.path("count").asInt(-1), clusterIndicesStats.path("store").path("size_in_bytes").asLong(-1L), clusterIndicesStats.path("fielddata").path("memory_size_in_bytes").asLong(-1L));
    return ClusterStats.create(clusterName, clusterVersion, nodesStats, indicesStats);
}
Also used : NodesStats(org.graylog2.system.stats.elasticsearch.NodesStats) IndicesStats(org.graylog2.system.stats.elasticsearch.IndicesStats) ClusterGetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 30 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method create.

@Override
public void create(String index, IndexSettings indexSettings) {
    final Map<String, Object> settings = new HashMap<>();
    settings.put("number_of_shards", indexSettings.shards());
    settings.put("number_of_replicas", indexSettings.replicas());
    final CreateIndexRequest request = new CreateIndexRequest(index).settings(settings);
    client.execute((c, requestOptions) -> c.indices().create(request, requestOptions), "Unable to create index " + index);
}
Also used : HashMap(java.util.HashMap) CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)

Aggregations

Request (org.elasticsearch.client.Request)54 Response (org.elasticsearch.client.Response)34 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 IOException (java.io.IOException)12 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)12 HttpEntity (org.apache.http.HttpEntity)11 NStringEntity (org.apache.http.nio.entity.NStringEntity)11 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)7 Response (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 InputStream (java.io.InputStream)6 StringEntity (org.apache.http.entity.StringEntity)6 RestClient (org.elasticsearch.client.RestClient)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 Locale (java.util.Locale)5 ContentType (org.apache.http.entity.ContentType)5