org.elasticsearch.action.search.SearchResponse

Here are the examples of the java api class org.elasticsearch.action.search.SearchResponse taken from open source projects.

1. OpenNlpPluginIntegrationTest#testThatOwnAnalyzersCanBeDefinedPerNlpMappedField()

View license
@Test
public void testThatOwnAnalyzersCanBeDefinedPerNlpMappedField() throws IOException {
    putMapping("/test-mapping-analyzers.json");
    String sampleText = copyToStringFromClasspath("/sample-text.txt");
    IndexResponse indexResponse = indexElement(sampleText);
    SearchResponse nonAnalyzedFieldSearchResponse = query(QueryBuilders.termQuery("someField.name", "jack"));
    assertThat(nonAnalyzedFieldSearchResponse.getHits().totalHits(), is(1L));
    // analyzed, therefore not resulting anything like the above query
    SearchResponse analyzedFieldSearchResponse = query(QueryBuilders.termQuery("someFieldAnalyzed.name", "jack"));
    assertThat(analyzedFieldSearchResponse.getHits().totalHits(), is(0L));
    SearchResponse searchResponse = query(QueryBuilders.prefixQuery("someFieldAnalyzed.name", "Jack"));
    assertThat(searchResponse.getHits().totalHits(), is(1L));
    searchResponse = query(QueryBuilders.matchQuery("someFieldAnalyzed.name", "Jack Nicholson"));
    assertThat(searchResponse.getHits().totalHits(), is(1L));
    assertThat(searchResponse.getHits().getAt(0).id(), is(indexResponse.getId()));
}

2. SuggestSearchTests#searchSuggest()

View license
protected Suggest searchSuggest(String suggestText, int expectShardsFailed, Map<String, SuggestionBuilder<?>> suggestions) {
    SearchRequestBuilder builder = client().prepareSearch().setSize(0);
    SuggestBuilder suggestBuilder = new SuggestBuilder();
    if (suggestText != null) {
        suggestBuilder.setGlobalText(suggestText);
    }
    for (Entry<String, SuggestionBuilder<?>> suggestion : suggestions.entrySet()) {
        suggestBuilder.addSuggestion(suggestion.getKey(), suggestion.getValue());
    }
    builder.suggest(suggestBuilder);
    SearchResponse actionGet = builder.execute().actionGet();
    assertThat(Arrays.toString(actionGet.getShardFailures()), actionGet.getFailedShards(), equalTo(expectShardsFailed));
    return actionGet.getSuggest();
}

3. AggregationTest#testFromSizeWithAggregations()

View license
@Test
public void testFromSizeWithAggregations() throws Exception {
    final String query1 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(0,1) */" + " account_number FROM %s/account GROUP BY gender", TEST_INDEX);
    SearchResponse response1 = (SearchResponse) getSearchRequestBuilder(query1).get();
    Assert.assertEquals(1, response1.getHits().getHits().length);
    Terms gender1 = response1.getAggregations().get("gender");
    Assert.assertEquals(2, gender1.getBuckets().size());
    Object account1 = response1.getHits().getHits()[0].getSource().get("account_number");
    final String query2 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(1,1) */" + " account_number FROM %s/account GROUP BY gender", TEST_INDEX);
    SearchResponse response2 = (SearchResponse) getSearchRequestBuilder(query2).get();
    Assert.assertEquals(1, response2.getHits().getHits().length);
    Terms gender2 = response2.getAggregations().get("gender");
    Assert.assertEquals(2, gender2.getBuckets().size());
    Object account2 = response2.getHits().getHits()[0].getSource().get("account_number");
    Assert.assertEquals(response1.getHits().getTotalHits(), response2.getHits().getTotalHits());
    Assert.assertNotEquals(account1, account2);
}

4. FieldSortIT#testIssue2986()

Project: elasticsearch
Source File: FieldSortIT.java
View license
public void testIssue2986() {
    assertAcked(client().admin().indices().prepareCreate("test").addMapping("type", "field1", "type=keyword").get());
    client().prepareIndex("test", "post", "1").setSource("{\"field1\":\"value1\"}").execute().actionGet();
    client().prepareIndex("test", "post", "2").setSource("{\"field1\":\"value2\"}").execute().actionGet();
    client().prepareIndex("test", "post", "3").setSource("{\"field1\":\"value3\"}").execute().actionGet();
    refresh();
    SearchResponse result = client().prepareSearch("test").setQuery(matchAllQuery()).setTrackScores(true).addSort("field1", SortOrder.ASC).execute().actionGet();
    for (SearchHit hit : result.getHits()) {
        assertFalse(Float.isNaN(hit.getScore()));
    }
}

5. GeoPolygonIT#testSimplePolygon()

Project: elasticsearch
Source File: GeoPolygonIT.java
View license
public void testSimplePolygon() throws Exception {
    List<GeoPoint> points = new ArrayList<>();
    points.add(new GeoPoint(40.7, -74.0));
    points.add(new GeoPoint(40.7, -74.1));
    points.add(new GeoPoint(40.8, -74.1));
    points.add(new GeoPoint(40.8, -74.0));
    points.add(new GeoPoint(40.7, -74.0));
    SearchResponse searchResponse = // from NY
    client().prepareSearch("test").setQuery(boolQuery().must(geoPolygonQuery("location", points))).execute().actionGet();
    assertHitCount(searchResponse, 4);
    assertThat(searchResponse.getHits().hits().length, equalTo(4));
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.id(), anyOf(equalTo("1"), equalTo("3"), equalTo("4"), equalTo("5")));
    }
}

