Browse Source

multisearch test

huangxy 6 years ago
parent
commit
c222e0ae0f
1 changed files with 16 additions and 0 deletions
  1. 16 0
      study/src/test/java/com/hxy/study/SearchClientTest.java

+ 16 - 0
study/src/test/java/com/hxy/study/SearchClientTest.java

@@ -76,7 +76,23 @@ public class SearchClientTest {
 //        QueryBuilder timeClause = QueryBuilders.rangeQuery("logtime.keyword").from(startTime).to(endTime);
 //        QueryBuilder queryBuilder = QueryBuilders.matchQuery("logclass.keyword", "com.huohuo.Test");
         // and/or/not等:涉及到多条件查询用boolQuery,组合多个query。must表示and,mustNot表示not,should表示or。
+    }
 
+    @Test
+    public void multiMatchTest() {
+        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+        QueryBuilder queryBuilder = QueryBuilders.multiMatchQuery("黄湘豫想进行驾照考试", "author", "name");
+        searchSourceBuilder.query(queryBuilder);
+        String query = searchSourceBuilder.toString();
+        Search search = new Search.Builder(query)
+                .addIndex("t_paper")
+                .build();
+        try {
+            SearchResult result = jestClient.execute(search);
+            System.out.println(result.getJsonString());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
 
     }