Search in sources :

Example 16 with FieldStatsResponse

use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.

the class FieldStatsTests method testString.

public void testString() {
    createIndex("test", Settings.EMPTY, "test", "field_index", makeType("keyword", true, false, false), "field_dv", makeType("keyword", false, true, false), "field_stored", makeType("keyword", false, true, true), "field_source", makeType("keyword", false, false, false));
    for (int value = 0; value <= 10; value++) {
        String keyword = String.format(Locale.ENGLISH, "%03d", value);
        client().prepareIndex("test", "test").setSource("field_index", keyword, "field_dv", keyword, "field_stored", keyword, "field_source", keyword).get();
    }
    client().admin().indices().prepareRefresh().get();
    FieldStatsResponse result = client().prepareFieldStats().setFields("field_index", "field_dv", "field_stored", "field_source").get();
    assertEquals(result.getAllFieldStats().size(), 3);
    for (String field : new String[] { "field_index", "field_dv", "field_stored" }) {
        FieldStats stats = result.getAllFieldStats().get(field);
        assertEquals(stats.getMaxDoc(), 11L);
        assertEquals(stats.getDisplayType(), "string");
        if ("field_index".equals(field)) {
            assertEquals(stats.getMinValue(), new BytesRef(String.format(Locale.ENGLISH, "%03d", 0)));
            assertEquals(stats.getMaxValue(), new BytesRef(String.format(Locale.ENGLISH, "%03d", 10)));
            assertEquals(stats.getMinValueAsString(), String.format(Locale.ENGLISH, "%03d", 0));
            assertEquals(stats.getMaxValueAsString(), String.format(Locale.ENGLISH, "%03d", 10));
            assertEquals(stats.getDocCount(), 11L);
            assertEquals(stats.getDensity(), 100);
        } else {
            assertEquals(stats.getDocCount(), 0L);
            assertNull(stats.getMinValue());
            assertNull(stats.getMaxValue());
            assertEquals(stats.getDensity(), 0);
        }
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) IndexConstraint(org.elasticsearch.action.fieldstats.IndexConstraint) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse) BytesRef(org.apache.lucene.util.BytesRef) FieldStats(org.elasticsearch.action.fieldstats.FieldStats)

Example 17 with FieldStatsResponse

use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.

the class FieldStatsTests method testDouble.

