当前ES api文档上面看到
SearchRequestBuilder srb1 = node.client() .prepareSearch().setQuery(QueryBuilders.queryStringQuery("elasticsearch")).setSize(1); SearchRequestBuilder srb2 = node.client() .prepareSearch().setQuery(QueryBuilders.matchQuery("name", "kimchy")).setSize(1); MultiSearchResponse sr = node.client().prepareMultiSearch() .add(srb1) .add(srb2) .execute().actionGet(); // You will get all inpidual responses from MultiSearchResponse#getResponses() long nbHits = 0; for (MultiSearchResponse.Item item : sr.getResponses()) { SearchResponse response = item.getResponse(); nbHits += response.getHits().getTotalHits(); }
这一段多查询条件代码,但是由于match查询接受一个operator参数,该参数的默认值是"or"。可以将它改变为"and"来要求所有的词条都需要被匹配:
GET /my_index/my_type/_search { "query": { "match": { "title": { "query": "BROWN DOG!", "operator": "and" } } } }
源代码如上,现在需要改进java api使用方式,请指教,谢谢
光阴似箭催人老,日月如移越少年。