Iterator<T> it = indexedCollection.retrieve(query).iterator();
while (it.hasNext()) {
it.next();
it.remove();
}
indexedCollection.delete(query);
For collections stored on-heap, the retrieval cost is low because only references are returned. And for collections stored off heap or on disk, each entire object needs to be retrieved anyway so its fields can be examined so it can be removed from all relevant indexes.
Your options are:
(1) fetch the objects matching a query and then call IndexedCollection.removeAll(objects)
(2) or to call remove(object) on-thefly for each one.
(3) or you can also do it in batches, where you fetch and then remove only a few at a time.
For IndexedCollections where you are using disk persistence, options 1 or 3 can have better performance, to minimise round trips to disk.