Search in sources :

Example 51 with RestRequest

use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.

the class RestCloseIndexAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
    closeIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", closeIndexRequest.masterNodeTimeout()));
    closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout()));
    closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions()));
    return channel -> client.admin().indices().close(closeIndexRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest)

Example 52 with RestRequest

use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.

the class RestTable method buildXContentBuilder.

public static RestResponse buildXContentBuilder(Table table, RestChannel channel) throws Exception {
    RestRequest request = channel.request();
    XContentBuilder builder = channel.newBuilder();
    List<DisplayHeader> displayHeaders = buildDisplayHeaders(table, request);
    builder.startArray();
    List<Integer> rowOrder = getRowOrder(table, request);
    for (Integer row : rowOrder) {
        builder.startObject();
        for (DisplayHeader header : displayHeaders) {
            builder.field(header.display, renderValue(request, table.getAsMap().get(header.name).get(row).value));
        }
        builder.endObject();
    }
    builder.endArray();
    return new BytesRestResponse(RestStatus.OK, builder);
}
Also used : RestRequest(org.elasticsearch.rest.RestRequest) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 53 with RestRequest

use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.

the class RestTable method buildResponse.

public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception {
    RestRequest request = channel.request();
    XContentType xContentType = XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept")));
    if (xContentType != null) {
        return buildXContentBuilder(table, channel);
    }
    return buildTextPlainResponse(table, channel);
}
Also used : RestRequest(org.elasticsearch.rest.RestRequest) XContentType(org.elasticsearch.common.xcontent.XContentType)

Example 54 with RestRequest

use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.

the class MultiSearchRequestTests method parseMultiSearchRequest.

private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException {
    byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(data), XContentType.JSON).build();
    return RestMultiSearchAction.parseRequest(restRequest, true);
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) RestRequest(org.elasticsearch.rest.RestRequest) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder)

Example 55 with RestRequest

use of org.elasticsearch.rest.RestRequest in project elasticsearch by elastic.

the class RestSearchAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    SearchRequest searchRequest = new SearchRequest();
    request.withContentOrSourceParamParserOrNull(parser -> parseSearchRequest(searchRequest, request, parser));
    return channel -> client.search(searchRequest, new RestStatusToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Arrays(java.util.Arrays) GET(org.elasticsearch.rest.RestRequest.Method.GET) SearchContext(org.elasticsearch.search.internal.SearchContext) SearchRequest(org.elasticsearch.action.search.SearchRequest) Strings(org.elasticsearch.common.Strings) RestActions(org.elasticsearch.rest.action.RestActions) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) NodeClient(org.elasticsearch.client.node.NodeClient) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) Set(java.util.Set) Scroll(org.elasticsearch.search.Scroll) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) SuggestBuilder(org.elasticsearch.search.suggest.SuggestBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) StoredFieldsContext(org.elasticsearch.search.fetch.StoredFieldsContext) SuggestBuilders.termSuggestion(org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion) SuggestMode(org.elasticsearch.search.suggest.term.TermSuggestionBuilder.SuggestMode) SortOrder(org.elasticsearch.search.sort.SortOrder) TimeValue.parseTimeValue(org.elasticsearch.common.unit.TimeValue.parseTimeValue) Collections(java.util.Collections) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) SearchRequest(org.elasticsearch.action.search.SearchRequest)

Aggregations

RestRequest (org.elasticsearch.rest.RestRequest)133 Settings (org.elasticsearch.common.settings.Settings)110 RestController (org.elasticsearch.rest.RestController)110 NodeClient (org.elasticsearch.client.node.NodeClient)108 IOException (java.io.IOException)91 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)88 Strings (org.elasticsearch.common.Strings)61 GET (org.elasticsearch.rest.RestRequest.Method.GET)57 RestResponse (org.elasticsearch.rest.RestResponse)50 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)41 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)41 POST (org.elasticsearch.rest.RestRequest.Method.POST)34 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)30 RestBuilderListener (org.elasticsearch.rest.action.RestBuilderListener)27 OK (org.elasticsearch.rest.RestStatus.OK)23 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)23 FakeRestRequest (org.elasticsearch.test.rest.FakeRestRequest)21 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)20 Table (org.elasticsearch.common.Table)19 HashMap (java.util.HashMap)17