use of org.opensearch.index.reindex.DeleteByQueryRequest in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method unindexEntity.
@Override
public void unindexEntity(final String href) throws CalFacadeException {
try {
final DeleteByQueryRequest dqr = new DeleteByQueryRequest(targetIndex);
final QueryBuilder qb = getFilters(null).singleEntityQuery(href, PropertyInfoIndex.HREF);
dqr.setConflicts("proceed");
dqr.setRefresh(true);
dqr.setQuery(qb);
BulkByScrollResponse bulkResponse = getClient().deleteByQuery(dqr, RequestOptions.DEFAULT);
markUpdated();
// TODO check response?
} catch (final OpenSearchException ese) {
// Failed somehow
error(ese);
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
error(t);
throw new CalFacadeException(t);
} finally {
lastIndexTime = System.currentTimeMillis();
}
}
use of org.opensearch.index.reindex.DeleteByQueryRequest in project OpenSearch by opensearch-project.
the class RequestConverters method prepareDeleteByQueryRequest.
private static Request prepareDeleteByQueryRequest(DeleteByQueryRequest deleteByQueryRequest, boolean waitForCompletion) throws IOException {
String endpoint = endpoint(deleteByQueryRequest.indices(), "_delete_by_query");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
Params params = new Params().withRouting(deleteByQueryRequest.getRouting()).withRefresh(deleteByQueryRequest.isRefresh()).withTimeout(deleteByQueryRequest.getTimeout()).withWaitForActiveShards(deleteByQueryRequest.getWaitForActiveShards()).withRequestsPerSecond(deleteByQueryRequest.getRequestsPerSecond()).withIndicesOptions(deleteByQueryRequest.indicesOptions()).withWaitForCompletion(waitForCompletion).withSlices(deleteByQueryRequest.getSlices());
if (deleteByQueryRequest.isAbortOnVersionConflict() == false) {
params.putParam("conflicts", "proceed");
}
if (deleteByQueryRequest.getBatchSize() != AbstractBulkByScrollRequest.DEFAULT_SCROLL_SIZE) {
params.putParam("scroll_size", Integer.toString(deleteByQueryRequest.getBatchSize()));
}
if (deleteByQueryRequest.getScrollTime() != AbstractBulkByScrollRequest.DEFAULT_SCROLL_TIMEOUT) {
params.putParam("scroll", deleteByQueryRequest.getScrollTime());
}
if (deleteByQueryRequest.getMaxDocs() > 0) {
params.putParam("max_docs", Integer.toString(deleteByQueryRequest.getMaxDocs()));
}
request.addParameters(params.asMap());
request.setEntity(createEntity(deleteByQueryRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}
use of org.opensearch.index.reindex.DeleteByQueryRequest in project OpenSearch by opensearch-project.
the class RequestConvertersTests method testDeleteByQuery.
public void testDeleteByQuery() throws IOException {
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest();
deleteByQueryRequest.indices(randomIndicesNames(1, 5));
Map<String, String> expectedParams = new HashMap<>();
if (randomBoolean()) {
int batchSize = randomInt(100);
deleteByQueryRequest.setBatchSize(batchSize);
expectedParams.put("scroll_size", Integer.toString(batchSize));
}
if (randomBoolean()) {
deleteByQueryRequest.setRouting("=cat");
expectedParams.put("routing", "=cat");
}
if (randomBoolean()) {
int size = randomIntBetween(100, 1000);
if (randomBoolean()) {
deleteByQueryRequest.setMaxDocs(size);
} else {
deleteByQueryRequest.setSize(size);
}
expectedParams.put("max_docs", Integer.toString(size));
}
if (randomBoolean()) {
deleteByQueryRequest.setAbortOnVersionConflict(false);
expectedParams.put("conflicts", "proceed");
}
if (randomBoolean()) {
String ts = randomTimeValue();
deleteByQueryRequest.setScroll(TimeValue.parseTimeValue(ts, "scroll"));
expectedParams.put("scroll", ts);
}
if (randomBoolean()) {
deleteByQueryRequest.setQuery(new TermQueryBuilder("foo", "fooval"));
}
if (randomBoolean()) {
float requestsPerSecond = (float) randomDoubleBetween(0.0, 10.0, false);
expectedParams.put("requests_per_second", Float.toString(requestsPerSecond));
deleteByQueryRequest.setRequestsPerSecond(requestsPerSecond);
} else {
expectedParams.put("requests_per_second", "-1");
}
if (randomBoolean()) {
int slices = randomIntBetween(0, 4);
if (slices == 0) {
expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
} else {
expectedParams.put("slices", Integer.toString(slices));
}
deleteByQueryRequest.setSlices(slices);
} else {
expectedParams.put("slices", "1");
}
setRandomIndicesOptions(deleteByQueryRequest::setIndicesOptions, deleteByQueryRequest::indicesOptions, expectedParams);
setRandomTimeout(deleteByQueryRequest::setTimeout, ReplicationRequest.DEFAULT_TIMEOUT, expectedParams);
expectedParams.put("wait_for_completion", Boolean.TRUE.toString());
Request request = RequestConverters.deleteByQuery(deleteByQueryRequest);
StringJoiner joiner = new StringJoiner("/", "/", "");
joiner.add(String.join(",", deleteByQueryRequest.indices()));
joiner.add("_delete_by_query");
assertEquals(joiner.toString(), request.getEndpoint());
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
assertEquals(expectedParams, request.getParameters());
assertToXContentBody(deleteByQueryRequest, request.getEntity());
}
use of org.opensearch.index.reindex.DeleteByQueryRequest in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method unindexTombstoned.
@Override
public void unindexTombstoned(final String docType, final String href) throws CalFacadeException {
try {
final DeleteByQueryRequest dqr = new DeleteByQueryRequest(targetIndex);
dqr.setConflicts("proceed");
dqr.setRefresh(true);
final QueryBuilder fb = getFilters(null).singleTombstonedEntityQuery(href, PropertyInfoIndex.HREF);
dqr.setQuery(fb);
final BulkByScrollResponse bulkResponse = getClient().deleteByQuery(dqr, RequestOptions.DEFAULT);
markUpdated();
// TODO check response?
} catch (final OpenSearchException ese) {
// Failed somehow
error(ese);
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
error(t);
throw new CalFacadeException(t);
} finally {
lastIndexTime = System.currentTimeMillis();
}
}
use of org.opensearch.index.reindex.DeleteByQueryRequest in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method deleteEvent.
private boolean deleteEvent(final EventInfo ei) throws CalFacadeException {
final DeleteByQueryRequest delQreq = new DeleteByQueryRequest(targetIndex);
final var path = ei.getEvent().getColPath();
final var uid = ei.getEvent().getUid();
final ESQueryFilter esq = getFilters(null);
final QueryBuilder qb = getFilters(null).allInstances(path, uid);
delQreq.setConflicts("proceed");
delQreq.setRefresh(true);
delQreq.setQuery(qb);
boolean ok = true;
try {
final BulkByScrollResponse bulkResponse = getClient().deleteByQuery(delQreq, RequestOptions.DEFAULT);
for (final BulkItemResponse.Failure f : bulkResponse.getBulkFailures()) {
warn(format("Failing shards for delete - " + "path: %s, uid: %s, index: %s", path, uid, f.getIndex()));
ok = false;
}
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
return ok;
}
Aggregations