Search in sources :

Example 46 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class CommitPoints method toXContent.

public static byte[] toXContent(CommitPoint commitPoint) throws Exception {
    XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
    builder.startObject();
    builder.field("version", commitPoint.version());
    builder.field("name", commitPoint.name());
    builder.field("type", commitPoint.type().toString());
    builder.startObject("index_files");
    for (CommitPoint.FileInfo fileInfo : commitPoint.indexFiles()) {
        builder.startObject(fileInfo.name());
        builder.field("physical_name", fileInfo.physicalName());
        builder.field("length", fileInfo.length());
        if (fileInfo.checksum() != null) {
            builder.field("checksum", fileInfo.checksum());
        }
        builder.endObject();
    }
    builder.endObject();
    builder.startObject("translog_files");
    for (CommitPoint.FileInfo fileInfo : commitPoint.translogFiles()) {
        builder.startObject(fileInfo.name());
        builder.field("physical_name", fileInfo.physicalName());
        builder.field("length", fileInfo.length());
        builder.endObject();
    }
    builder.endObject();
    builder.endObject();
    return BytesReference.toBytes(builder.bytes());
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 47 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class RestRefreshAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));
    refreshRequest.indicesOptions(IndicesOptions.fromRequest(request, refreshRequest.indicesOptions()));
    return channel -> client.admin().indices().refresh(refreshRequest, new RestBuilderListener<RefreshResponse>(channel) {

        @Override
        public RestResponse buildResponse(RefreshResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(response.getStatus(), builder);
        }
    });
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) RestActions.buildBroadcastShardsHeader(org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 48 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class RestSyncedFlushAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, IndicesOptions.lenientExpandOpen());
    SyncedFlushRequest syncedFlushRequest = new SyncedFlushRequest(Strings.splitStringByCommaToArray(request.param("index")));
    syncedFlushRequest.indicesOptions(indicesOptions);
    return channel -> client.admin().indices().syncedFlush(syncedFlushRequest, new RestBuilderListener<SyncedFlushResponse>(channel) {

        @Override
        public RestResponse buildResponse(SyncedFlushResponse results, XContentBuilder builder) throws Exception {
            builder.startObject();
            results.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(results.restStatus(), builder);
        }
    });
}
Also used : SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) NodeClient(org.elasticsearch.client.node.NodeClient) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 49 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class RestUpgradeAction method handleGet.

private RestChannelConsumer handleGet(final RestRequest request, NodeClient client) {
    UpgradeStatusRequest statusRequest = new UpgradeStatusRequest(Strings.splitStringByCommaToArray(request.param("index")));
    statusRequest.indicesOptions(IndicesOptions.fromRequest(request, statusRequest.indicesOptions()));
    return channel -> client.admin().indices().upgradeStatus(statusRequest, new RestBuilderListener<UpgradeStatusResponse>(channel) {

        @Override
        public RestResponse buildResponse(UpgradeStatusResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            response.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : UpgradeRequest(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) UpgradeStatusRequest(org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusRequest) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) UpgradeStatusResponse(org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusResponse) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) POST(org.elasticsearch.rest.RestRequest.Method.POST) Version(org.elasticsearch.Version) Settings(org.elasticsearch.common.settings.Settings) RestActions.buildBroadcastShardsHeader(org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader) UpgradeResponse(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeResponse) Map(java.util.Map) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) Tuple(org.elasticsearch.common.collect.Tuple) UpgradeStatusResponse(org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusResponse) UpgradeStatusRequest(org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 50 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class RestUpgradeAction method handlePost.

private RestChannelConsumer handlePost(final RestRequest request, NodeClient client) {
    UpgradeRequest upgradeReq = new UpgradeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    upgradeReq.indicesOptions(IndicesOptions.fromRequest(request, upgradeReq.indicesOptions()));
    upgradeReq.upgradeOnlyAncientSegments(request.paramAsBoolean("only_ancient_segments", false));
    return channel -> client.admin().indices().upgrade(upgradeReq, new RestBuilderListener<UpgradeResponse>(channel) {

        @Override
        public RestResponse buildResponse(UpgradeResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.startObject("upgraded_indices");
            for (Map.Entry<String, Tuple<Version, String>> entry : response.versions().entrySet()) {
                builder.startObject(entry.getKey());
                builder.field("upgrade_version", entry.getValue().v1());
                builder.field("oldest_lucene_segment_version", entry.getValue().v2());
                builder.endObject();
            }
            builder.endObject();
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : UpgradeRequest(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) UpgradeStatusRequest(org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusRequest) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) UpgradeStatusResponse(org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusResponse) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) POST(org.elasticsearch.rest.RestRequest.Method.POST) Version(org.elasticsearch.Version) Settings(org.elasticsearch.common.settings.Settings) RestActions.buildBroadcastShardsHeader(org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader) UpgradeResponse(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeResponse) Map(java.util.Map) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) Tuple(org.elasticsearch.common.collect.Tuple) UpgradeResponse(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeResponse) Version(org.elasticsearch.Version) UpgradeRequest(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Aggregations

XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)619 IOException (java.io.IOException)127 XContentParser (org.elasticsearch.common.xcontent.XContentParser)122 Settings (org.elasticsearch.common.settings.Settings)60 ArrayList (java.util.ArrayList)59 SearchResponse (org.elasticsearch.action.search.SearchResponse)56 Matchers.containsString (org.hamcrest.Matchers.containsString)53 HashMap (java.util.HashMap)47 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)43 Map (java.util.Map)41 RestRequest (org.elasticsearch.rest.RestRequest)37 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)36 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)35 Test (org.junit.Test)34 RestController (org.elasticsearch.rest.RestController)33 NodeClient (org.elasticsearch.client.node.NodeClient)32 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)32 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)32 GeoPoint (org.elasticsearch.common.geo.GeoPoint)31 CrateUnitTest (io.crate.test.integration.CrateUnitTest)28