• ES-JavaAPI实现 group by 查询


    public Set<String> queryBzms() {
        Set<String> result = new HashSet<>();
        try {
            // 搜索出成功上报的原始数据
            Object[] objects = new Object[]{};
            // 查询的结果字段,类似于(select id, XSE from ..)
            String[] fields = {"BZM"};
            FetchSourceContext sourceContext = new FetchSourceContext(true, fields, null);
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(QueryBuilders.boolQuery().must(QueryBuilders.existsQuery("BZM")));
            searchSourceBuilder.fetchSource(sourceContext);
            searchSourceBuilder.aggregation(AggregationBuilders.terms("BZM_group").field("BZM").size(Constant.max_es_size));
            String[] indes = {this.getAliase()};
            SearchRequest searchRequest = new SearchRequest(indes, searchSourceBuilder);
            searchSourceBuilder.size(0);
            SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
            long total = 0;
            Terms terms = searchResponse.getAggregations().get("BZM_group");
            for (Terms.Bucket bucket : terms.getBuckets()) {
                String bzm = bucket.getKeyAsString();
                result.add(bzm);
                total += 1;
            }
            logger.info("-------------- query BZM number by SpecificationEs to success : {} ----------------", total);
        } catch (Exception e){
            logger.error("-------------- query BZM by SpecificationEs to error : {} ----------------", e.getMessage());
        }
        return result;
    }
  • 相关阅读:
    真爱 vs. 种姓:新一代印度人的婚恋观
    美国司法部解禁guns打印技术
    特朗普访英,吃瓜群众却只想看《真爱至上》
    Semaphore(信号量)
    RLock(递归锁)
    用python编写九九乘法表
    php传值和传引用的区别
    post请求的header
    Content-type详解
    thinkphp5 学习笔记
  • 原文地址:https://www.cnblogs.com/chaoyou/p/14750196.html
Copyright © 2020-2023  润新知