|
@@ -48,6 +48,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -173,6 +174,7 @@ public class EsService {
|
|
|
treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
//3. 从es中检索数据
|
|
|
Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",projectId);
|
|
|
+ builder.query(q);
|
|
|
//判断同族分组
|
|
|
String str = "";
|
|
|
if (StringUtils.isNotEmpty(groupField)) {
|
|
@@ -195,18 +197,15 @@ public class EsService {
|
|
|
options.add(appDate);
|
|
|
Aggregation hits = AggregationBuilders.topHits(i -> i.size(1).sort(options));
|
|
|
Aggregation aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
- .field(esField).build())
|
|
|
+ .field(esField).size(10).build())
|
|
|
.aggregations(new HashMap() {{
|
|
|
put("hitAgg", hits);
|
|
|
}}).build();
|
|
|
- Aggregation filterAgg = new Aggregation.Builder().filter(i -> i.bool(j -> j.must(q)))
|
|
|
- .aggregations(new HashMap() {{
|
|
|
- put("filterAgg", aggregation);
|
|
|
- }}).build();
|
|
|
- builder.aggregations("Agg", filterAgg);
|
|
|
- } else {
|
|
|
- //4. 返回数据
|
|
|
- builder.query(q);
|
|
|
+// Aggregation filterAgg = new Aggregation.Builder().filter(i -> i.bool(j -> j.must(q)))
|
|
|
+// .aggregations(new HashMap() {{
|
|
|
+// put("filterAgg", aggregation);
|
|
|
+// }}).build();
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
}
|
|
|
|
|
|
//排序
|
|
@@ -247,11 +246,10 @@ public class EsService {
|
|
|
long total = 0L;
|
|
|
if (StringUtils.isNotEmpty(esField)) {
|
|
|
Aggregate agg = response.aggregations().get("Agg");
|
|
|
- Aggregate filtersAgg = agg.filter().aggregations().get("filterAgg");
|
|
|
- List<StringTermsBucket> termsBuckets = filtersAgg.sterms().buckets().array();
|
|
|
+ List<StringTermsBucket> termsBuckets = agg.sterms().buckets().array();
|
|
|
+ total = Long.valueOf(String.valueOf(termsBuckets.size()));
|
|
|
for (StringTermsBucket termsBucket : termsBuckets) {
|
|
|
Aggregate hitAgg = termsBucket.aggregations().get("hitAgg");
|
|
|
- total = hitAgg.topHits().hits().total().value();
|
|
|
List<Hit<JsonData>> hits = hitAgg.topHits().hits().hits();
|
|
|
hits.forEach(hit -> {
|
|
|
String id = hit.id();
|