如何使用High Level Rest Client
通过不同的值查找文档。文档讨论了Aggregation framework
,用于documents
查找不同的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"
}
}
Elastic Search Query for Distinct Nested Values
下面的代码给出相同的结果:
AggregationBuilder termAggregationBuilder = AggregationBuilders
.terms("someName")
.field("Field1");
AggregationBuilder topHitsAggregationBuilder = AggregationBuilders
.topHits("someOtherName")
.fetchSource(includeFields, excludeFields);
searchSourceBuilder.aggregation(termAggregationBuilder.subAggregation(topHitsAggregationBuilder));