2 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
嘗試這個(gè):
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder
.filter(QueryBuilders.termQuery("user", "kimchy"))
.filter(QueryBuilders.termQuery("city", "london"));
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(boolQueryBuilder);
的filter/must/should方法BoolQueryBuilder,取決于你想要哪個(gè)上下文,如果你想要“或”,你可以使用should。

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
大家可以試試這個(gè)。
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
foreach (var term in (s + ',' + t).Split(','))
{
booleanQuery.add(new TermQuery(new Term("content", term)), BooleanClause.Occur.SHOULD);
}
//booleanQuery.add(new TermQuery(new Term("content", s)), BooleanClause.Occur.MUST);
//booleanQuery.add(new TermQuery(new Term("content", t)), BooleanClause.Occur.MUST);
TopDocs hits = searcher.search(booleanQuery.build(), int.MaxValue);
添加回答
舉報(bào)