use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConvertersTests method testRefresh.
public void testRefresh() {
String[] indices = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 5);
RefreshRequest refreshRequest;
if (OpenSearchTestCase.randomBoolean()) {
refreshRequest = new RefreshRequest(indices);
} else {
refreshRequest = new RefreshRequest();
refreshRequest.indices(indices);
}
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomIndicesOptions(refreshRequest::indicesOptions, refreshRequest::indicesOptions, expectedParams);
Request request = IndicesRequestConverters.refresh(refreshRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
if (indices != null && indices.length > 0) {
endpoint.add(String.join(",", indices));
}
endpoint.add("_refresh");
Assert.assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
Assert.assertThat(request.getParameters(), equalTo(expectedParams));
Assert.assertThat(request.getEntity(), nullValue());
Assert.assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
}
use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.
the class CCSDuelIT method indexDocuments.
private static void indexDocuments(String idPrefix) throws IOException, InterruptedException {
// this index with a single document is used to test partial failures
IndexRequest indexRequest = new IndexRequest(INDEX_NAME + "_err");
indexRequest.id("id");
indexRequest.source("id", "id", "creationDate", "err");
indexRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
assertEquals(201, indexResponse.status().getStatus());
CreateIndexRequest createEmptyIndexRequest = new CreateIndexRequest(INDEX_NAME + "_empty");
CreateIndexResponse response = restHighLevelClient.indices().create(createEmptyIndexRequest, RequestOptions.DEFAULT);
assertTrue(response.isAcknowledged());
int numShards = randomIntBetween(1, 5);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(INDEX_NAME);
createIndexRequest.settings(Settings.builder().put("index.number_of_shards", numShards).put("index.number_of_replicas", 0));
createIndexRequest.mapping("{\"properties\":{" + "\"id\":{\"type\":\"keyword\"}," + "\"suggest\":{\"type\":\"completion\"}," + "\"join\":{\"type\":\"join\", \"relations\": {\"question\":\"answer\"}}}}", XContentType.JSON);
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
BulkProcessor bulkProcessor = BulkProcessor.builder((r, l) -> restHighLevelClient.bulkAsync(r, RequestOptions.DEFAULT, l), new BulkProcessor.Listener() {
@Override
public void beforeBulk(long executionId, BulkRequest request) {
}
@Override
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
assertFalse(response.hasFailures());
}
@Override
public void afterBulk(long executionId, BulkRequest request, Throwable failure) {
throw new AssertionError("Failed to execute bulk", failure);
}
}).build();
int numQuestions = randomIntBetween(50, 100);
for (int i = 0; i < numQuestions; i++) {
bulkProcessor.add(buildIndexRequest(idPrefix + i, "question", null));
}
int numAnswers = randomIntBetween(100, 150);
for (int i = 0; i < numAnswers; i++) {
bulkProcessor.add(buildIndexRequest(idPrefix + (i + 1000), "answer", idPrefix + randomIntBetween(0, numQuestions - 1)));
}
assertTrue(bulkProcessor.awaitClose(30, TimeUnit.SECONDS));
RefreshResponse refreshResponse = restHighLevelClient.indices().refresh(new RefreshRequest(INDEX_NAME), RequestOptions.DEFAULT);
assertEquals(0, refreshResponse.getFailedShards());
assertEquals(numShards, refreshResponse.getSuccessfulShards());
}
use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.
the class AbstractAsyncBulkByScrollAction method refreshAndFinish.
/**
* Start terminating a request that finished non-catastrophically by refreshing the modified indices and then proceeding to
* {@link #finishHim(Exception, List, List, boolean)}.
*/
void refreshAndFinish(List<Failure> indexingFailures, List<SearchFailure> searchFailures, boolean timedOut) {
if (task.isCancelled() || false == mainRequest.isRefresh() || destinationIndices.isEmpty()) {
finishHim(null, indexingFailures, searchFailures, timedOut);
return;
}
RefreshRequest refresh = new RefreshRequest();
refresh.indices(destinationIndices.toArray(new String[destinationIndices.size()]));
logger.debug("[{}]: refreshing", task.getId());
client.admin().indices().refresh(refresh, new ActionListener<RefreshResponse>() {
@Override
public void onResponse(RefreshResponse response) {
finishHim(null, indexingFailures, searchFailures, timedOut);
}
@Override
public void onFailure(Exception e) {
finishHim(e);
}
});
}
use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.
the class RestRefreshAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));
refreshRequest.indicesOptions(IndicesOptions.fromRequest(request, refreshRequest.indicesOptions()));
return channel -> client.admin().indices().refresh(refreshRequest, new RestToXContentListener<RefreshResponse>(channel) {
@Override
protected RestStatus getStatus(RefreshResponse response) {
return response.getStatus();
}
});
}
use of org.opensearch.action.admin.indices.refresh.RefreshRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method refresh.
static Request refresh(RefreshRequest refreshRequest) {
String[] indices = refreshRequest.indices() == null ? Strings.EMPTY_ARRAY : refreshRequest.indices();
Request request = new Request(HttpPost.METHOD_NAME, RequestConverters.endpoint(indices, "_refresh"));
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withIndicesOptions(refreshRequest.indicesOptions());
request.addParameters(parameters.asMap());
return request;
}
Aggregations