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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
Aggregations