Search in sources :

Example 51 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project datashare by ICIJ.

the class ElasticsearchConfigurationTest method test_create_client_with_user_pass.

@Test
public void test_create_client_with_user_pass() throws Exception {
    RestHighLevelClient esClient = ElasticsearchConfiguration.createESClient(new PropertiesProvider(new HashMap<String, String>() {

        {
            put("elasticsearchAddress", "http://user:pass@elasticsearch:9200");
        }
    }));
    Response response = esClient.getLowLevelClient().performRequest(new Request("GET", TEST_INDEX));
    assertThat(EntityUtils.toString(response.getEntity())).contains("settings");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Response(org.elasticsearch.client.Response) HashMap(java.util.HashMap) Request(org.elasticsearch.client.Request) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Test(org.junit.Test)

Example 52 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project datashare by ICIJ.

the class ElasticsearchConfigurationTest method test_create_client_creates_mapping.

@Test
public void test_create_client_creates_mapping() throws Exception {
    ElasticsearchConfiguration.createESClient(new PropertiesProvider());
    Response response = es.client.getLowLevelClient().performRequest(new Request("GET", TEST_INDEX));
    assertThat(EntityUtils.toString(response.getEntity())).contains("mapping");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request) Test(org.junit.Test)

Example 53 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.

the class ElasticsearchOps method deleteByQuery.

/**
 * Delete documents using query API
 * @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html">Delete by query API</a>
 */
Single<WriteResult> deleteByQuery(ObjectNode query) {
    Objects.requireNonNull(query, "query");
    Request request = new Request("POST", String.format("/%s/_delete_by_query", index));
    request.addParameter("refresh", "true");
    request.setJsonEntity(query.toString());
    return transport.execute(request).map(x -> WriteResult.unknown());
}
Also used : Request(org.elasticsearch.client.Request)

Example 54 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.

the class ElasticsearchOps method count.

/**
 * Call {@code _count} endpoint to get count of documents matching a query.
 * @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html">search-count</a>
 */
Single<Json.Count> count(ObjectNode query) {
    final Request request = new Request("POST", String.format("/%s/_count", index));
    request.setJsonEntity(query.toString());
    return transport.execute(request).map(r -> convert(r, Json.Count.class));
}
Also used : Request(org.elasticsearch.client.Request)

Example 55 with Request

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.

the class ScrollingTest method assertNoActiveScrolls.

/**
 * Ensures there are no pending scroll contexts in elastic search cluster.
 * Queries {@code /_nodes/stats/indices/search} endpoint.
 * @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html">Indices Stats</a>
 */
// for errorprone
@SuppressWarnings("unused")
private void assertNoActiveScrolls() throws Exception {
    // get node stats
    final Response response = restClient.performRequest(new Request("GET", "/_nodes/stats/indices/search"));
    try (InputStream is = response.getEntity().getContent()) {
        final ObjectNode node = backend().objectMapper.readValue(is, ObjectNode.class);
        final String path = "/indices/search/scroll_current";
        final JsonNode scrollCurrent = node.with("nodes").elements().next().at(path);
        if (scrollCurrent.isMissingNode()) {
            throw new IllegalStateException("Couldn't find node at " + path);
        }
        final int activeScrolls = scrollCurrent.asInt();
        if (activeScrolls != 0) {
            throw new AssertionError(String.format("Expected no active scrolls but got %d. " + "Current index stats %s", activeScrolls, node));
        }
    }
}
Also used : Response(org.elasticsearch.client.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) Request(org.elasticsearch.client.Request) JsonNode(com.fasterxml.jackson.databind.JsonNode)

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