Elasticsearch Java API実装検索機能(2)マルチフィールドマッチング


前言
   :https://blog.csdn.net/zx711166/article/details/77847120
        :https://blog.csdn.net/Leige_Smart/article/details/80900642
1. client      
2. matchPhraseQuery matchQuery   
3.        
4. 【XX】      

バージョン情報
Elasticsearch:5.6.9
Java:1.8.0

実装機能
     
should must    

shouldとmustの比較
should  :                   
  must  :            ,                  

使用するクラス
import java.net.InetAddress;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.elasticsearch.index.query.MatchQueryBuilder;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Scanner;

検索ルールの設計
 //        matchPhraseQuery matchQuery
 MatchPhraseQueryBuilder mpq1 = QueryBuilders
                .matchPhraseQuery(【tag1】,【key1】);

 MatchQueryBuilder mpq2= QueryBuilders
                .matchQuery(【tag2】,【key2】);

 MatchQueryBuilder mpq3= QueryBuilders
                .matchQuery(【tag3】,【key3】);

 //             
 QueryBuilder qb2 = QueryBuilders.boolQuery()
                .should(mpq1)
                .must(mpq2)
                .must(mpq3);

//       type      
 SearchRequestBuilder searchRequestBuilder = client.prepareSearch(【indices】).setTypes(【type】)
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setQuery(qb2);
 SearchResponse response = searchRequestBuilder 
                .setExplain(true).get();