Search in sources :

Example 1 with IndicesStatsRequestBuilder

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder 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 2 with IndicesStatsRequestBuilder

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder 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 3 with IndicesStatsRequestBuilder

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder 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 4 with IndicesStatsRequestBuilder

use of org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder 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 5 with IndicesStatsRequestBuilder

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

the class IndexStatsIT method testMultiIndex.

public void testMultiIndex() throws Exception {
    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();
    refresh();
    int numShards1 = getNumShards("test1").totalNumShards;
    int numShards2 = getNumShards("test2").totalNumShards;
    IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
    IndicesStatsResponse stats = builder.execute().actionGet();
    assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
    stats = builder.setIndices("_all").execute().actionGet();
    assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
    stats = builder.setIndices("_all").execute().actionGet();
    assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
    stats = builder.setIndices("*").execute().actionGet();
    assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
    stats = builder.setIndices("test1").execute().actionGet();
    assertThat(stats.getTotalShards(), equalTo(numShards1));
    stats = builder.setIndices("test1", "test2").execute().actionGet();
    assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
    stats = builder.setIndices("*2").execute().actionGet();
    assertThat(stats.getTotalShards(), equalTo(numShards2));
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequestBuilder(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder)

Aggregations

IndicesStatsRequestBuilder (org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder)6 IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)6 Random (java.util.Random)1 Flag (org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag)1