use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class ElasticsearchOps method closeScroll.
Completable closeScroll(Iterable<String> scrollIds) {
final ObjectNode payload = mapper.createObjectNode();
final ArrayNode array = payload.withArray("scroll_id");
scrollIds.forEach(array::add);
final Request request = new Request("DELETE", "/_search/scroll");
request.setJsonEntity(payload.toString());
return transport.execute(request).ignoreElement();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class ElasticsearchOps method insertDocument.
Single<WriteResult> insertDocument(ObjectNode document) throws IOException {
Objects.requireNonNull(document, "document");
String uri = String.format(Locale.ROOT, "/%s/_doc?refresh", index);
StringEntity entity = new StringEntity(mapper().writeValueAsString(document), ContentType.APPLICATION_JSON);
final Request r = new Request("POST", uri);
r.setEntity(entity);
return transport.execute(r).map(x -> WriteResult.unknown());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class ElasticsearchOps method searchRaw.
Single<Json.Result> searchRaw(ObjectNode query, Map<String, String> httpParams) {
final Request request = new Request("POST", String.format("/%s/_search", index));
httpParams.forEach(request::addParameter);
request.setJsonEntity(query.toString());
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Performing search {0} on {1}", new Object[] { query, request });
}
return transport.execute(request).map(r -> responseConverter().apply(r));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class IndexOps method version.
Single<Version> version() {
final Request request = new Request("GET", "/");
// version extract function
final Function<ObjectNode, Version> fn = node -> Version.of(node.get("version").get("number").asText());
return transport.execute(request).map(response -> mapper.readValue(response.getEntity().getContent(), ObjectNode.class)).map(fn::apply);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class IndexOps method mapping.
/**
* Return mapping for current index
*/
Single<Mapping> mapping() {
final String uri = String.format(Locale.ROOT, "/%s/_mapping", index);
final Request request = new Request("GET", uri);
return transport.execute(request).map(response -> mapper.readValue(response.getEntity().getContent(), ObjectNode.class)).map(root -> {
ObjectNode properties = (ObjectNode) root.elements().next().get("mappings");
if (properties == null) {
throw new IllegalStateException(String.format("No mappings found for index %s (after request %s)", index, request));
}
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
Json.visitMappingProperties(properties, builder::put);
return Mapping.ofElastic(builder.build());
});
}
Aggregations