Search in sources :

Example 11 with IndicesStatsResponse

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.

the class IndexStatsIT method testTypesParam.

public void testTypesParam() throws Exception {
    createIndex("test1");
    createIndex("test2");
    ensureGreen();
    client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
    client().prepareIndex("test2", "baz", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
    refresh();
    IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
    IndicesStatsResponse stats = builder.execute().actionGet();
    assertThat(stats.getTotal().indexing.getTotal().getIndexCount(), greaterThan(0L));
    assertThat(stats.getTotal().indexing.getTypeStats(), is(nullValue()));
    stats = builder.setTypes("bar").execute().actionGet();
    assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
    assertThat(stats.getTotal().indexing.getTypeStats().containsKey("baz"), is(false));
    stats = builder.setTypes("bar", "baz").execute().actionGet();
    assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
    assertThat(stats.getTotal().indexing.getTypeStats().get("baz").getIndexCount(), greaterThan(0L));
    stats = builder.setTypes("*").execute().actionGet();
    assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
    assertThat(stats.getTotal().indexing.getTypeStats().get("baz").getIndexCount(), greaterThan(0L));
    stats = builder.setTypes("*r").execute().actionGet();
    assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
    assertThat(stats.getTotal().indexing.getTypeStats().containsKey("baz"), is(false));
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequestBuilder(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder)

Example 12 with IndicesStatsResponse

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.

the class IndexStatsIT method testCompletionFieldsParam.

public void testCompletionFieldsParam() throws Exception {
    assertAcked(prepareCreate("test1").addMapping("bar", "{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}", XContentType.JSON));
    ensureGreen();
    client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
    client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
    refresh();
    IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
    IndicesStatsResponse stats = builder.execute().actionGet();
    assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields(), is(nullValue()));
    stats = builder.setCompletionFields("bar.completion").execute().actionGet();
    assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
    assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(false));
    stats = builder.setCompletionFields("bar.completion", "baz.completion").execute().actionGet();
    assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
    assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(true));
    assertThat(stats.getTotal().completion.getFields().get("baz.completion"), greaterThan(0L));
    stats = builder.setCompletionFields("*").execute().actionGet();
    assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
    assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(true));
    assertThat(stats.getTotal().completion.getFields().get("baz.completion"), greaterThan(0L));
    stats = builder.setCompletionFields("*r*").execute().actionGet();
    assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
    assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
    assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(false));
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequestBuilder(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder)

Example 13 with IndicesStatsResponse

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.

the class IndexStatsIT method testAllFlags.

