Search in sources :

Example 1 with RestToXContentListener

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

the class RestClusterSearchShardsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterSearchShardsRequest clusterSearchShardsRequest = Requests.clusterSearchShardsRequest(indices);
    clusterSearchShardsRequest.local(request.paramAsBoolean("local", clusterSearchShardsRequest.local()));
    clusterSearchShardsRequest.routing(request.param("routing"));
    clusterSearchShardsRequest.preference(request.param("preference"));
    clusterSearchShardsRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterSearchShardsRequest.indicesOptions()));
    return channel -> client.admin().cluster().searchShards(clusterSearchShardsRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) ClusterSearchShardsRequest(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest) Strings(org.elasticsearch.common.Strings) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests(org.elasticsearch.client.Requests) ClusterSearchShardsRequest(org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest)

Example 2 with RestToXContentListener

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

the class RestRolloverIndexAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index"));
    request.applyContentParser(parser -> RolloverRequest.PARSER.parse(parser, rolloverIndexRequest, null));
    rolloverIndexRequest.dryRun(request.paramAsBoolean("dry_run", false));
    rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout()));
    rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout()));
    rolloverIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
    return channel -> client.admin().indices().rolloverIndex(rolloverIndexRequest, new RestToXContentListener<>(channel));
}
Also used : ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) RolloverRequest(org.elasticsearch.action.admin.indices.rollover.RolloverRequest) RolloverRequest(org.elasticsearch.action.admin.indices.rollover.RolloverRequest)

Example 3 with RestToXContentListener

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

the class RestGetIndexTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] names = Strings.splitStringByCommaToArray(request.param("name"));
    final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
    getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
    getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));
    final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;
    return channel -> client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestToXContentListener<GetIndexTemplatesResponse>(channel) {

        @Override
        protected RestStatus getStatus(final GetIndexTemplatesResponse response) {
            final boolean templateExists = response.getIndexTemplates().isEmpty() == false;
            return (templateExists || implicitAll) ? OK : NOT_FOUND;
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) Set(java.util.Set) IOException(java.io.IOException) NOT_FOUND(org.elasticsearch.rest.RestStatus.NOT_FOUND) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) 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) RestStatus(org.elasticsearch.rest.RestStatus) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest)

Example 4 with RestToXContentListener

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

the class RestGetTaskAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    TaskId taskId = new TaskId(request.param("taskId"));
    boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false);
    TimeValue timeout = request.paramAsTime("timeout", null);
    GetTaskRequest getTaskRequest = new GetTaskRequest();
    getTaskRequest.setTaskId(taskId);
    getTaskRequest.setWaitForCompletion(waitForCompletion);
    getTaskRequest.setTimeout(timeout);
    return channel -> client.admin().cluster().getTask(getTaskRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) GetTaskRequest(org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskRequest) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) TimeValue(org.elasticsearch.common.unit.TimeValue) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) TaskId(org.elasticsearch.tasks.TaskId) GetTaskRequest(org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskRequest) TaskId(org.elasticsearch.tasks.TaskId) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 5 with RestToXContentListener

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

the class RestRestoreSnapshotAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    RestoreSnapshotRequest restoreSnapshotRequest = restoreSnapshotRequest(request.param("repository"), request.param("snapshot"));
    restoreSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", restoreSnapshotRequest.masterNodeTimeout()));
    restoreSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
    request.applyContentParser(p -> restoreSnapshotRequest.source(p.mapOrdered()));
    return channel -> client.admin().cluster().restoreSnapshot(restoreSnapshotRequest, new RestToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Requests.restoreSnapshotRequest(org.elasticsearch.client.Requests.restoreSnapshotRequest) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)

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