Search in sources :

Example 6 with ValueCount

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));
}
Also used : LeafSearchScript(org.elasticsearch.script.LeafSearchScript) SearchScript(org.elasticsearch.script.SearchScript) Script(org.elasticsearch.script.Script) CompiledScript(org.elasticsearch.script.CompiledScript) ExecutableScript(org.elasticsearch.script.ExecutableScript) ValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 7 with ValueCount

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));
}
Also used : ValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount) Global(org.elasticsearch.search.aggregations.bucket.global.Global) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 8 with ValueCount

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));
}
Also used : LeafSearchScript(org.elasticsearch.script.LeafSearchScript) SearchScript(org.elasticsearch.script.SearchScript) Script(org.elasticsearch.script.Script) CompiledScript(org.elasticsearch.script.CompiledScript) ExecutableScript(org.elasticsearch.script.ExecutableScript) ValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 9 with ValueCount

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));
}
Also used : ValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 10 with ValueCount

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));
}
Also used : ValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchResponse (org.elasticsearch.action.search.SearchResponse)11 ValueCount (org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount)11 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)11 CompiledScript (org.elasticsearch.script.CompiledScript)4 ExecutableScript (org.elasticsearch.script.ExecutableScript)4 LeafSearchScript (org.elasticsearch.script.LeafSearchScript)4 Script (org.elasticsearch.script.Script)4 SearchScript (org.elasticsearch.script.SearchScript)4 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 AggregationBuilders.reverseNested (org.elasticsearch.search.aggregations.AggregationBuilders.reverseNested)1 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)1 Global (org.elasticsearch.search.aggregations.bucket.global.Global)1 Nested (org.elasticsearch.search.aggregations.bucket.nested.Nested)1 ReverseNested (org.elasticsearch.search.aggregations.bucket.nested.ReverseNested)1 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)1