如何使用High Level Rest Client
按不同值查找文档。文档讨论Aggregation framework
了查找 distinct documents
by field
。但我找不到任何使用High Level Rest Client
. 我怎样才能与众不同documents
。field
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("Field1", "Value1"))
searchSourceBuilder.query(boolQueryBuilder);
searchSourceBuilder.aggregation(????)
数据
{
..
..
"Field1" : "Value1",
"Field2" : "Value2"
},
{
"Field1" : "Value1",
"Field2" : "Value21"
}
}
预期输出(任何带有“Field1”的文档:“Value1”)
{
..
..
"Field1" : "Value1",
"Field2" : "Value2"
}
}
下面的代码给出了相同的结果:
AggregationBuilder termAggregationBuilder = AggregationBuilders
.terms("someName")
.field("Field1");
AggregationBuilder topHitsAggregationBuilder = AggregationBuilders
.topHits("someOtherName")
.fetchSource(includeFields, excludeFields);
searchSourceBuilder.aggregation(termAggregationBuilder.subAggregation(topHitsAggregationBuilder));