|
@@ -23,6 +23,7 @@ import cn.cslg.pas.service.business.CommonService;
|
|
|
import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
+import co.elastic.clients.elasticsearch._types.Time;
|
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
@@ -187,7 +188,7 @@ public class EsScratchWordsService {
|
|
|
reQuery = QueryBuilders.bool(i -> i.must(riBool, q));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- System.out.println(e.getMessage());
|
|
|
+ System.out.println(e.getMessage());
|
|
|
}
|
|
|
return reQuery;
|
|
|
}
|
|
@@ -253,11 +254,19 @@ public class EsScratchWordsService {
|
|
|
builder.index("patent_marking");
|
|
|
builder.query(searchQuerys);
|
|
|
Aggregation hits = AggregationBuilders.bucketSort(i -> i.size(size.intValue()).from((current.intValue() - 1) * size.intValue()));
|
|
|
- Aggregation aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
- .field(esGroupFiled).build()).aggregations(new HashMap() {{
|
|
|
- put("pageAgg", hits);
|
|
|
- }}).build();
|
|
|
-
|
|
|
+ Aggregation aggregation = null;
|
|
|
+ if (esGroupFiled.equals("mark_time")) {
|
|
|
+ aggregation =
|
|
|
+ new Aggregation.Builder().dateHistogram(new DateHistogramAggregation.Builder().field(esGroupFiled).calendarInterval(CalendarInterval.Day).format("yyyy_MM_dd").build()).aggregations(new HashMap() {{
|
|
|
+ put("pageAgg", hits);
|
|
|
+ }}).build();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
+ .field(esGroupFiled).build()).aggregations(new HashMap() {{
|
|
|
+ put("pageAgg", hits);
|
|
|
+ }}).build();
|
|
|
+ }
|
|
|
builder.aggregations("agg", aggregation);
|
|
|
builder.size(0);
|
|
|
|
|
@@ -267,17 +276,31 @@ public class EsScratchWordsService {
|
|
|
try {
|
|
|
SearchResponse<Marking> response = client.search(builder.build(), Marking.class);
|
|
|
Aggregate agg = response.aggregations().get("agg");
|
|
|
- List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
List<Map<String, Object>> maps = new ArrayList<>();
|
|
|
- for (StringTermsBucket bucket : list) {
|
|
|
- String key = bucket.key().stringValue();
|
|
|
- Long count = bucket.docCount();
|
|
|
- Map map = new HashMap();
|
|
|
- map.put("key", key);
|
|
|
- map.put("count", count);
|
|
|
- maps.add(map);
|
|
|
+ if (esGroupFiled.equals("mark_time")) {
|
|
|
+ List<DateHistogramBucket> list = agg.dateHistogram().buckets().array();
|
|
|
+ for (DateHistogramBucket bucket : list) {
|
|
|
+ String key = bucket.keyAsString();
|
|
|
+ Long count = bucket.docCount();
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("key", key);
|
|
|
+ map.put("count", count);
|
|
|
+ maps.add(map);
|
|
|
+ }
|
|
|
}
|
|
|
- maps =this.loadNameMap(maps,groupField);
|
|
|
+ else {
|
|
|
+ List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
+ for (StringTermsBucket bucket : list) {
|
|
|
+ String key = bucket.key().stringValue();
|
|
|
+ Long count = bucket.docCount();
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("key", key);
|
|
|
+ map.put("count", count);
|
|
|
+ maps.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ maps = this.loadNameMap(maps, groupField);
|
|
|
records.setData(maps);
|
|
|
|
|
|
Aggregate totalAgg = response.aggregations().get("total");
|
|
@@ -286,6 +309,7 @@ public class EsScratchWordsService {
|
|
|
records.setCurrent(current);
|
|
|
records.setSize(size);
|
|
|
} catch (Exception e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
}
|
|
|
return records;
|
|
|
}
|