Search in sources :

Example 11 with FieldStats

use of org.elasticsearch.action.fieldstats.FieldStats 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)

Aggregations

FieldStats (org.elasticsearch.action.fieldstats.FieldStats)11 FieldStatsResponse (org.elasticsearch.action.fieldstats.FieldStatsResponse)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)2 UncheckedIOException (java.io.UncheckedIOException)1 Map (java.util.Map)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 LongPoint (org.apache.lucene.document.LongPoint)1 FieldInfo (org.apache.lucene.index.FieldInfo)1 IndexCommit (org.apache.lucene.index.IndexCommit)1 IndexReader (org.apache.lucene.index.IndexReader)1 SnapshotDeletionPolicy (org.apache.lucene.index.SnapshotDeletionPolicy)1 Terms (org.apache.lucene.index.Terms)1 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)1 BytesRef (org.apache.lucene.util.BytesRef)1 FixedBitSet (org.apache.lucene.util.FixedBitSet)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1