|
@@ -33,6 +33,7 @@ import org.elasticsearch.search.sort.SortOrder;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -54,8 +55,23 @@ public class EsQueryServiceImpl implements EsQueryService {
|
|
private static List<EsIndexfieldVo> indexFields = null;
|
|
private static List<EsIndexfieldVo> indexFields = null;
|
|
private static long cacheTime = 0;
|
|
private static long cacheTime = 0;
|
|
|
|
|
|
|
|
+ @PostConstruct
|
|
|
|
+ public void init() {
|
|
|
|
+ List<EsIndexVo> list1 = esIndexService.getAllList();
|
|
|
|
+ indexCache = list1.stream()
|
|
|
|
+ .map(m -> m.getIndexCode())
|
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ List<EsIndexfieldVo> list2 = list1.get(0).getFieldList();
|
|
|
|
+
|
|
|
|
+ indexFields = list2.stream().filter(p -> !p.getDataType().equals("NESTED")).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ pathCache = list2.stream().filter(p -> p.getDataType().equals("NESTED"))
|
|
|
|
+ .map(m -> m.getFieldCode())
|
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
|
+ }
|
|
public void getCacheList() {
|
|
public void getCacheList() {
|
|
- synchronized (lockObject) {
|
|
|
|
|
|
+ /*synchronized (lockObject) {
|
|
//从本地缓存加载数据
|
|
//从本地缓存加载数据
|
|
long timeSpan = (new Date()).getTime() - cacheTime;
|
|
long timeSpan = (new Date()).getTime() - cacheTime;
|
|
if (timeSpan > 30 * 1000 || indexCache == null || pathCache == null) {
|
|
if (timeSpan > 30 * 1000 || indexCache == null || pathCache == null) {
|
|
@@ -74,7 +90,7 @@ public class EsQueryServiceImpl implements EsQueryService {
|
|
|
|
|
|
cacheTime = (new Date()).getTime();
|
|
cacheTime = (new Date()).getTime();
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
}
|
|
}
|
|
|
|
|
|
public List<String> getIndexCache() {
|
|
public List<String> getIndexCache() {
|
|
@@ -214,7 +230,7 @@ public class EsQueryServiceImpl implements EsQueryService {
|
|
log.info("dsl:" + searchRequest.source().toString());
|
|
log.info("dsl:" + searchRequest.source().toString());
|
|
SearchResponse response = highLevelClient.search(searchRequest, RequestOptions.DEFAULT);
|
|
SearchResponse response = highLevelClient.search(searchRequest, RequestOptions.DEFAULT);
|
|
|
|
|
|
- log.info("response:" + response.toString());
|
|
|
|
|
|
+ //log.info("response:" + response.toString());
|
|
|
|
|
|
//[6]转换结果,可以对不同的index做出参数输出
|
|
//[6]转换结果,可以对不同的index做出参数输出
|
|
List<Map<String, Object>> rows = searchResponse2List(response);
|
|
List<Map<String, Object>> rows = searchResponse2List(response);
|
|
@@ -397,7 +413,6 @@ public class EsQueryServiceImpl implements EsQueryService {
|
|
line += " " + entry.getKey()
|
|
line += " " + entry.getKey()
|
|
+ ":" + (entry.getValue() == null ? "null" : entry.getValue().toString());
|
|
+ ":" + (entry.getValue() == null ? "null" : entry.getValue().toString());
|
|
}
|
|
}
|
|
- System.out.println(line);
|
|
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|