Search in sources :

Example 1 with ForceMergeResponse

use of org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse in project elasticsearch by elastic.

the class CompletionSuggestSearchIT method testPrunedSegments.

// see #3555
public void testPrunedSegments() throws IOException {
    createIndexAndMappingAndSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).build(), completionMappingBuilder);
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().startObject(FIELD).startArray("input").value("The Beatles").endArray().endObject().endObject()).get();
    client().prepareIndex(INDEX, TYPE, "2").setSource(jsonBuilder().startObject().field("somefield", "somevalue").endObject()).get();
    ForceMergeResponse actionGet = client().admin().indices().prepareForceMerge().setFlush(true).setMaxNumSegments(1).execute().actionGet();
    assertAllSuccessful(actionGet);
    refresh();
    // update the first one and then merge.. the target segment will have no value in FIELD
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().field("somefield", "somevalue").endObject()).get();
    actionGet = client().admin().indices().prepareForceMerge().setFlush(true).setMaxNumSegments(1).execute().actionGet();
    assertAllSuccessful(actionGet);
    refresh();
    assertSuggestions("b");
    assertThat(2L, equalTo(client().prepareSearch(INDEX).setSize(0).get().getHits().getTotalHits()));
    for (IndexShardSegments seg : client().admin().indices().prepareSegments().get().getIndices().get(INDEX)) {
        ShardSegments[] shards = seg.getShards();
        for (ShardSegments shardSegments : shards) {
            assertThat(shardSegments.getSegments().size(), equalTo(1));
        }
    }
}
Also used : ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments)

Example 2 with ForceMergeResponse

use of org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse in project elasticsearch by elastic.

the class ESIntegTestCase method forceMerge.

/**
     * Waits for all relocations and force merge all indices in the cluster to 1 segment.
     */
protected ForceMergeResponse forceMerge() {
    waitForRelocation();
    ForceMergeResponse actionGet = client().admin().indices().prepareForceMerge().setMaxNumSegments(1).execute().actionGet();
    assertNoFailures(actionGet);
    return actionGet;
}
Also used : ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse)

Example 3 with ForceMergeResponse

use of org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse in project elasticsearch by elastic.

the class DocumentActionsIT method testIndexActions.

