Search in sources :

Example 1 with SamplerAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder in project elasticsearch by elastic.

the class SamplerIT method testUnmappedChildAggNoDiversity.

public void testUnmappedChildAggNoDiversity() throws Exception {
    SamplerAggregationBuilder sampleAgg = sampler("sample").shardSize(100);
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("idx_unmapped").setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(new TermQueryBuilder("genre", "fantasy")).setFrom(0).setSize(60).addAggregation(sampleAgg).execute().actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    assertThat(sample.getDocCount(), equalTo(0L));
    Terms authors = sample.getAggregations().get("authors");
    assertThat(authors.getBuckets().size(), equalTo(0));
}
Also used : Sampler(org.elasticsearch.search.aggregations.bucket.sampler.Sampler) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with SamplerAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder in project elasticsearch by elastic.

the class SamplerIT method testSimpleSampler.

public void testSimpleSampler() throws Exception {
    SamplerAggregationBuilder sampleAgg = sampler("sample").shardSize(100);
    sampleAgg.subAggregation(terms("authors").field("author"));
    SearchResponse response = client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(new TermQueryBuilder("genre", "fantasy")).setFrom(0).setSize(60).addAggregation(sampleAgg).execute().actionGet();
    assertSearchResponse(response);
    Sampler sample = response.getAggregations().get("sample");
    Terms authors = sample.getAggregations().get("authors");
    Collection<Bucket> testBuckets = authors.getBuckets();
    long maxBooksPerAuthor = 0;
    for (Terms.Bucket testBucket : testBuckets) {
        maxBooksPerAuthor = Math.max(testBucket.getDocCount(), maxBooksPerAuthor);
    }
    assertThat(maxBooksPerAuthor, equalTo(3L));
}
Also used : Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Sampler(org.elasticsearch.search.aggregations.bucket.sampler.Sampler) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 3 with SamplerAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder in project fess by codelibs.

the class EsAbstractConditionAggregation method regSamplerA.

protected SamplerAggregationBuilder regSamplerA(String name) {
    SamplerAggregationBuilder builder = AggregationBuilders.sampler(name);
    regA(builder);
    return builder;
}
Also used : SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder)

Example 4 with SamplerAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder in project fess by codelibs.

the class BsAccessTokenCA method sampler.

public void sampler(String name, ConditionOptionCall<SamplerAggregationBuilder> opLambda, OperatorCall<BsAccessTokenCA> aggsLambda) {
    SamplerAggregationBuilder builder = regSamplerA(name);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        AccessTokenCA ca = new AccessTokenCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : AccessTokenCA(org.codelibs.fess.es.config.cbean.ca.AccessTokenCA) SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder)

Example 5 with SamplerAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder in project fess by codelibs.

the class BsBadWordCA method sampler.

public void sampler(String name, ConditionOptionCall<SamplerAggregationBuilder> opLambda, OperatorCall<BsBadWordCA> aggsLambda) {
    SamplerAggregationBuilder builder = regSamplerA(name);
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        BadWordCA ca = new BadWordCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : BadWordCA(org.codelibs.fess.es.config.cbean.ca.BadWordCA) SamplerAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder)

Aggregations

SamplerAggregationBuilder (org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregationBuilder)43 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)3 Sampler (org.elasticsearch.search.aggregations.bucket.sampler.Sampler)3 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)3 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)3 AccessTokenCA (org.codelibs.fess.es.config.cbean.ca.AccessTokenCA)1 BadWordCA (org.codelibs.fess.es.config.cbean.ca.BadWordCA)1 BoostDocumentRuleCA (org.codelibs.fess.es.config.cbean.ca.BoostDocumentRuleCA)1 CrawlingInfoCA (org.codelibs.fess.es.config.cbean.ca.CrawlingInfoCA)1 CrawlingInfoParamCA (org.codelibs.fess.es.config.cbean.ca.CrawlingInfoParamCA)1 DataConfigCA (org.codelibs.fess.es.config.cbean.ca.DataConfigCA)1 DataConfigToLabelCA (org.codelibs.fess.es.config.cbean.ca.DataConfigToLabelCA)1 DataConfigToRoleCA (org.codelibs.fess.es.config.cbean.ca.DataConfigToRoleCA)1 DuplicateHostCA (org.codelibs.fess.es.config.cbean.ca.DuplicateHostCA)1 ElevateWordCA (org.codelibs.fess.es.config.cbean.ca.ElevateWordCA)1 ElevateWordToLabelCA (org.codelibs.fess.es.config.cbean.ca.ElevateWordToLabelCA)1 FailureUrlCA (org.codelibs.fess.es.config.cbean.ca.FailureUrlCA)1 FileAuthenticationCA (org.codelibs.fess.es.config.cbean.ca.FileAuthenticationCA)1 FileConfigCA (org.codelibs.fess.es.config.cbean.ca.FileConfigCA)1