use of org.opensearch.index.reindex.BulkByScrollResponse 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.BulkByScrollResponse in project OpenSearch by opensearch-project.
the class ReindexIT method testReindex.
public void testReindex() throws IOException {
final String sourceIndex = "source1";
final String destinationIndex = "dest";
{
// Prepare
Settings settings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
createIndex(sourceIndex, settings);
createIndex(destinationIndex, settings);
BulkRequest bulkRequest = new BulkRequest().add(new IndexRequest(sourceIndex).id("1").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)).add(new IndexRequest(sourceIndex).id("2").source(Collections.singletonMap("foo2", "bar2"), XContentType.JSON)).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
assertEquals(RestStatus.OK, highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT).status());
}
{
// reindex one document with id 1 from source to destination
ReindexRequest reindexRequest = new ReindexRequest();
reindexRequest.setSourceIndices(sourceIndex);
reindexRequest.setDestIndex(destinationIndex);
reindexRequest.setSourceQuery(new IdsQueryBuilder().addIds("1"));
reindexRequest.setRefresh(true);
BulkByScrollResponse bulkResponse = execute(reindexRequest, highLevelClient()::reindex, highLevelClient()::reindexAsync);
assertEquals(1, bulkResponse.getCreated());
assertEquals(1, bulkResponse.getTotal());
assertEquals(0, bulkResponse.getDeleted());
assertEquals(0, bulkResponse.getNoops());
assertEquals(0, bulkResponse.getVersionConflicts());
assertEquals(1, bulkResponse.getBatches());
assertTrue(bulkResponse.getTook().getMillis() > 0);
assertEquals(1, bulkResponse.getBatches());
assertEquals(0, bulkResponse.getBulkFailures().size());
assertEquals(0, bulkResponse.getSearchFailures().size());
}
{
// set require_alias=true, but there exists no alias
ReindexRequest reindexRequest = new ReindexRequest();
reindexRequest.setSourceIndices(sourceIndex);
reindexRequest.setDestIndex(destinationIndex);
reindexRequest.setSourceQuery(new IdsQueryBuilder().addIds("1"));
reindexRequest.setRefresh(true);
reindexRequest.setRequireAlias(true);
OpenSearchStatusException exception = expectThrows(OpenSearchStatusException.class, () -> {
execute(reindexRequest, highLevelClient()::reindex, highLevelClient()::reindexAsync);
});
assertEquals(RestStatus.NOT_FOUND, exception.status());
assertEquals("OpenSearch exception [type=index_not_found_exception, reason=no such index [dest] and [require_alias] request flag is [true] and [dest] is not an alias]", exception.getMessage());
}
}
use of org.opensearch.index.reindex.BulkByScrollResponse in project OpenSearch by opensearch-project.
the class UpdateByQueryIT method testUpdateByQueryConflict.
public void testUpdateByQueryConflict() throws IOException {
final String index = "testupdatebyqueryconflict";
final Settings settings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
createIndex(index, settings);
final BulkRequest bulkRequest = new BulkRequest().add(new IndexRequest(index).id("1").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)).add(new IndexRequest(index).id("2").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
assertThat(highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT).status(), equalTo(RestStatus.OK));
putConflictPipeline();
final UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.indices(index);
updateByQueryRequest.setRefresh(true);
updateByQueryRequest.setPipeline(CONFLICT_PIPELINE_ID);
final BulkByScrollResponse response = highLevelClient().updateByQuery(updateByQueryRequest, RequestOptions.DEFAULT);
assertThat(response.getVersionConflicts(), equalTo(1L));
assertThat(response.getSearchFailures(), empty());
assertThat(response.getBulkFailures(), hasSize(1));
assertThat(response.getBulkFailures().stream().map(BulkItemResponse.Failure::getMessage).collect(Collectors.toSet()), everyItem(containsString("version conflict")));
assertThat(response.getTotal(), equalTo(2L));
assertThat(response.getCreated(), equalTo(0L));
assertThat(response.getUpdated(), equalTo(1L));
assertThat(response.getDeleted(), equalTo(0L));
assertThat(response.getNoops(), equalTo(0L));
assertThat(response.getBatches(), equalTo(1));
assertTrue(response.getTook().getMillis() > 0);
}
use of org.opensearch.index.reindex.BulkByScrollResponse 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.BulkByScrollResponse 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