public void testAllFlags() throws Exception {
    // rely on 1 replica for this tests
    createIndex("test1");
    createIndex("test2");
    ensureGreen();
    client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
    client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
    client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
    client().admin().indices().prepareRefresh().execute().actionGet();
    IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
    Flag[] values = CommonStatsFlags.Flag.values();
    for (Flag flag : values) {
        set(flag, builder, false);
    }
    IndicesStatsResponse stats = builder.execute().actionGet();
    for (Flag flag : values) {
        if (flag == Flag.Suggest) {
            // suggest flag is unused
            continue;
        }
        assertThat(isSet(flag, stats.getPrimaries()), equalTo(false));
        assertThat(isSet(flag, stats.getTotal()), equalTo(false));
    }
    for (Flag flag : values) {
        set(flag, builder, true);
    }
    stats = builder.execute().actionGet();
    for (Flag flag : values) {
        assertThat(isSet(flag, stats.getPrimaries()), equalTo(true));
        assertThat(isSet(flag, stats.getTotal()), equalTo(true));
    }
    Random random = random();
    EnumSet<Flag> flags = EnumSet.noneOf(Flag.class);
    for (Flag flag : values) {
        if (random.nextBoolean()) {
            flags.add(flag);
        }
    }
    for (Flag flag : values) {
        // clear all
        set(flag, builder, false);
    }
    for (Flag flag : flags) {
        // set the flags
        set(flag, builder, true);
    }
    stats = builder.execute().actionGet();
    for (Flag flag : flags) {
        // check the flags
        assertThat(isSet(flag, stats.getPrimaries()), equalTo(true));
        assertThat(isSet(flag, stats.getTotal()), equalTo(true));
    }
    for (Flag flag : EnumSet.complementOf(flags)) {
        // check the complement
        if (flag == Flag.Suggest) {
            // suggest flag is unused
            continue;
        }
        assertThat(isSet(flag, stats.getPrimaries()), equalTo(false));
        assertThat(isSet(flag, stats.getTotal()), equalTo(false));
    }
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequestBuilder(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder) Random(java.util.Random) Flag(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag)

Example 14 with IndicesStatsResponse

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.

the class IndexStatsIT method testGroupsParam.

public void testGroupsParam() throws Exception {
    createIndex("test1");
    ensureGreen();
    client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
    refresh();
    client().prepareSearch("_all").setStats("bar", "baz").execute().actionGet();
    IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
    IndicesStatsResponse stats = builder.execute().actionGet();
    assertThat(stats.getTotal().search.getTotal().getQueryCount(), greaterThan(0L));
    assertThat(stats.getTotal().search.getGroupStats(), is(nullValue()));
    stats = builder.setGroups("bar").execute().actionGet();
    assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
    assertThat(stats.getTotal().search.getGroupStats().containsKey("baz"), is(false));
    stats = builder.setGroups("bar", "baz").execute().actionGet();
    assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
    assertThat(stats.getTotal().search.getGroupStats().get("baz").getQueryCount(), greaterThan(0L));
    stats = builder.setGroups("*").execute().actionGet();
    assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
    assertThat(stats.getTotal().search.getGroupStats().get("baz").getQueryCount(), greaterThan(0L));
    stats = builder.setGroups("*r").execute().actionGet();
    assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
    assertThat(stats.getTotal().search.getGroupStats().containsKey("baz"), is(false));
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequestBuilder(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder)

Example 15 with IndicesStatsResponse

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.

the class IndexStatsIT method testNonThrottleStats.

public void testNonThrottleStats() throws Exception {
    assertAcked(prepareCreate("test").setSettings(settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, "1").put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, "0").put(MergePolicyConfig.INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE_SETTING.getKey(), "2").put(MergePolicyConfig.INDEX_MERGE_POLICY_SEGMENTS_PER_TIER_SETTING.getKey(), "2").put(MergeSchedulerConfig.MAX_THREAD_COUNT_SETTING.getKey(), "1").put(MergeSchedulerConfig.MAX_MERGE_COUNT_SETTING.getKey(), "10000")));
    ensureGreen();
    long termUpto = 0;
    IndicesStatsResponse stats;
    // Provoke slowish merging by making many unique terms:
    for (int i = 0; i < 100; i++) {
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < 100; j++) {
            sb.append(' ');
            sb.append(termUpto++);
            sb.append(" some random text that keeps repeating over and over again hambone");
        }
        client().prepareIndex("test", "type", "" + termUpto).setSource("field" + (i % 10), sb.toString()).get();
    }
    refresh();
    stats = client().admin().indices().prepareStats().execute().actionGet();
    //nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).get();
    stats = client().admin().indices().prepareStats().execute().actionGet();
    assertThat(stats.getPrimaries().getIndexing().getTotal().getThrottleTime().millis(), equalTo(0L));
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)

Aggregations

IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)39 SearchResponse (org.elasticsearch.action.search.SearchResponse)9 NodesStatsResponse (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse)7 IndicesStatsRequest (org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)7 Settings (org.elasticsearch.common.settings.Settings)6 IndicesStatsRequestBuilder (org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder)5 ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)5 IOException (java.io.IOException)4 Locale (java.util.Locale)4 IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)4 GetResponse (org.elasticsearch.action.get.GetResponse)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Set (java.util.Set)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2