vivo / MoonBox

月光宝盒:无侵入的流量录制与回放平台 A server-side traffic capture and replay platform with noninvasive
Apache License 2.0
1.21k stars 196 forks source link

/api/record/data/uriList录制信息模糊查询接口存在问题,只需要修改下面的类 #77

Open zhouliangiseeyou opened 6 months ago

zhouliangiseeyou commented 6 months ago

image moonbox-server/moonbox-service-data-es/src/main/java/com/vivo/internet/moonbox/service/data/es/record/service/RecordDataServiceImpl.java

` @Override public List getRecordUriCountList(RecordUriCountQuery query) { SearchRequest searchRequest = new SearchRequest(INDEX_NAME).indicesOptions(IndicesOptions.lenientExpandOpen()) .preference("_local");

    List<CompositeValuesSourceBuilder<?>> aggBuilder = Lists.newArrayList();
    aggBuilder.add(new TermsValuesSourceBuilder("uri").field(EsRecordEntity.Fields.entranceDesc));
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().size(0)
            .query(QueryBuilders.boolQuery().filter(
                    QueryBuilders.termQuery(EsRecordEntity.Fields.recordTaskRunId, query.getRecordTaskRunId())));
    if (StringUtils.isNotBlank(query.getUriMatchCondition())) {
        sourceBuilder.query(QueryBuilders.boolQuery().filter(
                QueryBuilders.termQuery(EsReplayEntity.Fields.entranceDesc, query.getUriMatchCondition())));
    }
    sourceBuilder.aggregation(new CompositeAggregationBuilder("myBuckets", aggBuilder).size(1000));
    searchRequest.source(sourceBuilder);

    // 获取聚合查询结果
    SearchResponse r = search(searchRequest);
    ParsedComposite parsedComposite = r.getAggregations().get("myBuckets");
    if (CollectionUtils.isEmpty(parsedComposite.getBuckets())) {
        return Lists.newArrayList();
    }
    return parsedComposite.getBuckets().stream().map(item -> {
        Map<String, Object> keys = item.getKey();
        return RecordUriCountResult.builder().recordUri(keys.get("uri").toString())
                .recordTaskRunId(query.getRecordTaskRunId()).recordCount(item.getDocCount())
                .invokeType(InvokeType.getInvokeTypeByUri(keys.get("uri").toString()).getInvokeName()).build();
    }).collect(Collectors.toList());
}`