Search in sources :

Example 11 with Cardinality

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

the class CardinalityIT method testPartiallyUnmapped.

public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx", "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, numDocs);
}
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 12 with Cardinality

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

the class CardinalityIT method testMultiValuedNumericHashed.

public void testMultiValuedNumericHashed() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(multiNumericField(true))).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)

Example 13 with Cardinality

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

the class CardinalityIT method testMultiValuedNumericValueScript.

public void testMultiValuedNumericValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(multiNumericField(false)).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 14 with Cardinality

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

the class CardinalityIT method testMultiValuedStringScript.

public void testMultiValuedStringScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['str_values'].values", 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 15 with Cardinality

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

the class CardinalityIT method testSingleValuedNumericScript.

public void testSingleValuedNumericScript() throws Exception {
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc[' + singleNumericField() + '].value", emptyMap());
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(script)).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)

Aggregations

Cardinality (org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality)21 SearchResponse (org.elasticsearch.action.search.SearchResponse)20 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)19 Script (org.elasticsearch.script.Script)8 ImmutableMap (com.google.common.collect.ImmutableMap)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)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 FilterBuilders.andFilter (org.elasticsearch.index.query.FilterBuilders.andFilter)1