Search in sources :

Example 1 with Cardinality

use of org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality in project elasticsearch by elastic.

the class MissingValueIT method testCardinality.

public void testCardinality() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(cardinality("card").field("long").missing(2)).get();
    assertSearchResponse(response);
    Cardinality cardinality = response.getAggregations().get("card");
    assertEquals(2, cardinality.getValue());
}
Also used : Cardinality(org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with Cardinality

use of org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality in project elasticsearch by elastic.

the class CardinalityIT method testUnmapped.

public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value")).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, 0);
}
Also used : Cardinality(org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 3 with Cardinality

use of org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality in project elasticsearch by elastic.

the class CardinalityIT method testSingleValuedNumericValueScript.

public void testSingleValuedNumericValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()).script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap()))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
Also used : Script(org.elasticsearch.script.Script) Cardinality(org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 4 with Cardinality

use of org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality in project elasticsearch by elastic.

the class CardinalityIT method testMultiValuedStringValueScript.

public void testMultiValuedStringValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_values").script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap()))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs * 2);
}
Also used : Script(org.elasticsearch.script.Script) Cardinality(org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 5 with Cardinality

use of org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality in project elasticsearch by elastic.

the class CardinalityIT method testMultiValuedNumeric.

public void testMultiValuedNumeric() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(multiNumericField(false))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs * 2);
}
Also used : Cardinality(org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

Cardinality (org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality)22 SearchResponse (org.elasticsearch.action.search.SearchResponse)20 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)19 Script (org.elasticsearch.script.Script)8 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Aggregations (org.elasticsearch.search.aggregations.Aggregations)2 AuthorisationException (com.atlassian.stash.exception.AuthorisationException)1 Repository (com.atlassian.stash.repository.Repository)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 GlobalSettings (com.palantir.stash.codesearch.admin.GlobalSettings)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)1