|
@@ -2,6 +2,7 @@ package cn.cslg.pas.service.business.es;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.PatentDTO;
|
|
import cn.cslg.pas.common.dto.PatentDTO;
|
|
import cn.cslg.pas.common.dto.business.EsCountDTO;
|
|
import cn.cslg.pas.common.dto.business.EsCountDTO;
|
|
|
|
+import cn.cslg.pas.common.dto.business.EsCountDetailDTO;
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
@@ -15,6 +16,7 @@ import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
|
+import co.elastic.clients.json.JsonData;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -22,6 +24,7 @@ import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.data.elasticsearch.client.elc.ElasticsearchAggregations;
|
|
import org.springframework.data.elasticsearch.client.elc.ElasticsearchAggregations;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -47,7 +50,7 @@ public class EsCountService {
|
|
EsCountDTO esCountDTO = new EsCountDTO();
|
|
EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
- builder.index("patent");
|
|
|
|
|
|
+ builder.index("patent_v1");
|
|
IEsCountBuilder iEsCountBuilder = null;
|
|
IEsCountBuilder iEsCountBuilder = null;
|
|
String json = CommonService.readJsonFile("esCount.json");
|
|
String json = CommonService.readJsonFile("esCount.json");
|
|
List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
@@ -64,12 +67,19 @@ public class EsCountService {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-// AggregationBuilders.t
|
|
|
|
Aggregation aggregation = iEsCountBuilder.createAggregation();
|
|
Aggregation aggregation = iEsCountBuilder.createAggregation();
|
|
builder.aggregations("Agg", aggregation);
|
|
builder.aggregations("Agg", aggregation);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
Aggregate agg = response.aggregations().get("Agg");
|
|
Aggregate agg = response.aggregations().get("Agg");
|
|
-
|
|
|
|
|
|
+ List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
|
+ List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
|
+ list.forEach(bucket -> {
|
|
|
|
+ EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
|
+ dto.setName(bucket.key().stringValue());
|
|
|
|
+ dto.setNumber(bucket.docCount());
|
|
|
|
+ detailDTOS.add(dto);
|
|
|
|
+ });
|
|
|
|
+ esCountDTO.setDetailDTOS(detailDTOS);
|
|
return esCountDTO;
|
|
return esCountDTO;
|
|
}
|
|
}
|
|
}
|
|
}
|