6. GeoPolygonIT#testSimpleUnclosedPolygon()

Project: elasticsearch
Source File: GeoPolygonIT.java
View license
public void testSimpleUnclosedPolygon() throws Exception {
    List<GeoPoint> points = new ArrayList<>();
    points.add(new GeoPoint(40.7, -74.0));
    points.add(new GeoPoint(40.7, -74.1));
    points.add(new GeoPoint(40.8, -74.1));
    points.add(new GeoPoint(40.8, -74.0));
    SearchResponse searchResponse = // from NY
    client().prepareSearch("test").setQuery(boolQuery().must(geoPolygonQuery("location", points))).execute().actionGet();
    assertHitCount(searchResponse, 4);
    assertThat(searchResponse.getHits().hits().length, equalTo(4));
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.id(), anyOf(equalTo("1"), equalTo("3"), equalTo("4"), equalTo("5")));
    }
}

7. FsCrawlerImplAllParametersTest#test_filesize_limit()

View license
@Test
public void test_filesize_limit() throws Exception {
    Fs fs = startCrawlerDefinition().setIndexedChars(new Percentage(7)).build();
    startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1, null, null, "*");
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.CONTENT), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXED_CHARS), notNullValue());
        // Our original text: "Bonjour David..." should be truncated
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.CONTENT).getValue(), is("Bonjour"));
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXED_CHARS).getValue(), is(7L));
    }
}

8. FsCrawlerImplAllParametersTest#test_filesize_limit_percentage()

View license
@Test
public void test_filesize_limit_percentage() throws Exception {
    Fs fs = startCrawlerDefinition().setIndexedChars(Percentage.parse("0.1%")).build();
    startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1, null, null, "*");
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.CONTENT), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXED_CHARS), notNullValue());
        // Our original text: "Bonjour David..." should be truncated
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.CONTENT).getValue(), is("Bonjour "));
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXED_CHARS).getValue(), is(8L));
    }
}

9. FsCrawlerImplAllParametersTest#test_filesize_nolimit()

View license
@Test
public void test_filesize_nolimit() throws Exception {
    Fs fs = startCrawlerDefinition().setIndexedChars(new Percentage(-1)).build();
    startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1, null, null, "*");
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.CONTENT), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXED_CHARS), nullValue());
        // Our original text: "Bonjour David\n\n\n" should not be truncated
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.CONTENT).getValue(), is("Bonjour David\n\n\n"));
    }
}

10. FsCrawlerImplAllParametersTest#test_filesize_disabled()

View license
@Test
public void test_filesize_disabled() throws Exception {
    Fs fs = startCrawlerDefinition().setAddFilesize(false).build();
    startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1);
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getFields().get("filesize"), nullValue());
    }
}

11. FsCrawlerImplAllParametersTest#test_metadata()

View license
@Test
public void test_metadata() throws Exception {
    Fs fs = startCrawlerDefinition().setIndexedChars(new Percentage(1)).build();
    startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1, null, null, "*");
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.FILENAME), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.CONTENT_TYPE), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.URL), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.FILESIZE), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXING_DATE), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXED_CHARS), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.LAST_MODIFIED), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.META + "." + FsCrawlerUtil.Doc.Meta.TITLE), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.META + "." + FsCrawlerUtil.Doc.Meta.KEYWORDS), notNullValue());
    }
}

12. FsCrawlerImplAllParametersTest#test_default_metadata()

View license
@Test
public void test_default_metadata() throws Exception {
    startCrawler();
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1, null, null, "*");
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.ATTACHMENT), nullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.FILENAME), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.CONTENT_TYPE), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.URL), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.FILESIZE), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXING_DATE), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.INDEXED_CHARS), nullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.FILE + "." + FsCrawlerUtil.Doc.File.LAST_MODIFIED), notNullValue());
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.META + "." + FsCrawlerUtil.Doc.Meta.TITLE), notNullValue());
    }
}

13. FsCrawlerImplAllParametersTest#test_store_source()

View license
@Test
public void test_store_source() throws Exception {
    Fs fs = startCrawlerDefinition().setStoreSource(true).build();
    startCrawler(getCrawlerName(), fs, endCrawlerDefinition(getCrawlerName()), null);
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1, null, null, "_source", "*");
    for (SearchHit hit : searchResponse.getHits()) {
        // We check that the field has been stored
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.ATTACHMENT), notNullValue());
        // We check that the field is not part of _source
        assertThat(hit.getSource().get(FsCrawlerUtil.Doc.ATTACHMENT), nullValue());
    }
}

14. FsCrawlerImplAllParametersTest#test_do_not_store_source()

View license
@Test
public void test_do_not_store_source() throws Exception {
    startCrawler();
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1, null, null, "_source", "*");
    for (SearchHit hit : searchResponse.getHits()) {
        // We check that the field has not been stored
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.ATTACHMENT), nullValue());
        // We check that the field is not part of _source
        assertThat(hit.getSource().get(FsCrawlerUtil.Doc.ATTACHMENT), nullValue());
    }
}

15. FsCrawlerImplAllParametersTest#test_defaults()

