org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestIndicesSegmentsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(Strings.splitStringByCommaToArray(request.param("index")));
    indicesSegmentsRequest.verbose(request.paramAsBoolean("verbose", false));
    indicesSegmentsRequest.indicesOptions(IndicesOptions.fromRequest(request, indicesSegmentsRequest.indicesOptions()));
    client.admin().indices().segments(indicesSegmentsRequest, new RestBuilderListener<IndicesSegmentResponse>(channel) {
        @Override
        public RestResponse buildResponse(IndicesSegmentResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            response.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example #2
Source File: RestSegmentsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));

    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);

    client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {
                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
 
Example #3
Source File: EsIndexOptimizationManager.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
@Override
protected void runImpl(LockingTaskExecutor executor, Instant lockAtMostUntil) {
    executor.executeWithLock(() -> {
        try {
            IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            IndicesSegmentResponse indicesSegmentResponse = elasticsearchConnection.getClient()
                    .admin()
                    .indices()
                    .segments(indicesSegmentsRequest)
                    .actionGet();
            Set<String> indicesToOptimize = Sets.newHashSet();

            Map<String, IndexSegments> segmentResponseIndices = indicesSegmentResponse.getIndices();
            for(Map.Entry<String, IndexSegments> entry : segmentResponseIndices.entrySet()) {
                String index = entry.getKey();
                extractIndicesToOptimizeForIndex(index, entry.getValue(), indicesToOptimize);
            }
            optimizeIndices(indicesToOptimize);
            LOGGER.info("No of indexes optimized : {}", indicesToOptimize.size());
        } catch (Exception e) {
            LOGGER.error("Error occurred while calling optimization API", e);
        }
    }, new LockConfiguration(esIndexOptimizationConfig.getJobName(), lockAtMostUntil));
}
 
Example #4
Source File: SegmentsRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(IndicesSegmentsRequest request, IndicesSegmentResponse response, XContentBuilder builder) throws IOException {
    builder.startObject();
    builder.field(Fields.OK, true);
    buildBroadcastShardsHeader(builder, response);
    response.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.endObject();
    return builder;
}
 
Example #5
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<IndicesSegmentResponse> segments(final IndicesSegmentsRequest request) {
    return execute(IndicesSegmentsAction.INSTANCE, request);
}
 
Example #6
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void segments(final IndicesSegmentsRequest request, final ActionListener<IndicesSegmentResponse> listener) {
    execute(IndicesSegmentsAction.INSTANCE, request, listener);
}
 
Example #7
Source File: Requests.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static IndicesSegmentsRequest indicesSegmentsRequest(String... indices) {
    return new IndicesSegmentsRequest(indices);
}
 
Example #8
Source File: SegmentsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public SegmentsRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new IndicesSegmentsRequest(), jsonToString, stringToJson);
}
 
Example #9
Source File: SegmentsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<IndicesSegmentResponse> doExecute(IndicesSegmentsRequest request) {
    return client.admin().indices().segments(request);
}
 
Example #10
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * The segments of one or more indices.
 *
 * @param request The indices segments request
 * @return The result future
 * @see Requests#indicesSegmentsRequest(String...)
 */
ActionFuture<IndicesSegmentResponse> segments(IndicesSegmentsRequest request);
 
Example #11
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * The segments of one or more indices.
 *
 * @param request  The indices segments request
 * @param listener A listener to be notified with a result
 * @see Requests#indicesSegmentsRequest(String...)
 */
void segments(IndicesSegmentsRequest request, ActionListener<IndicesSegmentResponse> listener);