public void testDouble() {
    createIndex("test", Settings.EMPTY, "test", "field_index", makeType("double", true, false, false), "field_dv", makeType("double", false, true, false), "field_stored", makeType("double", false, true, true), "field_source", makeType("double", false, false, false));
    for (double value = -1; value <= 9; value++) {
        client().prepareIndex("test", "test").setSource("field_index", value, "field_dv", value, "field_stored", value, "field_source", value).get();
    }
    client().admin().indices().prepareRefresh().get();
    FieldStatsResponse result = client().prepareFieldStats().setFields("field_index", "field_dv", "field_stored", "field_source").get();
    for (String field : new String[] { "field_index", "field_dv", "field_stored" }) {
        FieldStats stats = result.getAllFieldStats().get(field);
        assertEquals(stats.getMaxDoc(), 11L);
        assertEquals(stats.getDisplayType(), "float");
        if ("field_index".equals(field)) {
            assertEquals(stats.getDocCount(), 11L);
            assertEquals(stats.getDensity(), 100);
            assertEquals(stats.getMinValue(), -1d);
            assertEquals(stats.getMaxValue(), 9d);
            assertEquals(stats.getMinValueAsString(), Double.toString(-1));
        } else {
            assertEquals(stats.getDocCount(), 0L);
            assertNull(stats.getMinValue());
            assertNull(stats.getMaxValue());
            assertEquals(stats.getDensity(), 0);
        }
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse) FieldStats(org.elasticsearch.action.fieldstats.FieldStats)

Example 18 with FieldStatsResponse

use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.

the class FieldStatsTests method testFloat.

public void testFloat() {
    String fieldName = "field";
    createIndex("test", Settings.EMPTY, "test", "field_index", makeType("float", true, false, false), "field_dv", makeType("float", false, true, false), "field_stored", makeType("float", false, true, true), "field_source", makeType("float", false, false, false));
    for (float value = -1; value <= 9; value++) {
        client().prepareIndex("test", "test").setSource("field_index", value, "field_dv", value, "field_stored", value, "field_source", value).get();
    }
    client().admin().indices().prepareRefresh().get();
    FieldStatsResponse result = client().prepareFieldStats().setFields("field_index", "field_dv", "field_stored", "field_source").get();
    for (String field : new String[] { "field_index", "field_dv", "field_stored" }) {
        FieldStats stats = result.getAllFieldStats().get(field);
        assertEquals(stats.getMaxDoc(), 11L);
        assertEquals(stats.getDisplayType(), "float");
        if (field.equals("field_index")) {
            assertEquals(stats.getDocCount(), 11L);
            assertEquals(stats.getDensity(), 100);
            assertEquals(stats.getMinValue(), -1d);
            assertEquals(stats.getMaxValue(), 9d);
            assertEquals(stats.getMinValueAsString(), Float.toString(-1));
            assertEquals(stats.getMaxValueAsString(), Float.toString(9));
        } else {
            assertEquals(stats.getDocCount(), 0L);
            assertNull(stats.getMinValue());
            assertNull(stats.getMaxValue());
            assertEquals(stats.getDensity(), 0);
        }
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse) FieldStats(org.elasticsearch.action.fieldstats.FieldStats)

Example 19 with FieldStatsResponse

use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.

the class FieldStatsTests method testNumberFiltering.

public void testNumberFiltering() {
    createIndex("test1", Settings.EMPTY, "type", "value", "type=long");
    client().prepareIndex("test1", "test").setSource("value", 1L).get();
    createIndex("test2", Settings.EMPTY, "type", "value", "type=long");
    client().prepareIndex("test2", "test").setSource("value", 3L).get();
    client().admin().indices().prepareRefresh().get();
    FieldStatsResponse response = client().prepareFieldStats().setFields("value").setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 2);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "-1"), new IndexConstraint("value", MAX, LTE, "0")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "0"), new IndexConstraint("value", MAX, LT, "1")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "0"), new IndexConstraint("value", MAX, LTE, "1")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "1"), new IndexConstraint("value", MAX, LTE, "2")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "1"), new IndexConstraint("value", MAX, LTE, "2")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "2"), new IndexConstraint("value", MAX, LTE, "3")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "3"), new IndexConstraint("value", MAX, LTE, "4")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 1);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "3"), new IndexConstraint("value", MAX, LTE, "4")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GTE, "1"), new IndexConstraint("value", MAX, LTE, "3")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 2);
    assertEquals(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), 1L);
    assertEquals(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), 3L);
    response = client().prepareFieldStats().setFields("value").setIndexContraints(new IndexConstraint("value", MIN, GT, "1"), new IndexConstraint("value", MAX, LT, "3")).setLevel("indices").get();
    assertEquals(response.getIndicesMergedFieldStats().size(), 0);
}
Also used : IndexConstraint(org.elasticsearch.action.fieldstats.IndexConstraint) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse)

Aggregations

FieldStatsResponse (org.elasticsearch.action.fieldstats.FieldStatsResponse)19 IndexConstraint (org.elasticsearch.action.fieldstats.IndexConstraint)6 FieldStats (org.elasticsearch.action.fieldstats.FieldStats)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 BytesRef (org.apache.lucene.util.BytesRef)3 GeoPoint (org.elasticsearch.common.geo.GeoPoint)2 DateTime (org.joda.time.DateTime)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 HalfFloatPoint (org.apache.lucene.document.HalfFloatPoint)1 ActionRequestValidationException (org.elasticsearch.action.ActionRequestValidationException)1 FieldStatsRequest (org.elasticsearch.action.fieldstats.FieldStatsRequest)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1