View license
@Test
public void test_defaults() throws Exception {
    startCrawler();
    // We expect to have one file
    SearchResponse searchResponse = countTestHelper(getCrawlerName(), null, 1);
    // The default configuration should not add file attributes
    for (SearchHit hit : searchResponse.getHits()) {
        assertThat(hit.getFields().get(FsCrawlerUtil.Doc.ATTRIBUTES + "." + FsCrawlerUtil.Doc.Attributes.OWNER), nullValue());
    }
}

16. ESIndexer#search()

Project: Kundera
Source File: ESIndexer.java
View license
/*
     * (non-Javadoc)
     * 
     * @see com.impetus.kundera.index.Indexer#search(java.lang.Class,
     * com.impetus.kundera.metadata.model.EntityMetadata, java.lang.String, int,
     * int)
     */
@Override
public Map<String, Object> search(Class<?> clazz, EntityMetadata m, String luceneQuery, int start, int count) {
    if (log.isInfoEnabled()) {
        log.info("Executing lucene query " + luceneQuery);
    }
    ListenableActionFuture<SearchResponse> listenableActionFuture = client.prepareSearch(m.getSchema().toLowerCase()).setQuery(QueryBuilders.queryStringQuery(luceneQuery)).setSize(40000).execute();
    SearchResponse response = listenableActionFuture.actionGet();
    Map<String, Object> results = new HashMap<String, Object>();
    for (SearchHit hit : response.getHits()) {
        Object id = PropertyAccessorHelper.fromSourceToTargetClass(((AbstractAttribute) m.getIdAttribute()).getBindableJavaType(), String.class, hit.getId());
        results.put(hit.getId(), id);
    }
    return results;
}

17. ElasticSearchState#search()

View license
/**
     * It basically searches and returns a set of tweet ids for a given keyword.
     *
     * @param keyword
     * @return
     */
public Set<String> search(String keyword) {
    SearchResponse response;
    try {
        response = client.prepareSearch().setIndices("hackaton").setTypes("tweets").addFields("id", "text").setQuery(QueryBuilders.fieldQuery("text", keyword)).execute().actionGet();
    } catch (Throwable e) {
        return new HashSet<String>();
    }
    Set<String> result = new HashSet<String>();
    for (SearchHit hit : response.getHits()) {
        Long id = hit.field("id").<Long>getValue();
        result.add(String.valueOf(id));
    }
    return result;
}

18. MatchedQueriesIT#testRegExpQuerySupportsName()

Project: elasticsearch
Source File: MatchedQueriesIT.java
View license
public void testRegExpQuerySupportsName() {
    createIndex("test1");
    ensureGreen();
    client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.regexpQuery("title", "title1").queryName("regex")).get();
    assertHitCount(searchResponse, 1L);
    for (SearchHit hit : searchResponse.getHits()) {
        if (hit.id().equals("1")) {
            assertThat(hit.matchedQueries().length, equalTo(1));
            assertThat(hit.matchedQueries(), hasItemInArray("regex"));
        } else {
            fail("Unexpected document returned with id " + hit.id());
        }
    }
}

19. MatchedQueriesIT#testPrefixQuerySupportsName()

Project: elasticsearch
Source File: MatchedQueriesIT.java
View license
public void testPrefixQuerySupportsName() {
    createIndex("test1");
    ensureGreen();
    client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.prefixQuery("title", "title").queryName("prefix")).get();
    assertHitCount(searchResponse, 1L);
    for (SearchHit hit : searchResponse.getHits()) {
        if (hit.id().equals("1")) {
            assertThat(hit.matchedQueries().length, equalTo(1));
            assertThat(hit.matchedQueries(), hasItemInArray("prefix"));
        } else {
            fail("Unexpected document returned with id " + hit.id());
        }
    }
}

20. MatchedQueriesIT#testFuzzyQuerySupportsName()

Project: elasticsearch
Source File: MatchedQueriesIT.java
View license
public void testFuzzyQuerySupportsName() {
    createIndex("test1");
    ensureGreen();
    client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.fuzzyQuery("title", "titel1").queryName("fuzzy")).get();
    assertHitCount(searchResponse, 1L);
    for (SearchHit hit : searchResponse.getHits()) {
        if (hit.id().equals("1")) {
            assertThat(hit.matchedQueries().length, equalTo(1));
            assertThat(hit.matchedQueries(), hasItemInArray("fuzzy"));
        } else {
            fail("Unexpected document returned with id " + hit.id());
        }
    }
}

21. MatchedQueriesIT#testWildcardQuerySupportsName()

Project: elasticsearch
Source File: MatchedQueriesIT.java
View license
public void testWildcardQuerySupportsName() {
    createIndex("test1");
    ensureGreen();
    client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.wildcardQuery("title", "titl*").queryName("wildcard")).get();
    assertHitCount(searchResponse, 1L);
    for (SearchHit hit : searchResponse.getHits()) {
        if (hit.id().equals("1")) {
            assertThat(hit.matchedQueries().length, equalTo(1));
            assertThat(hit.matchedQueries(), hasItemInArray("wildcard"));
        } else {
            fail("Unexpected document returned with id " + hit.id());
        }
    }
}

22. MatchedQueriesIT#testSpanFirstQuerySupportsName()

