use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class StringTermsIT method testSingleValuedFieldWithSubAggregation.
public void testSingleValuedFieldWithSubAggregation() throws Exception {
SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())).subAggregation(count("count").field(MULTI_VALUED_FIELD_NAME))).execute().actionGet();
assertSearchResponse(response);
Terms terms = response.getAggregations().get("terms");
assertThat(terms, notNullValue());
assertThat(terms.getName(), equalTo("terms"));
assertThat(terms.getBuckets().size(), equalTo(5));
Object[] propertiesKeys = (Object[]) terms.getProperty("_key");
Object[] propertiesDocCounts = (Object[]) terms.getProperty("_count");
Object[] propertiesCounts = (Object[]) terms.getProperty("count.value");
for (int i = 0; i < 5; i++) {
Terms.Bucket bucket = terms.getBucketByKey("val" + i);
assertThat(bucket, notNullValue());
assertThat(key(bucket), equalTo("val" + i));
assertThat(bucket.getDocCount(), equalTo(1L));
ValueCount valueCount = bucket.getAggregations().get("count");
assertThat(valueCount, notNullValue());
assertThat(valueCount.getValue(), equalTo(2L));
assertThat((String) propertiesKeys[i], equalTo("val" + i));
assertThat((long) propertiesDocCounts[i], equalTo(1L));
assertThat((double) propertiesCounts[i], equalTo(2.0));
}
}
use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testSingleValuedScriptWithParams.
public void testSingleValuedScriptWithParams() throws Exception {
Map<String, Object> params = Collections.singletonMap("s", "value");
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(10L));
}
use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testMultiValuedField.
public void testMultiValuedField() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(count("count").field("values")).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 testMultiValuedScript.
public void testMultiValuedScript() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(count("count").script(new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "values", 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(20L));
}
use of org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount in project elasticsearch by elastic.
the class ValueCountIT method testSingleValuedField.
public void testSingleValuedField() throws Exception {
SearchResponse searchResponse = client().prepareSearch("idx").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