|
@@ -28,6 +28,7 @@ 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.elasticsearch.core.search.FieldCollapse;
|
|
import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
|
+import co.elastic.clients.elasticsearch.core.search.TotalHits;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -204,7 +205,7 @@ public class EsCountService {
|
|
}
|
|
}
|
|
} else if (childList.contains(field)) {
|
|
} else if (childList.contains(field)) {
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
- this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query,null);
|
|
|
|
|
|
+ this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query);
|
|
} else {
|
|
} else {
|
|
this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
detailDTOS, esCountDTO, firstName, map, values);
|
|
detailDTOS, esCountDTO, firstName, map, values);
|
|
@@ -743,7 +744,7 @@ public class EsCountService {
|
|
*/
|
|
*/
|
|
public void getChildCountDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
|
|
public void getChildCountDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
|
|
List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,Integer projectId,
|
|
List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,Integer projectId,
|
|
- String fieldId,Query query,String esField) throws Exception {
|
|
|
|
|
|
+ String fieldId,Query query) throws Exception {
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
@@ -765,12 +766,12 @@ public class EsCountService {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
if (fieldType == null || fieldType != 6) {
|
|
if (fieldType == null || fieldType != 6) {
|
|
- Integer customNum1 = this.getUnselectedCustomNum1(projectId, fieldId, query);
|
|
|
|
|
|
+ Long customNum = this.getUnselectedCustomNum1(projectId, fieldId, query);
|
|
EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
detail.setField(field);
|
|
detail.setField(field);
|
|
detail.setName("未选择");
|
|
detail.setName("未选择");
|
|
- if (customNum1 != null) {
|
|
|
|
- detail.setNumber(customNum1.longValue());
|
|
|
|
|
|
+ if (customNum != null) {
|
|
|
|
+ detail.setNumber(customNum);
|
|
} else {
|
|
} else {
|
|
detail.setNumber(0L);
|
|
detail.setNumber(0L);
|
|
}
|
|
}
|
|
@@ -800,28 +801,42 @@ public class EsCountService {
|
|
}
|
|
}
|
|
|
|
|
|
//统计未选择数量
|
|
//统计未选择数量
|
|
- public Integer getUnselectedCustomNum1(Integer projectId, String fieldId, Query query) throws Exception {
|
|
|
|
|
|
+ public Long getUnselectedCustomNum1(Integer projectId, String fieldId, Query query) throws Exception {
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
//设置查询索引
|
|
//设置查询索引
|
|
builder.index("patent");
|
|
builder.index("patent");
|
|
builder.query(query);
|
|
builder.query(query);
|
|
- builder.from(0).size(10000);
|
|
|
|
- builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
- List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
|
- for (Hit<Patent> hit : hits) {
|
|
|
|
- String id = hit.id();
|
|
|
|
- list.add(id);
|
|
|
|
- }
|
|
|
|
- if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
- return this.ifExistChild1(list, projectId, fieldId);
|
|
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ final long childCount = this.ifExistChild1(projectId, fieldId,query);
|
|
|
|
+ return total - childCount;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Long ifExistChild1(Integer projectId, String fieldId,Query query) throws IOException {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.exists(i -> i.field("custom_field"));
|
|
|
|
+ Query q2 = QueryBuilders.exists(i -> i.field("custom_field.field_value"));
|
|
|
|
+ Query q3 = QueryBuilders.term(i -> i.field("custom_field.if_new").value(1));
|
|
|
|
+ Query q4 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
|
|
|
|
+ Query q5 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1,q2, q3, q4, q5));
|
|
|
|
+ Query childQ = QueryBuilders.hasChild(i -> i.type("project_customfield").query(bool));
|
|
|
|
+ if (query != null) {
|
|
|
|
+ Query bool1 = QueryBuilders.bool(i -> i.must(query, childQ));
|
|
|
|
+ builder.query(bool1);
|
|
|
|
+ } else {
|
|
|
|
+ builder.query(childQ);
|
|
}
|
|
}
|
|
- return 0;
|
|
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ return response.hits().total().value();
|
|
}
|
|
}
|
|
|
|
|
|
//根据未选择查询专利
|
|
//根据未选择查询专利
|
|
public GetUnselectedDTO getUnselectedCustomNum(Integer projectId, String fieldId) throws Exception {
|
|
public GetUnselectedDTO getUnselectedCustomNum(Integer projectId, String fieldId) throws Exception {
|
|
|
|
+ Integer pageNum = 0;
|
|
|
|
+ Integer pageSize = 1000;
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
//设置查询索引
|
|
//设置查询索引
|
|
@@ -829,7 +844,7 @@ public class EsCountService {
|
|
Query query = QueryBuilders.term(i -> i.field("project_id").value(projectId));
|
|
Query query = QueryBuilders.term(i -> i.field("project_id").value(projectId));
|
|
Query q = QueryBuilders.hasChild(i -> i.type("project").query(query));
|
|
Query q = QueryBuilders.hasChild(i -> i.type("project").query(query));
|
|
builder.query(q);
|
|
builder.query(q);
|
|
- builder.from(0).size(10000);
|
|
|
|
|
|
+ builder.from(pageNum).size(pageSize);
|
|
builder.trackTotalHits(i -> i.enabled(true));
|
|
builder.trackTotalHits(i -> i.enabled(true));
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
@@ -838,35 +853,24 @@ public class EsCountService {
|
|
String id = hit.id();
|
|
String id = hit.id();
|
|
list.add(id);
|
|
list.add(id);
|
|
}
|
|
}
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ int sum = pageSize;
|
|
|
|
+ while (sum < total) {
|
|
|
|
+ pageNum = sum;
|
|
|
|
+ sum += 1000;
|
|
|
|
+ List<String> list1 = this.loadingBatchData(projectId, null, pageNum, pageSize);
|
|
|
|
+ list.addAll(list1);
|
|
|
|
+ }
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
dto = this.ifExistChild(list, projectId, fieldId);
|
|
dto = this.ifExistChild(list, projectId, fieldId);
|
|
}
|
|
}
|
|
return dto;
|
|
return dto;
|
|
}
|
|
}
|
|
|
|
|
|
- public Integer ifExistChild1(List<String> list, Integer projectId, String fieldId) throws IOException {
|
|
|
|
- int count = 0;
|
|
|
|
- SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
- //设置查询索引
|
|
|
|
- builder.index("patent");
|
|
|
|
- Query ids = QueryBuilders.ids(i -> i.values(list));
|
|
|
|
- Query q1 = QueryBuilders.hasParent(i -> i.parentType("patent").query(ids));
|
|
|
|
- Query q2 = QueryBuilders.exists(i -> i.field("custom_field"));
|
|
|
|
- Query q3 = QueryBuilders.term(i -> i.field("custom_field.if_new").value(1));
|
|
|
|
- Query q4 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
|
|
|
|
- Query q5 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
|
|
|
|
- Query bool = QueryBuilders.bool(i -> i.must(q1, q2, q3, q4, q5));
|
|
|
|
- builder.query(bool);
|
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
- if (response.hits().total() != null) {
|
|
|
|
- long total = response.hits().total().value();
|
|
|
|
- count = list.size() - (int) total;
|
|
|
|
- }
|
|
|
|
- return count;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//查询到对应的ids
|
|
//查询到对应的ids
|
|
public GetUnselectedDTO ifExistChild(List<String> list, Integer projectId, String fieldId) throws IOException {
|
|
public GetUnselectedDTO ifExistChild(List<String> list, Integer projectId, String fieldId) throws IOException {
|
|
|
|
+ Integer pageNum = 0;
|
|
|
|
+ Integer pageSize = 1000;
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
GetUnselectedDTO dto = new GetUnselectedDTO();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
//设置查询索引
|
|
//设置查询索引
|
|
@@ -884,6 +888,14 @@ public class EsCountService {
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
List<String> collect = hits.stream().map(Hit::routing).collect(Collectors.toList());
|
|
List<String> collect = hits.stream().map(Hit::routing).collect(Collectors.toList());
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ int sum = pageSize;
|
|
|
|
+ while (sum < total) {
|
|
|
|
+ pageNum = sum;
|
|
|
|
+ sum += 1000;
|
|
|
|
+ List<String> list1 = this.loadingBatchData(projectId, null, pageNum, pageSize);
|
|
|
|
+ list.addAll(list1);
|
|
|
|
+ }
|
|
list.removeAll(collect);
|
|
list.removeAll(collect);
|
|
dto.setBeinglessChildIds(list);
|
|
dto.setBeinglessChildIds(list);
|
|
return dto;
|
|
return dto;
|