Project: elasticsearch
Source File: MatchedQueriesIT.java
View license
public void testSpanFirstQuerySupportsName() {
    createIndex("test1");
    ensureGreen();
    client().prepareIndex("test1", "type1", "1").setSource("title", "title1 title2").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.spanFirstQuery(QueryBuilders.spanTermQuery("title", "title1"), 10).queryName("span")).get();
    assertHitCount(searchResponse, 1L);
    for (SearchHit hit : searchResponse.getHits()) {
        if (hit.id().equals("1")) {
            assertThat(hit.matchedQueries().length, equalTo(1));
            assertThat(hit.matchedQueries(), hasItemInArray("span"));
        } else {
            fail("Unexpected document returned with id " + hit.id());
        }
    }
}

23. SuggestSearchIT#searchSuggest()

Project: elasticsearch
Source File: SuggestSearchIT.java
View license
protected Suggest searchSuggest(String suggestText, int expectShardsFailed, Map<String, SuggestionBuilder<?>> suggestions) {
    SearchRequestBuilder builder = client().prepareSearch().setSize(0);
    SuggestBuilder suggestBuilder = new SuggestBuilder();
    if (suggestText != null) {
        suggestBuilder.setGlobalText(suggestText);
    }
    for (Entry<String, SuggestionBuilder<?>> suggestion : suggestions.entrySet()) {
        suggestBuilder.addSuggestion(suggestion.getKey(), suggestion.getValue());
    }
    builder.suggest(suggestBuilder);
    SearchResponse actionGet = builder.execute().actionGet();
    assertThat(Arrays.toString(actionGet.getShardFailures()), actionGet.getFailedShards(), equalTo(expectShardsFailed));
    return actionGet.getSuggest();
}

24. AvgIT#testEmptyAggregation()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx").setQuery(matchAllQuery()).addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0).subAggregation(avg("avg").field("value"))).execute().actionGet();
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    Histogram histo = searchResponse.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    Histogram.Bucket bucket = histo.getBuckets().get(1);
    assertThat(bucket, notNullValue());
    Avg avg = bucket.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(Double.isNaN(avg.getValue()), is(true));
}

25. DoubleTermsTests#testPartiallyUnmapped()

Project: elasticsearch
Source File: DoubleTermsTests.java
View license
public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    assertThat(terms.getBuckets().size(), equalTo(5));
    for (int i = 0; i < 5; i++) {
        Terms.Bucket bucket = terms.getBucketByKey("" + (double) i);
        assertThat(bucket, notNullValue());
        assertThat(key(bucket), equalTo("" + (double) i));
        assertThat(bucket.getKeyAsNumber().intValue(), equalTo(i));
        assertThat(bucket.getDocCount(), equalTo(1L));
    }
}

26. AvgIT#testUnmapped()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(avg("avg").field("value")).execute().actionGet();
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo(Double.NaN));
}

27. AvgIT#testSingleValuedField()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testSingleValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10));
}

28. AvgIT#testSingleValuedFieldGetProperty()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(avg("avg").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));
    Avg avg = global.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    double expectedAvgValue = (double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10;
    assertThat(avg.getValue(), equalTo(expectedAvgValue));
    assertThat((Avg) global.getProperty("avg"), equalTo(avg));
    assertThat((double) global.getProperty("avg.value"), equalTo(expectedAvgValue));
    assertThat((double) avg.getProperty("value"), equalTo(expectedAvgValue));
}

29. AvgIT#testSingleValuedFieldPartiallyUnmapped()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped").setQuery(matchAllQuery()).addAggregation(avg("avg").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10));
}

30. AvgIT#testSingleValuedFieldWithValueScript()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testSingleValuedFieldWithValueScript() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").field("value").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10));
}

31. AvgIT#testSingleValuedFieldWithValueScriptWithParams()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testSingleValuedFieldWithValueScriptWithParams() throws Exception {
    Map<String, Object> params = Collections.singletonMap("inc", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").field("value").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11) / 10));
}

32. AvgIT#testSingleValuedField_WithFormatter()

Project: elasticsearch
Source File: AvgIT.java
View license
public void testSingleValuedField_WithFormatter() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").format("#").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10));
    assertThat(avg.getValueAsString(), equalTo("6"));
}

33. AvgIT#testMultiValuedField()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testMultiValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").field("values")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12) / 20));
}

34. AvgIT#testMultiValuedFieldWithValueScript()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testMultiValuedFieldWithValueScript() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").field("values").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12) / 20));
}

35. AvgIT#testMultiValuedFieldWithValueScriptWithParams()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testMultiValuedFieldWithValueScriptWithParams() throws Exception {
    Map<String, Object> params = Collections.singletonMap("inc", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").field("values").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12 + 12 + 13) / 20));
}

36. AvgIT#testScriptSingleValued()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testScriptSingleValued() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10));
}

37. AvgIT#testScriptSingleValuedWithParams()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testScriptSingleValuedWithParams() throws Exception {
    Map<String, Object> params = Collections.singletonMap("inc", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11) / 10));
}

38. AvgIT#testScriptMultiValued()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testScriptMultiValued() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12) / 20));
}

39. AvgIT#testScriptMultiValuedWithParams()

