Browse Source

领域检索切换为RestHighLevelClient

xiaoqiao 3 months ago
parent
commit
3d4250cc3c

+ 1 - 1
src/main/java/com/bowintek/practice/config/HwElasticsearchConfig.java

@@ -32,7 +32,7 @@ public class HwElasticsearchConfig {
         RestHighLevelClient highLevelClient = null;
 
         try {
-            if (config.getIsDev() == 1) {
+            if (config.getIsDev()==1) {
                 highLevelClient = new RestHighLevelClient(
                         RestClient.builder(
                                 new HttpHost(config.getHosts(), config.getPort(), config.getSchema())));

+ 5 - 2
src/main/java/com/bowintek/practice/controller/EsQueryController.java

@@ -99,8 +99,8 @@ public class EsQueryController {
                 Map<String,HighlightField> highlight = (Map<String,HighlightField>) it.get("highlight");
                 for (String key : highlight.keySet()) {
                     //主索引
-                    if (it.keySet().contains(key)) {
-                        it.put(key, highlight.get(key).getFragments()[0].string());
+                    if (it.keySet().contains(key.replace(".keyword",""))) {
+                        it.put(key.replace(".keyword",""), highlight.get(key).getFragments()[0].string());
                     } else {
                         nestedHighlight(it);
                     }
@@ -113,6 +113,9 @@ public class EsQueryController {
     //实现逻辑,查找高亮部分innerHits->highlight的节点内容,替换搜索结果数据里面对应的字段内容
     private void nestedHighlight(Map<String, Object> it) {
         Map<String, Object> innerHits = (Map<String, Object>) it.get("innerHits");
+        if(innerHits==null){
+            return ;
+        }
         for (String nestedKey : innerHits.keySet()) {
             SearchHits nested = (SearchHits) innerHits.get(nestedKey);
             SearchHit[] nestedHits = nested.getHits();

+ 2 - 2
src/main/java/com/bowintek/practice/services/impl/AnalyzeServiceImpl.java

@@ -165,11 +165,11 @@ public class AnalyzeServiceImpl implements AnalyzeService {
             ex.printStackTrace();
             return null;
         }finally {
-            try {
+            /*try {
                 highLevelClient.close();
             } catch (IOException e) {
                 throw new RuntimeException(e);
-            }
+            }*/
         }
     }
 

+ 6 - 10
src/main/java/com/bowintek/practice/services/impl/EsQueryServiceImpl.java

@@ -44,9 +44,7 @@ import java.util.stream.Collectors;
 @Slf4j
 public class EsQueryServiceImpl implements EsQueryService {
     @Autowired
-    RestHighLevelClient highLevelClient;
-    @Autowired
-    private RestHighLevelClient esClient;
+    private RestHighLevelClient highLevelClient;
     @Autowired
     private AnalyzeService analyzeService;
     @Autowired
@@ -200,11 +198,10 @@ public class EsQueryServiceImpl implements EsQueryService {
             searchBuilder.aggregation(aggregation);
 
             //[5]Es发起查询
-            //SearchRequest request = searchRequest.build();
-            SearchRequest request =searchRequest.source(searchBuilder);
+            searchRequest.source(searchBuilder);
 
             log.info("dsl:" + searchRequest.source().toString());
-            SearchResponse response = esClient.search(searchRequest, RequestOptions.DEFAULT);
+            SearchResponse response = highLevelClient.search(searchRequest, RequestOptions.DEFAULT);
 
             log.info("response:" + response.toString());
 
@@ -219,8 +216,8 @@ public class EsQueryServiceImpl implements EsQueryService {
             result.put("Message", ex.getMessage());
             result.put("StackTrace", ex.getStackTrace());
         }finally {
-            /*try {
-                //esClient.close();
+           /* try {
+                highLevelClient.close();
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }*/
@@ -322,8 +319,7 @@ public class EsQueryServiceImpl implements EsQueryService {
         else if (opreation.equals("小于等于"))
             query = QueryBuilders.rangeQuery(fieldString).lte(value);
         else if (opreation.equals("等于"))
-            query = QueryBuilders.matchQuery(fieldString, value)
-                    .minimumShouldMatch("80%");
+            query = QueryBuilders.termQuery(fieldString+".keyword", value);
         else if (opreation.equals("包括IN")) {
             String[] fls = value.split(",");
             query=QueryBuilders.termsQuery(fieldString, fls);

+ 52 - 41
target/classes/META-INF/MANIFEST.MF

@@ -1,44 +1,55 @@
 Manifest-Version: 1.0
 Main-Class: com.bowintek.practice.PracticeApplication
-Class-Path: spring-boot-starter-web-2.7.2.jar tomcat-embed-el-9.0.65.jar
-  commons-codec-1.15.jar jul-to-slf4j-1.7.36.jar postgresql-42.3.6.jar n
- etty-transport-4.1.79.Final.jar mybatis-spring-boot-starter-2.2.2.jar c
- ommons-pool2-2.11.1.jar poi-ooxml-schemas-4.0.0.jar mybatis-spring-2.0.
- 7.jar spring-boot-starter-json-2.7.2.jar spring-beans-5.3.22.jar spring
- -oxm-5.3.22.jar elasticsearch-java-8.11.1.jar elasticsearch-rest-client
- -7.17.4.jar spring-jcl-5.3.22.jar lombok-1.18.20.jar spring-data-keyval
- ue-2.7.2.jar netty-resolver-4.1.79.Final.jar lucene-sandbox-4.7.2.jar n
- etty-handler-4.1.79.Final.jar curvesapi-1.04.jar commons-beanutils-1.9.
- 4.jar jackson-datatype-jdk8-2.13.3.jar tomcat-embed-core-9.0.65.jar jak
- arta.annotation-api-1.3.5.jar spring-boot-devtools-2.7.2.jar netty-code
- c-4.1.79.Final.jar logback-classic-1.2.11.jar commons-compress-1.18.jar
-  mybatis-3.5.9.jar pagehelper-5.3.1.jar aspectjrt-1.9.7.jar lettuce-cor
- e-6.1.9.RELEASE.jar druid-1.2.11.jar pagehelper-spring-boot-starter-1.4
- .3.jar commons-collections4-4.2.jar jackson-datatype-jsr310-2.13.3.jar 
- spring-expression-5.3.22.jar mysql-connector-java-8.0.29.jar httpcore-4
- .4.15.jar jackson-module-parameter-names-2.13.3.jar spring-web-5.3.22.j
- ar lucene-queries-4.7.2.jar fastjson-1.2.47.jar httpasyncclient-4.1.5.j
- ar spring-context-support-5.3.22.jar aspectjweaver-1.9.7.jar lucene-que
- ryparser-4.7.2.jar spring-tx-5.3.22.jar spring-boot-starter-jdbc-2.7.2.
- jar netty-buffer-4.1.79.Final.jar HikariCP-4.0.3.jar spring-core-5.3.22
- .jar opentelemetry-api-1.29.0.jar spring-data-redis-2.7.2.jar spring-bo
- ot-starter-logging-2.7.2.jar mybatis-spring-boot-autoconfigure-2.2.2.ja
- r poi-4.0.0.jar lucene-analyzers-common-4.7.2.jar commons-collections-3
- .2.2.jar httpclient-4.5.9.jar commons-logging-1.2.jar poi-ooxml-4.0.0.j
- ar log4j-api-2.17.2.jar jsr305-3.0.2.jar lucene-core-4.7.2.jar spring-b
- oot-starter-2.7.2.jar spring-jdbc-5.3.22.jar spring-data-commons-2.7.2.
- jar netty-common-4.1.79.Final.jar commons-net-3.6.jar spring-webmvc-5.3
- .22.jar ikanalyzer-2012_u6.jar jakarta.json-api-2.0.1.jar druid-spring-
- boot-starter-1.2.11.jar spring-boot-starter-tomcat-2.7.2.jar checker-qu
- al-3.5.0.jar httpcore-nio-4.4.15.jar spring-boot-2.7.2.jar jackson-core
- -2.13.3.jar logback-core-1.2.11.jar log4j-to-slf4j-2.17.2.jar spring-bo
- ot-starter-data-redis-2.7.2.jar pagehelper-spring-boot-autoconfigure-1.
- 4.3.jar poi-scratchpad-4.0.0.jar jackson-databind-2.13.3.jar snakeyaml-
- 1.30.jar slf4j-api-1.7.36.jar spring-boot-autoconfigure-2.7.2.jar netty
- -transport-native-unix-common-4.1.79.Final.jar aspose-cells-18.9.jar as
- pose-words-15.8.0-jdk16.jar jsqlparser-4.2.jar parsson-1.0.0.jar xmlbea
- ns-3.0.1.jar commons-lang3-3.5.jar spring-aop-5.3.22.jar tomcat-embed-w
- ebsocket-9.0.65.jar spring-context-5.3.22.jar opentelemetry-context-1.2
- 9.0.jar jackson-annotations-2.13.3.jar java-jwt-3.9.0.jar json-20190722
- .jar reactive-streams-1.0.4.jar reactor-core-3.4.21.jar
+Class-Path: commons-lang3-3.5.jar commons-pool2-2.11.1.jar hppc-0.8.1.ja
+ r lucene-analyzers-common-8.7.0.jar lang-mustache-client-7.10.2-h0.cbu.
+ mrs.320.r33.jar tomcat-embed-core-9.0.65.jar poi-4.0.0.jar snakeyaml-1.
+ 30.jar netty-common-4.1.79.Final.jar spring-data-redis-2.7.2.jar fastjs
+ on-1.2.47.jar spring-data-keyvalue-2.7.2.jar tomcat-embed-el-9.0.65.jar
+  log4j-api-2.17.2.jar elasticsearch-7.10.2-h0.cbu.mrs.320.r33.jar lucen
+ e-join-8.7.0.jar spring-boot-starter-web-2.7.2.jar netty-resolver-4.1.7
+ 9.Final.jar json-20190722.jar jul-to-slf4j-1.7.36.jar elasticsearch-res
+ t-high-level-client-7.10.2-h0.cbu.mrs.320.r33.jar httpcore-4.4.15.jar i
+ kanalyzer-2012_u6.jar spring-expression-5.3.22.jar lucene-memory-8.7.0.
+ jar spring-boot-starter-logging-2.7.2.jar checker-qual-3.5.0.jar lombok
+ -1.18.20.jar elasticsearch-java-8.11.1.jar jackson-annotations-2.13.3.j
+ ar opendistro-sql-jdbc-1.13.0.0-h0.cbu.mrs.320.r33.jar pagehelper-5.3.1
+ .jar compiler-0.9.6.jar mybatis-3.5.9.jar netty-transport-4.1.79.Final.
+ jar elasticsearch-x-content-7.10.2-h0.cbu.mrs.320.r33.jar commons-codec
+ -1.15.jar netty-handler-4.1.79.Final.jar druid-spring-boot-starter-1.2.
+ 11.jar spring-boot-autoconfigure-2.7.2.jar slf4j-api-1.7.36.jar elastic
+ search-secure-sm-7.10.2-h0.cbu.mrs.320.r33.jar spring-jdbc-5.3.22.jar c
+ ommons-logging-1.2.jar lucene-queryparser-4.7.2.jar parsson-1.0.0.jar c
+ urvesapi-1.04.jar jakarta.annotation-api-1.3.5.jar spring-oxm-5.3.22.ja
+ r spring-jcl-5.3.22.jar pagehelper-spring-boot-autoconfigure-1.4.3.jar 
+ lucene-core-8.7.0.jar aspectjweaver-1.9.7.jar httpclient-4.5.9.jar open
+ telemetry-context-1.29.0.jar opentelemetry-api-1.29.0.jar spring-beans-
+ 5.3.22.jar pagehelper-spring-boot-starter-1.4.3.jar spring-boot-starter
+ -jdbc-2.7.2.jar lucene-suggest-8.7.0.jar httpcore-nio-4.4.15.jar jackso
+ n-core-2.13.3.jar netty-codec-4.1.79.Final.jar reactive-streams-1.0.4.j
+ ar elasticsearch-core-7.10.2-h0.cbu.mrs.320.r33.jar spring-tx-5.3.22.ja
+ r lettuce-core-6.1.9.RELEASE.jar httpasyncclient-4.1.5.jar aspectjrt-1.
+ 9.7.jar tomcat-embed-websocket-9.0.65.jar spring-boot-2.7.2.jar lucene-
+ highlighter-8.7.0.jar spring-web-5.3.22.jar logback-core-1.2.11.jar jsq
+ lparser-4.2.jar netty-buffer-4.1.79.Final.jar rank-eval-client-7.10.2-h
+ 0.cbu.mrs.320.r33.jar druid-1.2.11.jar spring-boot-starter-json-2.7.2.j
+ ar spring-core-5.3.22.jar netty-transport-native-unix-common-4.1.79.Fin
+ al.jar logback-classic-1.2.11.jar HikariCP-4.0.3.jar reactor-core-3.4.2
+ 1.jar spring-boot-devtools-2.7.2.jar spring-aop-5.3.22.jar log4j-to-slf
+ 4j-2.17.2.jar ion-java-1.0.2.jar lucene-sandbox-4.7.2.jar spring-data-c
+ ommons-2.7.2.jar spring-boot-starter-tomcat-2.7.2.jar poi-ooxml-schemas
+ -4.0.0.jar commons-beanutils-1.9.4.jar lucene-queries-8.7.0.jar jakarta
+ .json-api-2.0.1.jar jackson-datatype-jsr310-2.13.3.jar commons-collecti
+ ons-3.2.2.jar aspose-cells-18.9.jar joda-time-2.10.4.jar jackson-module
+ -parameter-names-2.13.3.jar spring-boot-starter-2.7.2.jar java-jwt-3.9.
+ 0.jar spring-boot-starter-data-redis-2.7.2.jar jsr305-3.0.2.jar elastic
+ search-geo-7.10.2-h0.cbu.mrs.320.r33.jar poi-scratchpad-4.0.0.jar sprin
+ g-webmvc-5.3.22.jar poi-ooxml-4.0.0.jar mybatis-spring-boot-autoconfigu
+ re-2.2.2.jar mysql-connector-java-8.0.29.jar mapper-extras-client-7.10.
+ 2-h0.cbu.mrs.320.r33.jar spring-context-support-5.3.22.jar spring-conte
+ xt-5.3.22.jar aspose-words-15.8.0-jdk16.jar jackson-databind-2.13.3.jar
+  mybatis-spring-2.0.7.jar commons-compress-1.18.jar aws-java-sdk-core-1
+ .11.452.jar commons-net-3.6.jar commons-collections4-4.2.jar elasticsea
+ rch-rest-client-7.10.2-h0.cbu.mrs.320.r33.jar mybatis-spring-boot-start
+ er-2.2.2.jar xmlbeans-3.0.1.jar jackson-datatype-jdk8-2.13.3.jar postgr
+ esql-42.3.6.jar