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");
}
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");
}
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());
}
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));
}
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));
}
}
}
Aggregations