Elasticsearch uses spring data to aggregate queries. Filter condition does not take effect.

/**
 * 
 * @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;
}
Mar.18,2021

clipboard.png

is a data problem. Setting the property fielddata = true, takes effect

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b359b4-e4f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b359b4-e4f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?