Project: elasticsearch
Source File: AvgIT.java
View license
@Override
public void testScriptMultiValuedWithParams() throws Exception {
    Map<String, Object> params = Collections.singletonMap("inc", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(avg("avg").script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Avg avg = searchResponse.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    assertThat(avg.getValue(), equalTo((double) (3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12 + 12 + 13) / 20));
}

40. GeoBoundsIT#testSingleValuedField()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testSingleValuedField() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE));
}

41. GeoBoundsIT#testMultiValuedField()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testMultiValuedField() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME).addAggregation(geoBounds(aggName).field(MULTI_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(multiTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(multiTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(multiBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(multiBottomRight.lon(), GEOHASH_TOLERANCE));
}

42. GeoBoundsIT#testUnmapped()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(UNMAPPED_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft, equalTo(null));
    assertThat(bottomRight, equalTo(null));
}

43. GeoBoundsIT#testPartiallyUnmapped()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME, UNMAPPED_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE));
}

44. GeoBoundsIT#testEmptyAggregation()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch(EMPTY_IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
    GeoBounds geoBounds = searchResponse.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft, equalTo(null));
    assertThat(bottomRight, equalTo(null));
}

45. GeoBoundsIT#testSingleValuedFieldNearDateLine()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testSingleValuedFieldNearDateLine() throws Exception {
    SearchResponse response = client().prepareSearch(DATELINE_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoPoint geoValuesTopLeft = new GeoPoint(38, -179);
    GeoPoint geoValuesBottomRight = new GeoPoint(-24, 178);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(geoValuesTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(geoValuesTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(geoValuesBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(geoValuesBottomRight.lon(), GEOHASH_TOLERANCE));
}

46. GeoBoundsIT#testSingleValuedFieldNearDateLineWrapLongitude()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testSingleValuedFieldNearDateLineWrapLongitude() throws Exception {
    GeoPoint geoValuesTopLeft = new GeoPoint(38, 170);
    GeoPoint geoValuesBottomRight = new GeoPoint(-24, -175);
    SearchResponse response = client().prepareSearch(DATELINE_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(true)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(geoValuesTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(geoValuesTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(geoValuesBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(geoValuesBottomRight.lon(), GEOHASH_TOLERANCE));
}

47. GeoBoundsIT#testSingleValuedFieldWithZeroLon()

Project: elasticsearch
Source File: GeoBoundsIT.java
View license
public void testSingleValuedFieldWithZeroLon() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_ZERO_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
}

48. GeoCentroidIT#testEmptyAggregation()

Project: elasticsearch
Source File: GeoCentroidIT.java
View license
public void testEmptyAggregation() throws Exception {
    SearchResponse response = client().prepareSearch(EMPTY_IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(response);
    GeoCentroid geoCentroid = response.getAggregations().get(aggName);
    assertThat(response.getHits().getTotalHits(), equalTo(0L));
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid, equalTo(null));
}

49. GeoCentroidIT#testUnmapped()

Project: elasticsearch
Source File: GeoCentroidIT.java
View license
public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(UNMAPPED_IDX_NAME).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(response);
    GeoCentroid geoCentroid = response.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid, equalTo(null));
}

50. GeoCentroidIT#testPartiallyUnmapped()

Project: elasticsearch
Source File: GeoCentroidIT.java
View license
public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME, UNMAPPED_IDX_NAME).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(response);
    GeoCentroid geoCentroid = response.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid.lat(), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat(centroid.lon(), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
}

51. GeoCentroidIT#testSingleValuedField()

Project: elasticsearch
Source File: GeoCentroidIT.java
View license
public void testSingleValuedField() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(response);
    GeoCentroid geoCentroid = response.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid.lat(), closeTo(singleCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat(centroid.lon(), closeTo(singleCentroid.lon(), GEOHASH_TOLERANCE));
}

52. GeoCentroidIT#testMultiValuedField()

Project: elasticsearch
Source File: GeoCentroidIT.java
View license
public void testMultiValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch(IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoCentroid(aggName).field(MULTI_VALUED_FIELD_NAME)).execute().actionGet();
    assertSearchResponse(searchResponse);
    GeoCentroid geoCentroid = searchResponse.getAggregations().get(aggName);
    assertThat(geoCentroid, notNullValue());
    assertThat(geoCentroid.getName(), equalTo(aggName));
    GeoPoint centroid = geoCentroid.centroid();
    assertThat(centroid.lat(), closeTo(multiCentroid.lat(), GEOHASH_TOLERANCE));
    assertThat(centroid.lon(), closeTo(multiCentroid.lon(), GEOHASH_TOLERANCE));
}

53. GeoCentroidIT#testSingleValueFieldAsSubAggToGeohashGrid()

Project: elasticsearch
Source File: GeoCentroidIT.java
View license
public void testSingleValueFieldAsSubAggToGeohashGrid() throws Exception {
    SearchResponse response = client().prepareSearch(HIGH_CARD_IDX_NAME).addAggregation(geohashGrid("geoGrid").field(SINGLE_VALUED_FIELD_NAME).subAggregation(geoCentroid(aggName).field(SINGLE_VALUED_FIELD_NAME))).execute().actionGet();
    assertSearchResponse(response);
    GeoHashGrid grid = response.getAggregations().get("geoGrid");
    assertThat(grid, notNullValue());
    assertThat(grid.getName(), equalTo("geoGrid"));
    List<GeoHashGrid.Bucket> buckets = grid.getBuckets();
    for (int i = 0; i < buckets.size(); ++i) {
        GeoHashGrid.Bucket cell = buckets.get(i);
        String geohash = cell.getKeyAsString();
        GeoPoint expectedCentroid = expectedCentroidsForGeoHash.get(geohash);
        GeoCentroid centroidAgg = cell.getAggregations().get(aggName);
        assertThat("Geohash " + geohash + " has wrong centroid latitude ", expectedCentroid.lat(), closeTo(centroidAgg.centroid().lat(), GEOHASH_TOLERANCE));
        assertThat("Geohash " + geohash + " has wrong centroid longitude", expectedCentroid.lon(), closeTo(centroidAgg.centroid().lon(), GEOHASH_TOLERANCE));
    }
}

