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));
}
}
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations