use of org.elasticsearch.client.Request in project beam by apache.
the class ElasticsearchIOTestUtils method flushAndRefreshAllIndices.
static void flushAndRefreshAllIndices(RestClient restClient) throws IOException {
Request request = new Request("POST", "/_flush");
restClient.performRequest(request);
request = new Request("POST", "/_refresh");
restClient.performRequest(request);
}
use of org.elasticsearch.client.Request in project beam by apache.
the class ElasticsearchIOTestUtils method closeIndex.
private static void closeIndex(RestClient restClient, String index) throws IOException {
Request request = new Request("POST", String.format("/%s/_close", index));
restClient.performRequest(request);
}
use of org.elasticsearch.client.Request in project beam by apache.
the class ElasticsearchIOTestUtils method createIndex.
public static void createIndex(RestClient restClient, String indexName) throws IOException {
deleteIndex(restClient, indexName);
Request request = new Request("PUT", String.format("/%s", indexName));
restClient.performRequest(request);
}
use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method createIndex.
@Override
public void createIndex(String indexName, Map<String, Object> settings) throws IOException {
Request request = new Request(REQUEST_TYPE_PUT, REQUEST_SEPARATOR + indexName);
if (majorVersion.getValue() > 6) {
if (useMappingTypes) {
request.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
}
if (settings != null && settings.size() > 0) {
Map<String, Object> updatedSettings = new HashMap<>();
updatedSettings.put("settings", settings);
settings = updatedSettings;
}
}
performRequest(request, mapWriter.writeValueAsBytes(settings));
}
use of org.elasticsearch.client.Request in project janusgraph by JanusGraph.
the class RestElasticSearchClient method bulkRequest.
@Override
public void bulkRequest(List<ElasticSearchMutation> requests, String ingestPipeline) throws IOException {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
for (final ElasticSearchMutation request : requests) {
Map<String, Object> requestData = new HashMap<>();
if (useMappingTypes) {
requestData.put("_index", request.getIndex());
requestData.put("_type", request.getType());
requestData.put("_id", request.getId());
} else {
requestData.put("_index", request.getIndex());
requestData.put("_id", request.getId());
}
if (retryOnConflict != null && request.getRequestType() == ElasticSearchMutation.RequestType.UPDATE) {
requestData.put(retryOnConflictKey, retryOnConflict);
}
outputStream.write(mapWriter.writeValueAsBytes(ImmutableMap.of(request.getRequestType().name().toLowerCase(), requestData)));
outputStream.write(NEW_LINE_BYTES);
if (request.getSource() != null) {
outputStream.write(mapWriter.writeValueAsBytes(request.getSource()));
outputStream.write(NEW_LINE_BYTES);
}
}
final StringBuilder builder = new StringBuilder();
if (ingestPipeline != null) {
APPEND_OP.apply(builder).append("pipeline=").append(ingestPipeline);
}
if (bulkRefreshEnabled) {
APPEND_OP.apply(builder).append("refresh=").append(bulkRefresh);
}
builder.insert(0, REQUEST_SEPARATOR + "_bulk");
final Response response = performRequest(REQUEST_TYPE_POST, builder.toString(), outputStream.toByteArray());
try (final InputStream inputStream = response.getEntity().getContent()) {
final RestBulkResponse bulkResponse = mapper.readValue(inputStream, RestBulkResponse.class);
final List<Object> errors = bulkResponse.getItems().stream().flatMap(item -> item.values().stream()).filter(item -> item.getError() != null && item.getStatus() != 404).map(RestBulkItemResponse::getError).collect(Collectors.toList());
if (!errors.isEmpty()) {
errors.forEach(error -> log.error("Failed to execute ES query: {}", error));
throw new IOException("Failure(s) in Elasticsearch bulk request: " + errors);
}
}
}
Aggregations