54. SumIT#testEmptyAggregation()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx").setQuery(matchAllQuery()).addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0).subAggregation(sum("sum").field("value"))).execute().actionGet();
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    Histogram histo = searchResponse.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    Histogram.Bucket bucket = histo.getBuckets().get(1);
    assertThat(bucket, notNullValue());
    Sum sum = bucket.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo(0.0));
}

55. SumIT#testUnmapped()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx_unmapped").setQuery(matchAllQuery()).addAggregation(sum("sum").field("value")).execute().actionGet();
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo(0.0));
}

56. SumIT#testSingleValuedField()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testSingleValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10));
}

57. SumIT#testSingleValuedFieldWithFormatter()

Project: elasticsearch
Source File: SumIT.java
View license
public void testSingleValuedFieldWithFormatter() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").format("0000.0").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10));
    assertThat(sum.getValueAsString(), equalTo("0055.0"));
}

58. SumIT#testSingleValuedFieldGetProperty()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testSingleValuedFieldGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(sum("sum").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));
    Sum sum = global.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    double expectedSumValue = (double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
    assertThat(sum.getValue(), equalTo(expectedSumValue));
    assertThat((Sum) global.getProperty("sum"), equalTo(sum));
    assertThat((double) global.getProperty("sum.value"), equalTo(expectedSumValue));
    assertThat((double) sum.getProperty("value"), equalTo(expectedSumValue));
}

59. SumIT#testSingleValuedFieldPartiallyUnmapped()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testSingleValuedFieldPartiallyUnmapped() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx", "idx_unmapped").setQuery(matchAllQuery()).addAggregation(sum("sum").field("value")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10));
}

60. SumIT#testSingleValuedFieldWithValueScript()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testSingleValuedFieldWithValueScript() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").field("value").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10));
}

61. SumIT#testSingleValuedFieldWithValueScriptWithParams()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testSingleValuedFieldWithValueScriptWithParams() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("increment", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").field("value").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10));
}

62. SumIT#testScriptSingleValued()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testScriptSingleValued() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10));
}

63. SumIT#testScriptSingleValuedWithParams()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testScriptSingleValuedWithParams() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("inc", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").script(new Script("value", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11));
}

64. SumIT#testScriptMultiValued()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testScriptMultiValued() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12));
}

65. SumIT#testScriptMultiValuedWithParams()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testScriptMultiValuedWithParams() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("inc", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").script(new Script("values", ScriptType.INLINE, ExtractFieldScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12 + 12 + 13));
}

66. SumIT#testMultiValuedField()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testMultiValuedField() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").field("values")).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12));
}

67. SumIT#testMultiValuedFieldWithValueScript()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testMultiValuedFieldWithValueScript() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").field("values").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, null))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12));
}

68. SumIT#testMultiValuedFieldWithValueScriptWithParams()

Project: elasticsearch
Source File: SumIT.java
View license
@Override
public void testMultiValuedFieldWithValueScriptWithParams() throws Exception {
    Map<String, Object> params = new HashMap<>();
    params.put("increment", 1);
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(sum("sum").field("values").script(new Script("", ScriptType.INLINE, FieldValueScriptEngine.NAME, params))).execute().actionGet();
    assertHitCount(searchResponse, 10);
    Sum sum = searchResponse.getAggregations().get("sum");
    assertThat(sum, notNullValue());
    assertThat(sum.getName(), equalTo("sum"));
    assertThat(sum.getValue(), equalTo((double) 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7 + 7 + 8 + 8 + 9 + 9 + 10 + 10 + 11 + 11 + 12));
}

69. TopHitsIT#testBasicsGetProperty()

Project: elasticsearch
Source File: TopHitsIT.java
View license
public void testBasicsGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(topHits("hits"))).execute().actionGet();
    assertSearchResponse(searchResponse);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    TopHits topHits = global.getAggregations().get("hits");
    assertThat(topHits, notNullValue());
    assertThat(topHits.getName(), equalTo("hits"));
    assertThat((TopHits) global.getProperty("hits"), sameInstance(topHits));
}

70. TopHitsIT#testDontExplode()

Project: elasticsearch
Source File: TopHitsIT.java
View license
public void testDontExplode() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").executionHint(randomExecutionHint()).field(TERMS_AGGS_FIELD).subAggregation(topHits("hits").size(ArrayUtil.MAX_ARRAY_LENGTH - 1).sort(SortBuilders.fieldSort(SORT_FIELD).order(SortOrder.DESC)))).get();
    assertNoFailures(response);
}

71. ValueCountIT#testUnmapped()

Project: elasticsearch
Source File: ValueCountIT.java
View license
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));
}

72. ValueCountIT#testSingleValuedField()

Project: elasticsearch
Source File: ValueCountIT.java
View license
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));
}

73. ValueCountIT#testSingleValuedFieldGetProperty()

