Search in sources :

Example 1 with RareTerms

use of org.opensearch.search.aggregations.bucket.terms.RareTerms in project OpenSearch by opensearch-project.

the class SearchIT method testSearchWithRareTermsAgg.

public void testSearchWithRareTermsAgg() throws IOException {
    SearchRequest searchRequest = new SearchRequest();
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.aggregation(new RareTermsAggregationBuilder("agg1").userValueTypeHint(ValueType.STRING).field("type.keyword").maxDocCount(2));
    searchSourceBuilder.size(0);
    searchRequest.source(searchSourceBuilder);
    SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
    assertSearchHeader(searchResponse);
    assertNull(searchResponse.getSuggest());
    assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
    assertEquals(0, searchResponse.getHits().getHits().length);
    RareTerms termsAgg = searchResponse.getAggregations().get("agg1");
    assertEquals("agg1", termsAgg.getName());
    assertEquals(1, termsAgg.getBuckets().size());
    RareTerms.Bucket type2 = termsAgg.getBucketByKey("type2");
    assertEquals(2, type2.getDocCount());
    assertEquals(0, type2.getAggregations().asList().size());
}
Also used : MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) SearchRequest(org.opensearch.action.search.SearchRequest) RareTerms(org.opensearch.search.aggregations.bucket.terms.RareTerms) RareTermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.RareTermsAggregationBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) MultiSearchResponse(org.opensearch.action.search.MultiSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

MultiSearchRequest (org.opensearch.action.search.MultiSearchRequest)1 MultiSearchResponse (org.opensearch.action.search.MultiSearchResponse)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 SearchResponse (org.opensearch.action.search.SearchResponse)1 RareTerms (org.opensearch.search.aggregations.bucket.terms.RareTerms)1 RareTermsAggregationBuilder (org.opensearch.search.aggregations.bucket.terms.RareTermsAggregationBuilder)1 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)1