use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testMultiValuedScriptWithParams.
public void testMultiValuedScriptWithParams() throws Exception {
Map<String, Object> params = Collections.singletonMap("s", "values");
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(count("count").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", params))).execute().actionGet();
assertHitCount(searchResponse, 10);
ValueCount valueCount = searchResponse.getAggregations().get("count");
assertThat(valueCount, notNullValue());
assertThat(valueCount.getName(), equalTo("count"));
assertThat(valueCount.getValue(), equalTo(20L));
}
use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testSingleValuedFieldGetProperty.
public void testSingleValuedFieldGetProperty() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(count("count").field("value"))).execute().actionGet();
assertHitCount(searchResponse, 10);
Global global = searchResponse.getAggregations().get("global");
assertThat(global, notNullValue());
assertThat(global.getName(), equalTo("global"));
assertThat(global.getDocCount(), equalTo(10L));
assertThat(global.getAggregations(), notNullValue());
assertThat(global.getAggregations().asMap().size(), equalTo(1));
ValueCount valueCount = global.getAggregations().get("count");
assertThat(valueCount, notNullValue());
assertThat(valueCount.getName(), equalTo("count"));
assertThat(valueCount.getValue(), equalTo(10L));
assertThat((ValueCount) global.getProperty("count"), equalTo(valueCount));
assertThat((double) global.getProperty("count.value"), equalTo(10d));
assertThat((double) valueCount.getProperty("value"), equalTo(10d));
}
use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testSingleValuedScript.
public void testSingleValuedScript() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(count("count").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "value", Collections.emptyMap()))).execute().actionGet();
assertHitCount(searchResponse, 10);
ValueCount valueCount = searchResponse.getAggregations().get("count");
assertThat(valueCount, notNullValue());
assertThat(valueCount.getName(), equalTo("count"));
assertThat(valueCount.getValue(), equalTo(10L));
}
use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testUnmapped.
public void testUnmapped() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(count("count").field("value")).execute().actionGet();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
ValueCount valueCount = searchResponse.getAggregations().get("count");
assertThat(valueCount, notNullValue());
assertThat(valueCount.getName(), equalTo("count"));
assertThat(valueCount.getValue(), equalTo(0L));
}
use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testSingleValuedFieldPartiallyUnmapped.
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped").setQuery(matchAllQuery()).addAggregation(count("count").field("value")).execute().actionGet();
assertHitCount(searchResponse, 10);
ValueCount valueCount = searchResponse.getAggregations().get("count");
assertThat(valueCount, notNullValue());
assertThat(valueCount.getName(), equalTo("count"));
assertThat(valueCount.getValue(), equalTo(10L));
}
Aggregations