EsCountService.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package cn.cslg.pas.service.business.es;
  2. import cn.cslg.pas.common.dto.PatentDTO;
  3. import cn.cslg.pas.common.dto.business.EsCountDTO;
  4. import cn.cslg.pas.common.model.request.QueryRequest;
  5. import cn.cslg.pas.common.vo.business.EsCountVO;
  6. import cn.cslg.pas.domain.es.Patent;
  7. import co.elastic.clients.elasticsearch.ElasticsearchClient;
  8. import co.elastic.clients.elasticsearch._types.aggregations.AggregateBuilders;
  9. import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
  10. import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
  11. import co.elastic.clients.elasticsearch._types.aggregations.NestedAggregate;
  12. import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
  13. import co.elastic.clients.elasticsearch.core.SearchRequest;
  14. import co.elastic.clients.elasticsearch.core.SearchResponse;
  15. import lombok.RequiredArgsConstructor;
  16. import org.springframework.context.annotation.Lazy;
  17. import org.springframework.stereotype.Service;
  18. @Service
  19. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  20. public class EsCountService {
  21. private final ElasticsearchClient client;
  22. /**
  23. * 查询专利库中的专利分组聚合统计
  24. * @param vo
  25. * @return
  26. * @throws Exception
  27. */
  28. public EsCountDTO esCountSearch(EsCountVO vo) throws Exception {
  29. String field = vo.getField();
  30. String value = vo.getValue();
  31. Integer topN = vo.getTopN();
  32. EsCountDTO esCountDTO = new EsCountDTO();
  33. SearchRequest.Builder builder = new SearchRequest.Builder();
  34. builder.index("patent");
  35. if (field.equals("applicant")) {
  36. }
  37. if (field.equals("rightHolder")) {
  38. }
  39. if (field.equals("mipc")) {
  40. }
  41. if (field.equals("appDate")) {
  42. }
  43. // AggregationBuilders.terms(i -> i.field()).field()
  44. SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
  45. return esCountDTO;
  46. }
  47. }