Search in sources :

Example 6 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class BulkRequestTests method testBulkNoSource.

// issue 15120
public void testBulkNoSource() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(new UpdateRequest("index", "type", "id"));
    bulkRequest.add(new IndexRequest("index", "type", "id"));
    ActionRequestValidationException validate = bulkRequest.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.validationErrors(), not(empty()));
    assertThat(validate.validationErrors(), contains("script or doc is missing", "source is missing", "content type is missing"));
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 7 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class IndexRequest method validate.

@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = super.validate();
    if (type == null) {
        validationException = addValidationError("type is missing", validationException);
    }
    if (source == null) {
        validationException = addValidationError("source is missing", validationException);
    }
    if (contentType == null) {
        validationException = addValidationError("content type is missing", validationException);
    }
    final long resolvedVersion = resolveVersionDefaults();
    if (opType() == OpType.CREATE) {
        if (versionType != VersionType.INTERNAL) {
            validationException = addValidationError("create operations only support internal versioning. use index instead", validationException);
            return validationException;
        }
        if (resolvedVersion != Versions.MATCH_DELETED) {
            validationException = addValidationError("create operations do not support explicit versions. use index instead", validationException);
            return validationException;
        }
    }
    if (opType() != OpType.INDEX && id == null) {
        addValidationError("an id is required for a " + opType() + " operation", validationException);
    }
    if (!versionType.validateVersionForWrites(resolvedVersion)) {
        validationException = addValidationError("illegal version value [" + resolvedVersion + "] for version type [" + versionType.name() + "]", validationException);
    }
    if (versionType == VersionType.FORCE) {
        validationException = addValidationError("version type [force] may no longer be used", validationException);
    }
    if (id != null && id.getBytes(StandardCharsets.UTF_8).length > 512) {
        validationException = addValidationError("id is too long, must be no longer than 512 bytes but was: " + id.getBytes(StandardCharsets.UTF_8).length, validationException);
    }
    if (id == null && (versionType == VersionType.INTERNAL && resolvedVersion == Versions.MATCH_ANY) == false) {
        validationException = addValidationError("an id must be provided if version type or value are set", validationException);
    }
    return validationException;
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException)

Example 8 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class MultiTermVectorsRequest method validate.

@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = null;
    if (requests.isEmpty()) {
        validationException = ValidateActions.addValidationError("multi term vectors: no documents requested", validationException);
    } else {
        for (int i = 0; i < requests.size(); i++) {
            TermVectorsRequest termVectorsRequest = requests.get(i);
            ActionRequestValidationException validationExceptionForDoc = termVectorsRequest.validate();
            if (validationExceptionForDoc != null) {
                validationException = ValidateActions.addValidationError("at multi term vectors for doc " + i, validationExceptionForDoc);
            }
        }
    }
    return validationException;
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException)

Example 9 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class TransportAction method execute.

/**
     * Use this method when the transport action should continue to run in the context of the current task
     */
public final void execute(Task task, Request request, ActionListener<Response> listener) {
    ActionRequestValidationException validationException = request.validate();
    if (validationException != null) {
        listener.onFailure(validationException);
        return;
    }
    if (task != null && request.getShouldStoreResult()) {
        listener = new TaskResultStoringActionListener<>(taskManager, task, listener);
    }
    RequestFilterChain<Request, Response> requestFilterChain = new RequestFilterChain<>(this, logger);
    requestFilterChain.proceed(task, actionName, request, listener);
}
Also used : ActionResponse(org.elasticsearch.action.ActionResponse) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) ActionRequest(org.elasticsearch.action.ActionRequest)

Example 10 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class RestGetSourceAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime()));
    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));
    return channel -> {
        if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) {
            final ActionRequestValidationException validationError = new ActionRequestValidationException();
            validationError.addValidationError("fetching source can not be disabled");
            channel.sendResponse(new BytesRestResponse(channel, validationError));
        } else {
            client.get(getRequest, new RestResponseListener<GetResponse>(channel) {

                @Override
                public RestResponse buildResponse(final GetResponse response) throws Exception {
                    final XContentBuilder builder = channel.newBuilder(request.getXContentType(), false);
                    if (response.isSourceEmpty()) {
                        return new BytesRestResponse(NOT_FOUND, builder);
                    } else {
                        builder.rawValue(response.getSourceInternal());
                        return new BytesRestResponse(OK, builder);
                    }
                }
            });
        }
    };
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequest(org.elasticsearch.action.get.GetRequest) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) IOException(java.io.IOException) NOT_FOUND(org.elasticsearch.rest.RestStatus.NOT_FOUND) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) HEAD(org.elasticsearch.rest.RestRequest.Method.HEAD) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) GetRequest(org.elasticsearch.action.get.GetRequest) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) GetResponse(org.elasticsearch.action.get.GetResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

ActionRequestValidationException (org.elasticsearch.action.ActionRequestValidationException)18 IOException (java.io.IOException)4 ActionRequest (org.elasticsearch.action.ActionRequest)4 IndexRequest (org.elasticsearch.action.index.IndexRequest)4 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)4 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)3 GetRequest (org.elasticsearch.action.get.GetRequest)3 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)2 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 MainRequest (org.elasticsearch.action.main.MainRequest)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2 Settings (org.elasticsearch.common.settings.Settings)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 RemoteInfo (org.elasticsearch.index.reindex.remote.RemoteInfo)2 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)2 RestRequest (org.elasticsearch.rest.RestRequest)2