zero 1 anno fa
parent
commit
e4d4a00e37

+ 9 - 2
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -269,12 +269,19 @@ public class EsService {
      * @param projectId
      * @return
      */
-    public Boolean search(String parentId, Integer projectId){
+    public Boolean search(String parentId, Integer projectId) throws IOException {
         boolean flag = false;
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("patent");
+
         Query q1 = QueryBuilders.term(t -> t.field("project_id").value(projectId));
         Query q2 = QueryBuilders.parentId(parent -> parent.type("project").id(parentId));
         Query bool = QueryBuilders.bool(i -> i.must(q1, q2));
-        if (bool != null) {
+        builder.query(bool);
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        long total = response.hits().total().value();
+        if (total > 0) {
             flag = true;
         }
         return flag;

+ 3 - 2
src/test/java/cn/cslg/pas/service/EventServiceTests.java

@@ -19,6 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -135,8 +136,8 @@ public class EventServiceTests {
     }
 
     @Test
-    void test12(){
-        Boolean bool = esService.search("YST6D4wBmB3pRkTj49Jn", 5);
+    void test12() throws IOException {
+        Boolean bool = esService.search("YiQCGowBmB3pRkTj4NNG", 5);
         System.out.println(bool);
     }
 }