Search in sources :

Example 6 with IndicesStatsRequestBuilder

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

the class IndexStatsIT method testFieldDataFieldsParam.

public void testFieldDataFieldsParam() throws Exception {
    assertAcked(client().admin().indices().prepareCreate("test1").addMapping("type", "bar", "type=text,fielddata=true", "baz", "type=text,fielddata=true").get());
    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();
    client().prepareSearch("_all").addSort("bar", SortOrder.ASC).addSort("baz", SortOrder.ASC).execute().actionGet();
    IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
    IndicesStatsResponse stats = builder.execute().actionGet();
    assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields(), is(nullValue()));
    stats = builder.setFieldDataFields("bar").execute().actionGet();
    assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
    assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(false));
    stats = builder.setFieldDataFields("bar", "baz").execute().actionGet();
    assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
    assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(true));
    assertThat(stats.getTotal().fieldData.getFields().get("baz"), greaterThan(0L));
    stats = builder.setFieldDataFields("*").execute().actionGet();
    assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
    assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(true));
    assertThat(stats.getTotal().fieldData.getFields().get("baz"), greaterThan(0L));
    stats = builder.setFieldDataFields("*r").execute().actionGet();
    assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
    assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
    assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(false));
}
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