Project: elasticsearch
Source File: ValueCountIT.java
View license
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));
}

74. ValueCountIT#testSingleValuedFieldPartiallyUnmapped()

Project: elasticsearch
Source File: ValueCountIT.java
View license
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));
}

75. ValueCountIT#testMultiValuedField()

Project: elasticsearch
Source File: ValueCountIT.java
View license
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));
}

76. ValueCountIT#testSingleValuedScriptWithParams()

Project: elasticsearch
Source File: ValueCountIT.java
View license
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));
}

77. ValueCountIT#testMultiValuedScriptWithParams()

Project: elasticsearch
Source File: ValueCountIT.java
View license
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));
}

78. MissingValueIT#testLongTerms()

Project: elasticsearch
Source File: MissingValueIT.java
View license
public void testLongTerms() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("my_terms").field("long").missing(4)).get();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("my_terms");
    assertEquals(2, terms.getBuckets().size());
    assertEquals(1, terms.getBucketByKey("3").getDocCount());
    assertEquals(1, terms.getBucketByKey("4").getDocCount());
    response = client().prepareSearch("idx").addAggregation(terms("my_terms").field("long").missing(3)).get();
    assertSearchResponse(response);
    terms = response.getAggregations().get("my_terms");
    assertEquals(1, terms.getBuckets().size());
    assertEquals(2, terms.getBucketByKey("3").getDocCount());
}

79. MissingValueIT#testDoubleTerms()

Project: elasticsearch
Source File: MissingValueIT.java
View license
public void testDoubleTerms() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("my_terms").field("double").missing(4.5)).get();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("my_terms");
    assertEquals(2, terms.getBuckets().size());
    assertEquals(1, terms.getBucketByKey("4.5").getDocCount());
    assertEquals(1, terms.getBucketByKey("5.5").getDocCount());
    response = client().prepareSearch("idx").addAggregation(terms("my_terms").field("double").missing(5.5)).get();
    assertSearchResponse(response);
    terms = response.getAggregations().get("my_terms");
    assertEquals(1, terms.getBuckets().size());
    assertEquals(2, terms.getBucketByKey("5.5").getDocCount());
}

80. MissingValueIT#testHistogram()

Project: elasticsearch
Source File: MissingValueIT.java
View license
public void testHistogram() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(histogram("my_histogram").field("long").interval(5).missing(7)).get();
    assertSearchResponse(response);
    Histogram histogram = response.getAggregations().get("my_histogram");
    assertEquals(2, histogram.getBuckets().size());
    assertEquals(0L, histogram.getBuckets().get(0).getKey());
    assertEquals(1, histogram.getBuckets().get(0).getDocCount());
    assertEquals(5L, histogram.getBuckets().get(1).getKey());
    assertEquals(1, histogram.getBuckets().get(1).getDocCount());
    response = client().prepareSearch("idx").addAggregation(histogram("my_histogram").field("long").interval(5).missing(3)).get();
    assertSearchResponse(response);
    histogram = response.getAggregations().get("my_histogram");
    assertEquals(1, histogram.getBuckets().size());
    assertEquals(0L, histogram.getBuckets().get(0).getKey());
    assertEquals(2, histogram.getBuckets().get(0).getDocCount());
}

81. CardinalityTests#testSingleValuedStringValueScript()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testSingleValuedStringValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value").script(new Script("_value"))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}

82. CardinalityTests#testUnmapped()

Project: elasticsearch
Source File: CardinalityTests.java
View license
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);
}

83. CardinalityTests#testPartiallyUnmapped()

Project: elasticsearch
Source File: CardinalityTests.java
View license
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);
}

84. CardinalityTests#testSingleValuedString()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testSingleValuedString() throws Exception {
    SearchResponse response = client().prepareSearch("idx").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);
}

85. CardinalityTests#testSingleValuedNumeric()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testSingleValuedNumeric() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField())).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}

86. CardinalityTests#testSingleValuedNumericGetProperty()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testSingleValuedNumericGetProperty() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("idx").setQuery(matchAllQuery()).addAggregation(global("global").subAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))).execute().actionGet();
    assertSearchResponse(searchResponse);
    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    // assertThat(global.getDocCount(), equalTo(numDocs));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));
    Cardinality cardinality = global.getAggregations().get("cardinality");
    assertThat(cardinality, notNullValue());
    assertThat(cardinality.getName(), equalTo("cardinality"));
    long expectedValue = numDocs;
    assertCount(cardinality, expectedValue);
    assertThat((Cardinality) global.getProperty("cardinality"), equalTo(cardinality));
    assertThat((double) global.getProperty("cardinality.value"), equalTo((double) cardinality.getValue()));
    assertThat((double) cardinality.getProperty("value"), equalTo((double) cardinality.getValue()));
}

87. CardinalityTests#testSingleValuedNumericHashed()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testSingleValuedNumericHashed() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField())).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}

88. CardinalityTests#testMultiValuedString()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testMultiValuedString() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_values")).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs * 2);
}

89. CardinalityTests#testMultiValuedNumeric()

Project: elasticsearch
Source File: CardinalityTests.java
View license
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);
}

90. CardinalityTests#testMultiValuedNumericHashed()

Project: elasticsearch
Source File: CardinalityTests.java
View license
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);
}

91. CardinalityTests#testSingleValuedStringScript()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testSingleValuedStringScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(new Script("doc['str_value'].value"))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}

