Search in sources :

Example 1 with DeleteByQueryRequest

use of org.elasticsearch.action.bulk.byscroll.DeleteByQueryRequest in project elasticsearch by elastic.

the class RestDeleteByQueryAction method buildRequest.

@Override
protected DeleteByQueryRequest buildRequest(RestRequest request) throws IOException {
    if (false == request.hasContent()) {
        throw new ElasticsearchException("_delete_by_query requires a request body");
    }
    /*
         * Passing the search request through DeleteByQueryRequest first allows
         * it to set its own defaults which differ from SearchRequest's
         * defaults. Then the parseInternalRequest can override them.
         */
    DeleteByQueryRequest internal = new DeleteByQueryRequest(new SearchRequest());
    Map<String, Consumer<Object>> consumers = new HashMap<>();
    consumers.put("conflicts", o -> internal.setConflicts((String) o));
    parseInternalRequest(internal, request, consumers);
    return internal;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Consumer(java.util.function.Consumer) HashMap(java.util.HashMap) DeleteByQueryRequest(org.elasticsearch.action.bulk.byscroll.DeleteByQueryRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 2 with DeleteByQueryRequest

use of org.elasticsearch.action.bulk.byscroll.DeleteByQueryRequest in project elasticsearch by elastic.

the class RoundTripTests method testDeleteByQueryRequest.

public void testDeleteByQueryRequest() throws IOException {
    DeleteByQueryRequest delete = new DeleteByQueryRequest(new SearchRequest());
    randomRequest(delete);
    DeleteByQueryRequest tripped = new DeleteByQueryRequest();
    roundTrip(delete, tripped);
    assertRequestEquals(delete, tripped);
    // Try slices with a version that doesn't support slices. That should fail.
    delete.setSlices(between(2, 1000));
    Exception e = expectThrows(IllegalArgumentException.class, () -> roundTrip(Version.V_5_0_0_rc1, delete, null));
    assertEquals("Attempting to send sliced reindex-style request to a node that doesn't support it. " + "Version is [5.0.0-rc1] but must be [5.1.1]", e.getMessage());
    // Try without slices with a version that doesn't support slices. That should work.
    tripped = new DeleteByQueryRequest();
    delete.setSlices(1);
    roundTrip(Version.V_5_0_0_rc1, delete, tripped);
    assertRequestEquals(delete, tripped);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) DeleteByQueryRequest(org.elasticsearch.action.bulk.byscroll.DeleteByQueryRequest) IOException(java.io.IOException)

Aggregations

DeleteByQueryRequest (org.elasticsearch.action.bulk.byscroll.DeleteByQueryRequest)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Consumer (java.util.function.Consumer)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1