2016-05-28 3 views
1

これで、ESで(右)クエリを作成し、センスプラグインを使用してローカルESインストールに対してテストしたところ、私は今問題に直面しています:ES JAVA APIを使用して自分のコードから同じことを行う方法。ここで私が翻訳しようとしているクエリは次のとおりです。ElasticSearchのマルチ検索クエリをcURLからJAVAに変換する方法は?

{ 
"size": 5, 
"query": { 
    "multi_match": { 
    "query": "physics", 
    "type": "most_fields", 
    "fields": [ 
     "document.title^10", 
     "document.title.shingles^2", 
     "document.title.ngrams", 
     "person.name^10", 
     "person.name.shingles^2", 
     "person.name.ngrams", 
     "document.topics.name^10", 
     "document.topics.name.shingles^2", 
     "document.topics.name.ngrams" 
     ], 
     "operator": "and" 
    } 
    } 
}' 

私はそれがこのようなものでなければなりません知っているが、私はかなりわからない:

Node node = nodeBuilder().client(true).node(); 
    Client client = node.client(); 

    SearchResponse response = client.prepareSearch("dlsnew") 
      .setTypes("person", "document") 
      .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 
      .setQuery(QueryBuilders.multiMatchQuery("physics", 
        "document.title^10", 
        "document.title.shingles^2", 
        "document.title.ngrams", 
        "person.name^10", 
        "person.name.shingles^2", 
        "person.name.ngrams", 
        "document.topics.name^10", 
        "document.topics.name.shingles^2", 
        "document.topics.name.ngrams")) 
      .setFrom(0).setSize(5).setExplain(true) 
      .execute() 
      .actionGet(); 

    SearchHit[] results = response.getHits().getHits(); 

また、「演算子」をどのように扱うかと"type": "most_fields"の部分をクエリから取得しますか?

答えて

1

あなたは、ほぼそれに動作します

QueryBuilders.multiMatchQuery("physics", 
       "document.title^10", 
       "document.title.shingles^2", 
       "document.title.ngrams", 
       "person.name^10", 
       "person.name.shingles^2", 
       "person.name.ngrams", 
       "document.topics.name^10", 
       "document.topics.name.shingles^2", 
       "document.topics.name.ngrams") 
       .operator(MatchQueryBuilder.Operator.AND) 
       .type(MultiMatchQueryBuilder.Type.MOST_FIELDS); 
+0

おかげで、やりました! –

関連する問題