All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.client.internal.ElasticsearchClient;

public class DeleteByQueryRequestBuilder extends AbstractBulkByScrollRequestBuilder {

    private Boolean abortOnVersionConflict;

    public DeleteByQueryRequestBuilder(ElasticsearchClient client) {
        this(client, new SearchRequestBuilder(client));
    }

    private DeleteByQueryRequestBuilder(ElasticsearchClient client, SearchRequestBuilder search) {
        super(client, DeleteByQueryAction.INSTANCE, search);
        source().setFetchSource(false);
    }

    @Override
    protected DeleteByQueryRequestBuilder self() {
        return this;
    }

    @Override
    public DeleteByQueryRequestBuilder abortOnVersionConflict(boolean abortOnVersionConflict) {
        this.abortOnVersionConflict = abortOnVersionConflict;
        return this;
    }

    @Override
    public DeleteByQueryRequest request() {
        SearchRequest search = source().request();
        try {
            DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(search, false);
            try {
                apply(deleteByQueryRequest);
                return deleteByQueryRequest;
            } catch (Exception e) {
                deleteByQueryRequest.decRef();
                throw e;
            }
        } catch (Exception e) {
            search.decRef();
            throw e;
        }
    }

    @Override
    public void apply(DeleteByQueryRequest request) {
        super.apply(request);
        if (abortOnVersionConflict != null) {
            request.setAbortOnVersionConflict(abortOnVersionConflict);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy