Search in sources :

Example 1 with TermsAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project elasticsearch by elastic.

the class DiversifiedSamplerIT method testNestedDiversity.

public void testNestedDiversity() throws Exception {
    // Test multiple samples gathered under buckets made by a parent agg
    int MAX_DOCS_PER_AUTHOR = 1;
    TermsAggregationBuilder rootTerms = terms("genres").field("genre");
    DiversifiedAggregationBuilder sampleAgg = new DiversifiedAggregationBuilder("sample").shardSize(100);
    sampleAgg.field("author").maxDocsPerValue(MAX_DOCS_PER_AUTHOR).executionHint(randomExecutionHint());
    sampleAgg.subAggregation(terms("authors").field("author"));
    rootTerms.subAggregation(sampleAgg);
    SearchResponse response = client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH).addAggregation(rootTerms).execute().actionGet();
    assertSearchResponse(response);
    Terms genres = response.getAggregations().get("genres");
    Collection<Bucket> genreBuckets = genres.getBuckets();
    for (Terms.Bucket genreBucket : genreBuckets) {
        Sampler sample = genreBucket.getAggregations().get("sample");
        Terms authors = sample.getAggregations().get("authors");
        Collection<Bucket> testBuckets = authors.getBuckets();
        for (Terms.Bucket testBucket : testBuckets) {
            assertThat(testBucket.getDocCount(), lessThanOrEqualTo((long) NUM_SHARDS * MAX_DOCS_PER_AUTHOR));
        }
    }
}
Also used : Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) 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) DiversifiedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregationBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 2 with TermsAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project elasticsearch by elastic.

the class DiversifiedSamplerTests method testCase.

private void testCase(IndexSearcher indexSearcher, MappedFieldType genreFieldType, String executionHint, Consumer<InternalSampler> verify) throws IOException {
    MappedFieldType idFieldType = new KeywordFieldMapper.KeywordFieldType();
    idFieldType.setName("id");
    idFieldType.setHasDocValues(true);
    SortedNumericDVIndexFieldData fieldData = new SortedNumericDVIndexFieldData(new Index("index", "index"), "price", IndexNumericFieldData.NumericType.DOUBLE);
    FunctionScoreQuery query = new FunctionScoreQuery(new MatchAllDocsQuery(), new FieldValueFactorFunction("price", 1, FieldValueFactorFunction.Modifier.RECIPROCAL, null, fieldData));
    DiversifiedAggregationBuilder builder = new DiversifiedAggregationBuilder("_name").field(genreFieldType.name()).executionHint(executionHint).subAggregation(new TermsAggregationBuilder("terms", null).field("id"));
    InternalSampler result = search(indexSearcher, query, builder, genreFieldType, idFieldType);
    verify.accept(result);
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SortedNumericDVIndexFieldData(org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) FieldValueFactorFunction(org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Index(org.elasticsearch.index.Index) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 3 with TermsAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project fess by codelibs.

the class BsDataConfigToLabelCA method setLabelTypeId_Terms.

public void setLabelTypeId_Terms(String name, ConditionOptionCall<TermsAggregationBuilder> opLambda, OperatorCall<BsDataConfigToLabelCA> aggsLambda) {
    TermsAggregationBuilder builder = regTermsA(name, "labelTypeId");
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        DataConfigToLabelCA ca = new DataConfigToLabelCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) DataConfigToLabelCA(org.codelibs.fess.es.config.cbean.ca.DataConfigToLabelCA)

Example 4 with TermsAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project fess by codelibs.

the class BsDataConfigToRoleCA method setDataConfigId_Terms.

public void setDataConfigId_Terms(String name, ConditionOptionCall<TermsAggregationBuilder> opLambda, OperatorCall<BsDataConfigToRoleCA> aggsLambda) {
    TermsAggregationBuilder builder = regTermsA(name, "dataConfigId");
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        DataConfigToRoleCA ca = new DataConfigToRoleCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) DataConfigToRoleCA(org.codelibs.fess.es.config.cbean.ca.DataConfigToRoleCA)

Example 5 with TermsAggregationBuilder

use of org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project fess by codelibs.

the class BsElevateWordCA method setTargetLabel_Terms.

public void setTargetLabel_Terms(String name, ConditionOptionCall<TermsAggregationBuilder> opLambda, OperatorCall<BsElevateWordCA> aggsLambda) {
    TermsAggregationBuilder builder = regTermsA(name, "targetLabel");
    if (opLambda != null) {
        opLambda.callback(builder);
    }
    if (aggsLambda != null) {
        ElevateWordCA ca = new ElevateWordCA();
        aggsLambda.callback(ca);
        ca.getAggregationBuilderList().forEach(builder::subAggregation);
    }
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) ElevateWordCA(org.codelibs.fess.es.config.cbean.ca.ElevateWordCA)

Aggregations

TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)64 SignificantTermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder)20 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)14 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)13 Test (org.junit.Test)11 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)8 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)8 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)8 LinkedList (java.util.LinkedList)7 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)6 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude)6 Arrays (java.util.Arrays)4 Map (java.util.Map)4 SearchRequest (org.apache.metron.indexing.dao.search.SearchRequest)4 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)4 AggregationBuilders (org.elasticsearch.search.aggregations.AggregationBuilders)4 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)4 Nullable (javax.annotation.Nullable)3 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)3