Search in sources :

Example 6 with RestToXContentListener

use of org.elasticsearch.rest.action.RestToXContentListener in project elasticsearch by elastic.

the class RestSnapshotsStatusAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String repository = request.param("repository", "_all");
    String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
    if (snapshots.length == 1 && "_all".equalsIgnoreCase(snapshots[0])) {
        snapshots = Strings.EMPTY_ARRAY;
    }
    SnapshotsStatusRequest snapshotsStatusRequest = snapshotsStatusRequest(repository).snapshots(snapshots);
    snapshotsStatusRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", snapshotsStatusRequest.ignoreUnavailable()));
    snapshotsStatusRequest.masterNodeTimeout(request.paramAsTime("master_timeout", snapshotsStatusRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().snapshotsStatus(snapshotsStatusRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) SnapshotsStatusRequest(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) Requests.snapshotsStatusRequest(org.elasticsearch.client.Requests.snapshotsStatusRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) SnapshotsStatusRequest(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)

Example 7 with RestToXContentListener

use of org.elasticsearch.rest.action.RestToXContentListener in project elasticsearch by elastic.

the class RestVerifyRepositoryAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    VerifyRepositoryRequest verifyRepositoryRequest = verifyRepositoryRequest(request.param("repository"));
    verifyRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", verifyRepositoryRequest.masterNodeTimeout()));
    verifyRepositoryRequest.timeout(request.paramAsTime("timeout", verifyRepositoryRequest.timeout()));
    return channel -> client.admin().cluster().verifyRepository(verifyRepositoryRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) POST(org.elasticsearch.rest.RestRequest.Method.POST) VerifyRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest) Settings(org.elasticsearch.common.settings.Settings) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests.verifyRepositoryRequest(org.elasticsearch.client.Requests.verifyRepositoryRequest) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) VerifyRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)

Example 8 with RestToXContentListener

use of org.elasticsearch.rest.action.RestToXContentListener in project elasticsearch by elastic.

the class RestGetAction 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()));
    if (request.param("fields") != null) {
        throw new IllegalArgumentException("the parameter [fields] is no longer supported, " + "please use [stored_fields] to retrieve stored fields or [_source] to load the field from _source");
    }
    final String fieldsParam = request.param("stored_fields");
    if (fieldsParam != null) {
        final String[] fields = Strings.splitStringByCommaToArray(fieldsParam);
        if (fields != null) {
            getRequest.storedFields(fields);
        }
    }
    getRequest.version(RestActions.parseVersion(request));
    getRequest.versionType(VersionType.fromString(request.param("version_type"), getRequest.versionType()));
    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));
    return channel -> client.get(getRequest, new RestToXContentListener<GetResponse>(channel) {

        @Override
        protected RestStatus getStatus(final GetResponse response) {
            return response.isExists() ? OK : NOT_FOUND;
        }
    });
}
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) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) IOException(java.io.IOException) NOT_FOUND(org.elasticsearch.rest.RestStatus.NOT_FOUND) RestController(org.elasticsearch.rest.RestController) VersionType(org.elasticsearch.index.VersionType) Strings(org.elasticsearch.common.Strings) RestActions(org.elasticsearch.rest.action.RestActions) Settings(org.elasticsearch.common.settings.Settings) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) HEAD(org.elasticsearch.rest.RestRequest.Method.HEAD) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) RestStatus(org.elasticsearch.rest.RestStatus) GetRequest(org.elasticsearch.action.get.GetRequest) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 9 with RestToXContentListener

use of org.elasticsearch.rest.action.RestToXContentListener in project elasticsearch by elastic.

the class RestMultiTermVectorsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    MultiTermVectorsRequest multiTermVectorsRequest = new MultiTermVectorsRequest();
    TermVectorsRequest template = new TermVectorsRequest();
    template.index(request.param("index"));
    template.type(request.param("type"));
    RestTermVectorsAction.readURIParameters(template, request);
    multiTermVectorsRequest.ids(Strings.commaDelimitedListToStringArray(request.param("ids")));
    request.withContentOrSourceParamParserOrNull(p -> multiTermVectorsRequest.add(template, p));
    return channel -> client.multiTermVectors(multiTermVectorsRequest, new RestToXContentListener<MultiTermVectorsResponse>(channel));
}
Also used : MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse) Strings(org.elasticsearch.common.Strings) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse)

Example 10 with RestToXContentListener

use of org.elasticsearch.rest.action.RestToXContentListener in project elasticsearch by elastic.

the class RestSimulatePipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    Tuple<XContentType, BytesReference> sourceTuple = restRequest.contentOrSourceParam();
    SimulatePipelineRequest request = new SimulatePipelineRequest(sourceTuple.v2(), sourceTuple.v1());
    request.setId(restRequest.param("id"));
    request.setVerbose(restRequest.paramAsBoolean("verbose", false));
    return channel -> client.admin().cluster().simulatePipeline(request, new RestToXContentListener<>(channel));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) XContentType(org.elasticsearch.common.xcontent.XContentType) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) SimulatePipelineRequest(org.elasticsearch.action.ingest.SimulatePipelineRequest) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesReference(org.elasticsearch.common.bytes.BytesReference) Tuple(org.elasticsearch.common.collect.Tuple) XContentType(org.elasticsearch.common.xcontent.XContentType) SimulatePipelineRequest(org.elasticsearch.action.ingest.SimulatePipelineRequest)

Aggregations

IOException (java.io.IOException)16 NodeClient (org.elasticsearch.client.node.NodeClient)16 Settings (org.elasticsearch.common.settings.Settings)16 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)16 RestController (org.elasticsearch.rest.RestController)16 RestRequest (org.elasticsearch.rest.RestRequest)16 RestToXContentListener (org.elasticsearch.rest.action.RestToXContentListener)16 GET (org.elasticsearch.rest.RestRequest.Method.GET)10 Strings (org.elasticsearch.common.Strings)8 POST (org.elasticsearch.rest.RestRequest.Method.POST)8 XContentParser (org.elasticsearch.common.xcontent.XContentParser)3 Set (java.util.Set)2 TermVectorsRequest (org.elasticsearch.action.termvectors.TermVectorsRequest)2 VersionType (org.elasticsearch.index.VersionType)2 HEAD (org.elasticsearch.rest.RestRequest.Method.HEAD)2 RestStatus (org.elasticsearch.rest.RestStatus)2 NOT_FOUND (org.elasticsearch.rest.RestStatus.NOT_FOUND)2 OK (org.elasticsearch.rest.RestStatus.OK)2 HashSet (java.util.HashSet)1 GetTaskRequest (org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskRequest)1