use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class IndexOps method exists.
Single<Boolean> exists() {
final String uri = String.format(Locale.ROOT, "/%s/_mapping", index);
final Request request = new Request("GET", uri);
return transport.execute(request).map(x -> true).onErrorResumeNext(e -> Single.just(false));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class IndexOps method create.
/**
* Creates index in elastic search given a mapping. Mapping can contain nested fields expressed
* as dots({@code .}).
*
* <p>Example
* <pre>
* {@code
* b.a: long
* b.b: keyword
* }
* </pre>
*
* @param mapping field and field type mapping
* @throws IOException if there is an error
*/
Completable create(Map<String, String> mapping) {
Objects.requireNonNull(mapping, "mapping");
ObjectNode mappings = mapper.createObjectNode();
ObjectNode properties = mappings.with("mappings").with("properties");
for (Map.Entry<String, String> entry : mapping.entrySet()) {
applyMapping(properties, entry.getKey(), entry.getValue());
}
// create index and mapping
try {
final HttpEntity entity = new StringEntity(mapper.writeValueAsString(mappings), ContentType.APPLICATION_JSON);
final Request r = new Request("PUT", "/" + index);
r.setEntity(entity);
return transport.execute(r).ignoreElement();
} catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project immutables by immutables.
the class ElasticsearchOps method insertBulkInternal.
private Single<WriteResult> insertBulkInternal(List<ObjectNode> documents) throws JsonProcessingException {
Objects.requireNonNull(documents, "documents");
if (documents.isEmpty()) {
// nothing to process
return Single.just(WriteResult.empty());
}
final List<String> bulk = new ArrayList<>(documents.size() * 2);
for (ObjectNode doc : documents) {
final ObjectNode header = mapper.createObjectNode();
header.with("index").put("_index", index);
if (doc.has("_id")) {
// check if document has already an _id
header.with("index").set("_id", doc.get("_id"));
doc.remove("_id");
}
bulk.add(header.toString());
bulk.add(mapper().writeValueAsString(doc));
}
final StringEntity entity = new StringEntity(String.join("\n", bulk) + "\n", ContentType.APPLICATION_JSON);
final Request r = new Request("POST", "/_bulk?refresh");
r.setEntity(entity);
return transport.execute(r).map(x -> WriteResult.unknown());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class SearchRequestFactoryTest method searchIncludesTimerange.
@Test
void searchIncludesTimerange() {
final SearchSourceBuilder search = this.searchRequestFactory.create(ScrollCommand.builder().indices(Collections.singleton("graylog_0")).range(AbsoluteRange.create(DateTime.parse("2020-07-23T11:03:32.243Z"), DateTime.parse("2020-07-23T11:08:32.243Z"))).build());
assertJsonPath(search, request -> {
request.jsonPathAsListOf("$.query.bool.filter..range.timestamp.from", String.class).containsExactly("2020-07-23 11:03:32.243");
request.jsonPathAsListOf("$.query.bool.filter..range.timestamp.to", String.class).containsExactly("2020-07-23 11:08:32.243");
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request in project graylog2-server by Graylog2.
the class ClientES7 method templateExists.
@Override
public boolean templateExists(String templateName) {
final GetIndexTemplatesRequest request = new GetIndexTemplatesRequest("*");
final GetIndexTemplatesResponse result = client.execute((c, requestOptions) -> c.indices().getIndexTemplate(request, requestOptions));
return result.getIndexTemplates().stream().anyMatch(indexTemplate -> indexTemplate.name().equals(templateName));
}
Aggregations