92. CardinalityTests#testMultiValuedStringScript()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testMultiValuedStringScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(new Script("doc['str_values'].values"))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs * 2);
}

93. CardinalityTests#testSingleValuedNumericScript()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testSingleValuedNumericScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(new Script("doc['" + singleNumericField() + "'].value"))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}

94. CardinalityTests#testMultiValuedNumericScript()

Project: elasticsearch
Source File: CardinalityTests.java
View license
public void testMultiValuedNumericScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).script(new Script("doc['" + multiNumericField(false) + "'].values"))).execute().actionGet();
    assertSearchResponse(response);
    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs * 2);
}

95. DoubleTermsTests#testMultiValuedFieldWithValueScriptNotUnique()

Project: elasticsearch
Source File: DoubleTermsTests.java
View license
public void testMultiValuedFieldWithValueScriptNotUnique() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(MULTI_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())).script(new Script("(long) (_value / 1000 + 1)"))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    assertThat(terms.getBuckets().size(), equalTo(1));
    Terms.Bucket bucket = terms.getBucketByKey("1.0");
    assertThat(bucket, notNullValue());
    assertThat(key(bucket), equalTo("1.0"));
    assertThat(bucket.getKeyAsNumber().intValue(), equalTo(1));
    assertThat(bucket.getDocCount(), equalTo(5L));
}

96. DoubleTermsTests#testSingleValueFieldOrderedByTermAsc()

Project: elasticsearch
Source File: DoubleTermsTests.java
View license
public void testSingleValueFieldOrderedByTermAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.term(true))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    assertThat(terms.getBuckets().size(), equalTo(5));
    int i = 0;
    for (Terms.Bucket bucket : terms.getBuckets()) {
        assertThat(bucket, notNullValue());
        assertThat(key(bucket), equalTo("" + (double) i));
        assertThat(bucket.getKeyAsNumber().intValue(), equalTo(i));
        assertThat(bucket.getDocCount(), equalTo(1L));
        i++;
    }
}

97. DoubleTermsTests#testSingleValueFieldOrderedByTermDesc()

Project: elasticsearch
Source File: DoubleTermsTests.java
View license
public void testSingleValueFieldOrderedByTermDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.term(false))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    assertThat(terms.getBuckets().size(), equalTo(5));
    int i = 4;
    for (Terms.Bucket bucket : terms.getBuckets()) {
        assertThat(bucket, notNullValue());
        assertThat(key(bucket), equalTo("" + (double) i));
        assertThat(bucket.getKeyAsNumber().intValue(), equalTo(i));
        assertThat(bucket.getDocCount(), equalTo(1L));
        i--;
    }
}

98. DoubleTermsTests#testSingleValuedFieldWithValueScript()

Project: elasticsearch
Source File: DoubleTermsTests.java
View license
public void testSingleValuedFieldWithValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())).script(new Script("_value + 1"))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    assertThat(terms.getBuckets().size(), equalTo(5));
    for (int i = 0; i < 5; i++) {
        Terms.Bucket bucket = terms.getBucketByKey("" + (i + 1d));
        assertThat(bucket, notNullValue());
        assertThat(key(bucket), equalTo("" + (i + 1d)));
        assertThat(bucket.getKeyAsNumber().intValue(), equalTo(i + 1));
        assertThat(bucket.getDocCount(), equalTo(1L));
    }
}

99. DoubleTermsTests#testIncludeExcludeResults()

Project: elasticsearch
Source File: DoubleTermsTests.java
View license
private void testIncludeExcludeResults(double[] includes, double[] excludes, double[] expecteds) {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME).includeExclude(new IncludeExclude(includes, excludes)).collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    assertThat(terms.getBuckets().size(), equalTo(expecteds.length));
    for (int i = 0; i < expecteds.length; i++) {
        Terms.Bucket bucket = terms.getBucketByKey("" + expecteds[i]);
        assertThat(bucket, notNullValue());
        assertThat(bucket.getDocCount(), equalTo(1L));
    }
}

100. DoubleTermsTests#testScriptSingleValue()

Project: elasticsearch
Source File: DoubleTermsTests.java
View license
/*

    [1, 2]
    [2, 3]
    [3, 4]
    [4, 5]
    [5, 6]

    1 - count: 1 - sum: 1
    2 - count: 2 - sum: 4
    3 - count: 2 - sum: 6
    4 - count: 2 - sum: 8
    5 - count: 2 - sum: 10
    6 - count: 1 - sum: 6

    */
public void testScriptSingleValue() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").collectMode(randomFrom(SubAggCollectionMode.values())).script(new Script("doc['" + MULTI_VALUED_FIELD_NAME + "'].value"))).execute().actionGet();
    assertSearchResponse(response);
    Terms terms = response.getAggregations().get("terms");
    assertThat(terms, notNullValue());
    assertThat(terms.getName(), equalTo("terms"));
    assertThat(terms.getBuckets().size(), equalTo(5));
    for (int i = 0; i < 5; i++) {
        Terms.Bucket bucket = terms.getBucketByKey("" + (double) i);
        assertThat(bucket, notNullValue());
        assertThat(key(bucket), equalTo("" + (double) i));
        assertThat(bucket.getKeyAsNumber().intValue(), equalTo(i));
        assertThat(bucket.getDocCount(), equalTo(1L));
    }
}