【java】elasticsearch用spring data聚合查询,过滤条件不生效

/**

* 聚合查询

* @return list

*/

public List<UserResponseVO> listConditionsAggregations() {

TermsAggregationBuilder builder = AggregationBuilders.terms("interests").field("interests");

SearchQuery query = new NativeSearchQueryBuilder()

.withQuery(QueryBuilders.matchQuery("lastName","smith")) // 此处条件不生效

.addAggregation(builder.subAggregation(AggregationBuilders.filter("interests",QueryBuilders.matchQuery("lastName","smith"))))

.build();

Aggregations aggregations = elasticsearchTemplate.query(query, new ResultsExtractor<Aggregations>() {

@Override

public Aggregations extract(SearchResponse response) {

return response.getAggregations();

}

});

List<UserResponseVO> list = new ArrayList<>();

Terms terms = aggregations.get("interests");

Iterator<Terms.Bucket> iterator = (Iterator<Terms.Bucket>) terms

.getBuckets().iterator();

while (iterator.hasNext()) {

MultiBucketsAggregation.Bucket bucket = iterator.next();

UserResponseVO user = new UserResponseVO((String) bucket.getKey(), (int) bucket.getDocCount());

list.add(user);

}

return list;

}

回答

【java】elasticsearch用spring data聚合查询,过滤条件不生效

是数据的问题,属性设置 fielddata = true,即生效

以上是 【java】elasticsearch用spring data聚合查询,过滤条件不生效 的全部内容, 来源链接: utcz.com/a/75059.html

回到顶部