Allow to delete a set of documents by specifying the targeted indexes (or mapped types in the POJO mapper) and a predicate.
For now, we're not entirely sure we can implement this feature reliably for the Lucene backend, so let's implement it as an extension, for the Elasticsearch backend only.
API we agreed on during the August 2018 face-to-face meeting:
{code} // Allow users to write this PojoTarget<?> target = searchManager.target( MyType.class, MyOtherType.class ); SearchPredicate searchPredicate = target.predicate(). … ; CompletableFuture<?> future = target.withExtension( ElasticsearchExtension.get() ) .executeDeleteByQuery( searchPredicate );
// Or this PojoTarget<?> target = searchManager.target( MyType.class, MyOtherType.class ); SearchPredicate searchPredicate = target.predicate(). … ; CompletableFuture<?> future = target.withExtension( ElasticsearchExtension.get() ) .executeDeleteByQuery( searchPredicate, c -> { … set options… });
// Or this PojoTarget<?> target = searchManager.target( MyType.class, MyOtherType.class ); CompletableFuture<?> future = target.withExtension( ElasticsearchExtension.get() ) .executeDeleteByQuery( c -> { c.match(). … } , c -> { … set options… });
// NOT THIS (we don’t really want to represent options as objects) PojoTarget<?> target = searchManager.target( MyType.class, MyOtherType.class ); SearchPredicate searchPredicate = target.predicate(). … ; DeleteByQueryOptions options = target.deleteByQueryOptions(). … ; target.withExtension( ElasticsearchExtension.get() ) .executeDeleteByQuery( searchPredicate, options ); {code}
Note that we pass options See what was done in a way that is slightly different from the predicate DSL, HSEARCH-3049 for example. That's mainly so that the call to {{executeDeleteByQuery(...)}} executes the query directly; if we offered an API such as {{deleteByQuery().setSomeOption()....execute()}}, users could forget the call to execute and would end up not noticing that the query wasn't executed. Another option, maybe, would be to expose something like {{prepareDeleteByQuery().setSomeOption()....execute()}}?
Note that this new API will serve as an example for all future "write" APIs :
* that allow to create works on a given entity, a whole indexed type, or even a set of indexed types * and/or that are specific to one technology in particular (Lucene, Elasticsearch, …) .
Among these future APIs:
* For Elasticsearch, the ability to execute native requests (more or less provide a path template along with a JSON string representing the payload) could be very useful. * Per-index flush calls * Per-index optimize calls |
|