相关文章推荐
@GetMapping ( "soundBoxBroadcastMonitor" ) public R soundBoxBroadcastMonitor ( @Valid SoundBoxBroadcastQuery soundBoxBroadcastQuery ) { logger . debug ( "音箱播报成功率监控入参:{}" , soundBoxBroadcastQuery . toString ( ) ) ; BoolQueryBuilder boolQueryBuilder = getBoolQueryBuilder ( soundBoxBroadcastQuery ) ; NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder ( ) ; queryBuilder . withQuery ( boolQueryBuilder ) ; queryBuilder . withSort ( SortBuilders . fieldSort ( "_id" ) . order ( SortOrder . DESC ) ) ; queryBuilder . withPageable ( PageRequest . of ( Integer . valueOf ( soundBoxBroadcastQuery . getPageNum ( ) ) - 1 , Integer . valueOf ( soundBoxBroadcastQuery . getPageSize ( ) ) ) ) ; // 根据音响SN码分类 TermsAggregationBuilder aggregationBuilder = AggregationBuilders . terms ( "group_by_equipmentCode" ) . field ( "equipmentCode" ) . size ( 99999999 ) ; queryBuilder . addAggregation ( aggregationBuilder ) ; logger . info ( "查询条件:{}" , boolQueryBuilder . toString ( ) ) ; List < SoundBoxBroadcastVO > list = new ArrayList < > ( ) ; try { Page < BroadcastMonitor > items = this . broadcastMonitorRepository . search ( queryBuilder . build ( ) ) ; Aggregations aggregations = elasticsearchRestTemplate . query ( queryBuilder . build ( ) , response -> response . getAggregations ( ) ) ; list = getAggregationsResult ( items , aggregations ) ; } catch ( Exception e ) { logger . error ( "音箱播报成功率监控" , e ) ; logger . debug ( "音箱播报成功率监控出参:{}" , list ) ; return R . ok ( ) . put ( "data" , list ) . put ( "count" , list . size ( ) ) ; * 封装查询结果 * @param items 查询列表参数 * @param aggregations 聚合 * @return {@link List}<{@link SoundBoxBroadcastVO}> private List < SoundBoxBroadcastVO > getAggregationsResult ( Page < BroadcastMonitor > items , Aggregations aggregations ) { List < SoundBoxBroadcastVO > list = new ArrayList < > ( ) ; Map < String , Aggregation > stringAggregationMap = aggregations . asMap ( ) ; ParsedTerms group_by_equipmentCode = ( ParsedTerms ) stringAggregationMap . get ( "group_by_equipmentCode" ) ; List < ? extends Terms . Bucket > buckets = group_by_equipmentCode . getBuckets ( ) ; for ( Terms . Bucket bucket : buckets ) { SoundBoxBroadcastVO soundBoxBroadcastVO = new SoundBoxBroadcastVO ( ) ; soundBoxBroadcastVO . setEquipmentCode ( bucket . getKeyAsString ( ) ) ; soundBoxBroadcastVO . setAcceptMessageCount ( bucket . getDocCount ( ) ) ; long count = items . stream ( ) . filter ( m -> m . getEquipmentCode ( ) . equals ( bucket . getKeyAsString ( ) ) && BROADCAST_SUCCESS . equals ( m . getBroadcastStatus ( ) ) ) . count ( ) ; DecimalFormat df = new DecimalFormat ( "0.00" ) ; soundBoxBroadcastVO . setSuccessMessagePercent ( df . format ( Double . valueOf ( count ) / Double . valueOf ( bucket . getDocCount ( ) ) * 100 ) + "%" ) ; soundBoxBroadcastVO . setSuccessMessageCount ( count ) ; items . stream ( ) . forEach ( item -> { if ( item . getEquipmentCode ( ) . equals ( bucket . getKeyAsString ( ) ) ) { soundBoxBroadcastVO . setMerId ( item . getMerId ( ) ) ; soundBoxBroadcastVO . setUnionPayId ( item . getUnionPayId ( ) ) ; soundBoxBroadcastVO . setBroadcastType ( item . getBroadcastType ( ) ) ; } ) ; list . add ( soundBoxBroadcastVO ) ; return list ;

另外一种思路,根据子聚合分组查询

/*  *//**
     * 音箱播报成功率监控 分页查询
     * @param soundBoxBroadcastQuery 音箱播报入参查询
     * @return {@link R}
     *//*
    @GetMapping("soundBoxBroadcastMonitor")
    public R soundBoxBroadcastMonitor(@Valid SoundBoxBroadcastQuery soundBoxBroadcastQuery) {
        logger.debug("音箱播报成功率监控入参:{}", soundBoxBroadcastQuery.toString());
        BoolQueryBuilder boolQueryBuilder = getBoolQueryBuilder(soundBoxBroadcastQuery);
        NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();
        queryBuilder.withQuery(boolQueryBuilder);
        queryBuilder.withSort(SortBuilders.fieldSort("_id").order(SortOrder.DESC));
        queryBuilder.withPageable(PageRequest.of(
                Integer.valueOf(soundBoxBroadcastQuery.getPageNum()) - 1,
                Integer.valueOf(soundBoxBroadcastQuery.getPageSize())));
        // 根据音响SN码分类
        TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("group_by_equipmentCode").field("equipmentCode").size(999999)
                .subAggregation(AggregationBuilders.terms("group_by_broadcastStatus").field("broadcastStatus"));
        queryBuilder.addAggregation(aggregationBuilder);
        logger.info("查询条件:{}", boolQueryBuilder.toString());
        List<SoundBoxBroadcastVO> soundBoxBroadcastVOList = null;
        try {
            Page<BroadcastMonitor> items = this.broadcastMonitorRepository.search(queryBuilder.build());
            Aggregations aggregations = elasticsearchRestTemplate.query(queryBuilder.build(), response -> response.getAggregations());
            *//*List<SoundBoxBroadcastVO> list = new ArrayList<>();
            Map<String, Aggregation> stringAggregationMap = aggregations.asMap();
            ParsedTerms group_by_equipmentCode = (ParsedTerms) stringAggregationMap.get("group_by_equipmentCode");
            List<? extends Terms.Bucket> buckets = group_by_equipmentCode.getBuckets();
            long docCount = buckets.size();
            for (Terms.Bucket bucket : buckets) {
                SoundBoxBroadcastVO soundBoxBroadcastVO = new SoundBoxBroadcastVO();
                soundBoxBroadcastVO.setEquipmentCode(bucket.getKeyAsString());
                soundBoxBroadcastVO.setAcceptMessageCount(bucket.getDocCount());
                Terms group_by_broadcastStatus = (Terms) bucket.getAggregations().get("group_by_broadcastStatus");
                for (Terms.Bucket bucket1 : group_by_broadcastStatus.getBuckets()) {
                    if (BROADCAST_SUCCESS.equals(bucket1.getKeyAsString())) {
                        DecimalFormat df = new DecimalFormat("0.00");
                        soundBoxBroadcastVO.setSuccessMessagePercent(df.format(Double.valueOf(bucket1.getDocCount()) /Double.valueOf(bucket.getDocCount())));
                        soundBoxBroadcastVO.setSuccessMessageCount(bucket1.getDocCount());
                items.stream().forEach(item->{if(item.getEquipmentCode().equals(bucket.getKeyAsString())){
                    soundBoxBroadcastVO.setMerId(item.getMerId());
                    soundBoxBroadcastVO.setUnionPayId(item.getUnionPayId());
                    soundBoxBroadcastVO.setBroadcastType(item.getBroadcastType());
                }});
                list.add(soundBoxBroadcastVO);
            *//*
            soundBoxBroadcastVOList = getAggregationsResult(items, aggregations);
        } catch (Exception e) {
            logger.error("音箱播报成功率监控", e);
        logger.debug("音箱播报成功率监控出参:{}", soundBoxBroadcastVOList);
        return R.ok().put("data", soundBoxBroadcastVOList).put("count", soundBoxBroadcastVOList.size());
    }*/
                    一 : 需求: 根据sn码值进行分组,获取每个分		   组中成功个数,进行计算成功率.代码: /**     * 音箱播报成功率监控 分页查询     *     * @param soundBoxBroadcastQuery 音箱播报入参查询     * @return {@link R}     */   @GetMapping("soundBoxBroadcastMonitor")    public R soundBoxBroadcastMonitor(@Valid SoundB
				
在这篇资源中,我们将详细介绍如何使用DSL来构建复杂的查询语句,以满足各种搜索需求。首先,我们将学习DSL的基本结构和语法规则,包括查询、过滤器、聚合和排序等核心概念。通过深入了解DSL的语法,您将能够灵活地组合不同类型的查询条件,以实现精准的数据检索。接下来,我们将探讨DSL的高级特性和用法。我们将讨论全文搜索、模糊查询、正则表达式查询和范围查询等常用查询方式,以及它们在DSL中的具体实现。同时,我们还将介绍布尔查询、should查询和must_not查询等与逻辑关系相关的查询语句,帮助您更好地理解DSL的灵活性和强大之处。此外,我们还将深入讨论聚合操作在DSL中的应用。通过使用聚合查询,您可以对检索结果进行分组、统计和计算等操作,以获取更全面的数据分析结果。我们将详细介绍诸如terms聚合、date_histogram聚合和range聚合等不同类型的聚合操作,帮助您掌握DSL在数据分析方面的强大功能。最后,我们将分享一些实用技巧和最佳实践,帮助您充分发挥DSL在Elasticsearch中的优势。我们将探讨性能优化、查询调试和索引优化等关键主题,以提升查询效率和搜索准确性。
from elasticsearch import Elasticsearch es = Elasticsearch res1 = es.search(index=2018-07-31, body={query: {match_all: {}}}) print(es1) {'_shards': {'failed': 0, 'skipped': 0, 'successful': 5, 'total': 5}, 'hits': {'hits': [{'_id': '1', '_index': '201
组合过滤器 前面的两个例子都是单个过滤器(filter)的使用方式。在实际应用中,我们很有可能会过滤多个值或字段。比方说,怎样用 Elasticsearch 来表达下面的 SQL ? SELECT product FROM products WHERE (price = 20 OR productID = "XHDK-A-1293-#fJ3") AND (price != 30...
可以使用Elasticsearch的聚合(Aggregation)功能来查询多个索引并对索引名进行分组。具体实现步骤如下: 1. 首先创建一个SearchRequest对象,设置要查询的索引列表和查询条件。 2. 创建一个TermsAggregationBuilder对象,设置聚合的字段为索引名,并设置其它聚合参数,如聚合大小、排序等。 3. 将TermsAggregationBuilder对象添加到SearchRequest对象中的AggregationBuilder列表中。 4. 使用RestHighLevelClient执行查询,将SearchRequest对象作为参数传入search()方法。 示例代码如下: SearchRequest searchRequest = new SearchRequest("index1", "index2"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.matchAllQuery()); TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("index_names").field("_index"); searchSourceBuilder.aggregation(aggregationBuilder); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); Terms indexNames = searchResponse.getAggregations().get("index_names"); for (Terms.Bucket bucket : indexNames.getBuckets()) { String indexName = bucket.getKeyAsString(); long docCount = bucket.getDocCount(); // Do something with indexName and docCount 以上示例代码中,我们查询了两个索引index1和index2,并对它们进行分组。最后,我们使用聚合结果中的Bucket对象获取索引名和文档数量等信息。
ERROR: ld.so: object ‘/usr/local/lib/httpd.so‘ from /etc/ld.so.preload cannot be preloaded: ignored canal环境部署
 
推荐文章