public void testIndexActions() throws Exception {
    createIndex();
    NumShards numShards = getNumShards(getConcreteIndexName());
    logger.info("Running Cluster Health");
    ensureGreen();
    logger.info("Indexing [type1/1]");
    IndexResponse indexResponse = client().prepareIndex().setIndex("test").setType("type1").setId("1").setSource(source("1", "test")).setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
    assertThat(indexResponse.getIndex(), equalTo(getConcreteIndexName()));
    assertThat(indexResponse.getId(), equalTo("1"));
    assertThat(indexResponse.getType(), equalTo("type1"));
    logger.info("Refreshing");
    RefreshResponse refreshResponse = refresh();
    assertThat(refreshResponse.getSuccessfulShards(), equalTo(numShards.totalNumShards));
    logger.info("--> index exists?");
    assertThat(indexExists(getConcreteIndexName()), equalTo(true));
    logger.info("--> index exists?, fake index");
    assertThat(indexExists("test1234565"), equalTo(false));
    logger.info("Clearing cache");
    ClearIndicesCacheResponse clearIndicesCacheResponse = client().admin().indices().clearCache(clearIndicesCacheRequest("test").recycler(true).fieldDataCache(true).queryCache(true)).actionGet();
    assertNoFailures(clearIndicesCacheResponse);
    assertThat(clearIndicesCacheResponse.getSuccessfulShards(), equalTo(numShards.totalNumShards));
    logger.info("Force Merging");
    waitForRelocation(ClusterHealthStatus.GREEN);
    ForceMergeResponse mergeResponse = forceMerge();
    assertThat(mergeResponse.getSuccessfulShards(), equalTo(numShards.totalNumShards));
    GetResponse getResult;
    logger.info("Get [type1/1]");
    for (int i = 0; i < 5; i++) {
        getResult = client().prepareGet("test", "type1", "1").setOperationThreaded(false).execute().actionGet();
        assertThat(getResult.getIndex(), equalTo(getConcreteIndexName()));
        assertThat("cycle #" + i, getResult.getSourceAsString(), equalTo(source("1", "test").string()));
        assertThat("cycle(map) #" + i, (String) getResult.getSourceAsMap().get("name"), equalTo("test"));
        getResult = client().get(getRequest("test").type("type1").id("1").operationThreaded(true)).actionGet();
        assertThat("cycle #" + i, getResult.getSourceAsString(), equalTo(source("1", "test").string()));
        assertThat(getResult.getIndex(), equalTo(getConcreteIndexName()));
    }
    logger.info("Get [type1/1] with script");
    for (int i = 0; i < 5; i++) {
        getResult = client().prepareGet("test", "type1", "1").setStoredFields("name").execute().actionGet();
        assertThat(getResult.getIndex(), equalTo(getConcreteIndexName()));
        assertThat(getResult.isExists(), equalTo(true));
        assertThat(getResult.getSourceAsBytes(), nullValue());
        assertThat(getResult.getField("name").getValues().get(0).toString(), equalTo("test"));
    }
    logger.info("Get [type1/2] (should be empty)");
    for (int i = 0; i < 5; i++) {
        getResult = client().get(getRequest("test").type("type1").id("2")).actionGet();
        assertThat(getResult.isExists(), equalTo(false));
    }
    logger.info("Delete [type1/1]");
    DeleteResponse deleteResponse = client().prepareDelete("test", "type1", "1").execute().actionGet();
    assertThat(deleteResponse.getIndex(), equalTo(getConcreteIndexName()));
    assertThat(deleteResponse.getId(), equalTo("1"));
    assertThat(deleteResponse.getType(), equalTo("type1"));
    logger.info("Refreshing");
    client().admin().indices().refresh(refreshRequest("test")).actionGet();
    logger.info("Get [type1/1] (should be empty)");
    for (int i = 0; i < 5; i++) {
        getResult = client().get(getRequest("test").type("type1").id("1")).actionGet();
        assertThat(getResult.isExists(), equalTo(false));
    }
    logger.info("Index [type1/1]");
    client().index(indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet();
    logger.info("Index [type1/2]");
    client().index(indexRequest("test").type("type1").id("2").source(source("2", "test2"))).actionGet();
    logger.info("Flushing");
    FlushResponse flushResult = client().admin().indices().prepareFlush("test").execute().actionGet();
    assertThat(flushResult.getSuccessfulShards(), equalTo(numShards.totalNumShards));
    assertThat(flushResult.getFailedShards(), equalTo(0));
    logger.info("Refreshing");
    client().admin().indices().refresh(refreshRequest("test")).actionGet();
    logger.info("Get [type1/1] and [type1/2]");
    for (int i = 0; i < 5; i++) {
        getResult = client().get(getRequest("test").type("type1").id("1")).actionGet();
        assertThat(getResult.getIndex(), equalTo(getConcreteIndexName()));
        assertThat("cycle #" + i, getResult.getSourceAsString(), equalTo(source("1", "test").string()));
        getResult = client().get(getRequest("test").type("type1").id("2")).actionGet();
        String ste1 = getResult.getSourceAsString();
        String ste2 = source("2", "test2").string();
        assertThat("cycle #" + i, ste1, equalTo(ste2));
        assertThat(getResult.getIndex(), equalTo(getConcreteIndexName()));
    }
    logger.info("Count");
    // check count
    for (int i = 0; i < 5; i++) {
        // test successful
        SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(termQuery("_type", "type1")).execute().actionGet();
        assertNoFailures(countResponse);
        assertThat(countResponse.getHits().getTotalHits(), equalTo(2L));
        assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
        assertThat(countResponse.getFailedShards(), equalTo(0));
        // count with no query is a match all one
        countResponse = client().prepareSearch("test").setSize(0).execute().actionGet();
        assertThat("Failures " + countResponse.getShardFailures(), countResponse.getShardFailures() == null ? 0 : countResponse.getShardFailures().length, equalTo(0));
        assertThat(countResponse.getHits().getTotalHits(), equalTo(2L));
        assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
        assertThat(countResponse.getFailedShards(), equalTo(0));
    }
}
Also used : ClearIndicesCacheResponse(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) FlushResponse(org.elasticsearch.action.admin.indices.flush.FlushResponse) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) GetResponse(org.elasticsearch.action.get.GetResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 4 with ForceMergeResponse

use of org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse in project elasticsearch by elastic.

the class RestForceMergeAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
    mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
    mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
    mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
    return channel -> client.admin().indices().forceMerge(mergeRequest, new RestBuilderListener<ForceMergeResponse>(channel) {

        @Override
        public RestResponse buildResponse(ForceMergeResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) 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) ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) Strings(org.elasticsearch.common.Strings) ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) 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) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) 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 5 with ForceMergeResponse

use of org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse in project crate by crate.

the class DDLStatementDispatcher method executeMergeSegments.

private static CompletableFuture<Long> executeMergeSegments(OptimizeTableAnalyzedStatement analysis, TransportForceMergeAction transportForceMergeAction) {
    ForceMergeRequest request = new ForceMergeRequest(analysis.indexNames().toArray(new String[0]));
    // Pass parameters to ES request
    request.maxNumSegments(analysis.settings().getAsInt(OptimizeSettings.MAX_NUM_SEGMENTS.name(), ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS));
    request.onlyExpungeDeletes(analysis.settings().getAsBoolean(OptimizeSettings.ONLY_EXPUNGE_DELETES.name(), ForceMergeRequest.Defaults.ONLY_EXPUNGE_DELETES));
    request.flush(analysis.settings().getAsBoolean(OptimizeSettings.FLUSH.name(), ForceMergeRequest.Defaults.FLUSH));
    request.indicesOptions(IndicesOptions.lenientExpandOpen());
    FutureActionListener<ForceMergeResponse, Long> listener = new FutureActionListener<>(Functions.constant((long) analysis.indexNames().size()));
    transportForceMergeAction.execute(request, listener);
    return listener;
}
Also used : ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) FutureActionListener(io.crate.action.FutureActionListener)

Aggregations

ForceMergeResponse (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse)6 ForceMergeRequest (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest)2 Settings (org.elasticsearch.common.settings.Settings)2 FutureActionListener (io.crate.action.FutureActionListener)1 IOException (java.io.IOException)1 ClearIndicesCacheResponse (org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse)1 FlushResponse (org.elasticsearch.action.admin.indices.flush.FlushResponse)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 IndexShardSegments (org.elasticsearch.action.admin.indices.segments.IndexShardSegments)1 ShardSegments (org.elasticsearch.action.admin.indices.segments.ShardSegments)1 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)1 GetResponse (org.elasticsearch.action.get.GetResponse)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 IndexService (org.elasticsearch.index.IndexService)1 IndexShard (org.elasticsearch.index.shard.IndexShard)1