use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.
the class FieldStatsIntegrationIT method testIncompatibleFieldTypesMultipleFields.
public void testIncompatibleFieldTypesMultipleFields() {
assertAcked(prepareCreate("test1").addMapping("test", "value", "type=long", "value2", "type=long"));
assertAcked(prepareCreate("test2").addMapping("test", "value", "type=text", "value2", "type=long"));
ensureGreen("test1", "test2");
client().prepareIndex("test1", "test").setSource("value", 1L, "value2", 1L).get();
client().prepareIndex("test1", "test").setSource("value", 2L).get();
client().prepareIndex("test2", "test").setSource("value", "a").get();
client().prepareIndex("test2", "test").setSource("value", "b").get();
refresh();
FieldStatsResponse response = client().prepareFieldStats().setFields("value", "value2").get();
assertAllSuccessful(response);
assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
assertThat(response.getIndicesMergedFieldStats().get("_all").size(), equalTo(1));
assertThat(response.getIndicesMergedFieldStats().get("_all").get("value2").getMinValue(), equalTo(1L));
assertThat(response.getIndicesMergedFieldStats().get("_all").get("value2").getMaxValue(), equalTo(1L));
assertThat(response.getConflicts().size(), equalTo(1));
assertThat(response.getConflicts().get("value"), equalTo("Field [value] of type [integer] conflicts with existing field of type [string] " + "in other index."));
response = client().prepareFieldStats().setFields("value", "value2").setLevel("indices").get();
assertAllSuccessful(response);
assertThat(response.getIndicesMergedFieldStats().size(), equalTo(2));
assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), equalTo(1L));
assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMaxValue(), equalTo(2L));
assertThat(response.getIndicesMergedFieldStats().get("test1").get("value2").getMinValue(), equalTo(1L));
assertThat(response.getIndicesMergedFieldStats().get("test1").get("value2").getMaxValue(), equalTo(1L));
assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), equalTo(new BytesRef("a")));
assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMaxValue(), equalTo(new BytesRef("b")));
assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getDisplayType(), equalTo("string"));
}
use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.
the class FieldStatsIntegrationIT method testCached.
public void testCached() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test").setSettings("index.number_of_replicas", 0));
indexRange("test", "value", 0, 99);
// First query should be a cache miss
FieldStatsResponse fieldStats = client().prepareFieldStats().setFields("value").get();
assertEquals(100, fieldStats.getAllFieldStats().get("value").getDocCount());
RequestCacheStats indexStats = client().admin().indices().prepareStats().get().getIndex("test").getTotal().getRequestCache();
assertEquals(0, indexStats.getHitCount());
assertThat(indexStats.getMemorySizeInBytes(), greaterThan(0L));
// Second query should be a cache hit
fieldStats = client().prepareFieldStats().setFields("value").get();
assertEquals(100, fieldStats.getAllFieldStats().get("value").getDocCount());
indexStats = client().admin().indices().prepareStats().get().getIndex("test").getTotal().getRequestCache();
assertThat(indexStats.getHitCount(), greaterThan(0L));
assertThat(indexStats.getMemorySizeInBytes(), greaterThan(0L));
// Indexing some new documents and refreshing should give you consistent data.
long oldHitCount = indexStats.getHitCount();
indexRange("test", "value", 100, 199);
fieldStats = client().prepareFieldStats().setFields("value").get();
assertEquals(200, fieldStats.getAllFieldStats().get("value").getDocCount());
// Because we refreshed the index we don't have any more hits in the cache. This is read from the index.
assertEquals(oldHitCount, indexStats.getHitCount());
// We can also turn off the cache entirely
fieldStats = client().prepareFieldStats().setFields("value").get();
assertEquals(200, fieldStats.getAllFieldStats().get("value").getDocCount());
assertEquals(oldHitCount, indexStats.getHitCount());
}
use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.
the class FieldStatsIntegrationIT method testIncompatibleFieldTypesSingleField.
public void testIncompatibleFieldTypesSingleField() {
assertAcked(prepareCreate("test1").addMapping("test", "value", "type=long"));
assertAcked(prepareCreate("test2").addMapping("test", "value", "type=text"));
ensureGreen("test1", "test2");
client().prepareIndex("test1", "test").setSource("value", 1L).get();
client().prepareIndex("test1", "test").setSource("value", 2L).get();
client().prepareIndex("test2", "test").setSource("value", "a").get();
client().prepareIndex("test2", "test").setSource("value", "b").get();
refresh();
FieldStatsResponse response = client().prepareFieldStats().setFields("value", "value2").get();
assertAllSuccessful(response);
assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
assertThat(response.getIndicesMergedFieldStats().get("_all").size(), equalTo(0));
assertThat(response.getConflicts().size(), equalTo(1));
assertThat(response.getConflicts().get("value"), equalTo("Field [value] of type [integer] conflicts with existing field of type [string] " + "in other index."));
response = client().prepareFieldStats().setFields("value").setLevel("indices").get();
assertAllSuccessful(response);
assertThat(response.getIndicesMergedFieldStats().size(), equalTo(2));
assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), equalTo(1L));
assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMaxValue(), equalTo(2L));
assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), equalTo(new BytesRef("a")));
assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMaxValue(), equalTo(new BytesRef("b")));
}
use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.
the class FieldStatsIntegrationIT method testGeoPointNotIndexed.
public void testGeoPointNotIndexed() throws Exception {
assertAcked(prepareCreate("test").addMapping("test", "value", "type=long", "location", "type=geo_point,index=false"));
ensureGreen("test");
client().prepareIndex("test", "test").setSource("value", 1L, "location", new GeoPoint(32, -132)).get();
client().prepareIndex("test", "test").setSource("value", 2L).get();
client().prepareIndex("test", "test").setSource("value", 3L).get();
client().prepareIndex("test", "test").setSource("value", 4L).get();
refresh();
FieldStatsResponse response = client().prepareFieldStats().setFields("value", "location").get();
assertAllSuccessful(response);
assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
assertThat(response.getAllFieldStats().get("location").getMinValue(), equalTo(null));
assertThat(response.getAllFieldStats().get("location").getMaxValue(), equalTo(null));
assertThat(response.getAllFieldStats().get("location").isAggregatable(), equalTo(true));
assertThat(response.getAllFieldStats().get("location").isSearchable(), equalTo(false));
}
use of org.elasticsearch.action.fieldstats.FieldStatsResponse in project elasticsearch by elastic.
the class FieldStatsTests method testNumberRange.
private void testNumberRange(String fieldName, String fieldType, long min, long max) {
createIndex("test", Settings.EMPTY, "test", fieldName, "type=" + fieldType);
// index=false
createIndex("test1", Settings.EMPTY, "test", fieldName, "type=" + fieldType + ",index=false");
// no value
createIndex("test2", Settings.EMPTY, "test", fieldName, "type=" + fieldType);
for (long value = min; value <= max; value++) {
client().prepareIndex("test", "test").setSource(fieldName, value).get();
}
client().admin().indices().prepareRefresh().get();
FieldStatsResponse result = client().prepareFieldStats().setFields(fieldName).get();
long numDocs = max - min + 1;
assertEquals(result.getAllFieldStats().get(fieldName).getMaxDoc(), numDocs);
assertEquals(result.getAllFieldStats().get(fieldName).getDocCount(), numDocs);
assertEquals(result.getAllFieldStats().get(fieldName).getDensity(), 100);
assertEquals(result.getAllFieldStats().get(fieldName).getMinValue(), min);
assertEquals(result.getAllFieldStats().get(fieldName).getMaxValue(), max);
assertEquals(result.getAllFieldStats().get(fieldName).getMinValueAsString(), java.lang.Long.toString(min));
assertEquals(result.getAllFieldStats().get(fieldName).getMaxValueAsString(), java.lang.Long.toString(max));
assertEquals(result.getAllFieldStats().get(fieldName).isSearchable(), true);
assertEquals(result.getAllFieldStats().get(fieldName).isAggregatable(), true);
if (fieldType.equals("float") || fieldType.equals("double") || fieldType.equals("half-float")) {
assertEquals(result.getAllFieldStats().get(fieldName).getDisplayType(), "float");
} else {
assertEquals(result.getAllFieldStats().get(fieldName).getDisplayType(), "integer");
}
client().admin().indices().prepareDelete("test").get();
client().admin().indices().prepareDelete("test1").get();
client().admin().indices().prepareDelete("test2").get();
}
Aggregations