Elasticsearch应该操作查询

时间:2017-05-17 11:41:40

标签: elasticsearch

我怎么能暗示"应该"操作 ("标记" =" A" OR"标记" =" B")和"名称" =&#34 ;猫"

喜欢?

 BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("tag","A"))
.shold(QueryBuilders.matchQuery("tag","B"))

。必须(QueryBuilders.matchQuery("名称""猫&#34));

1 个答案:

答案 0 :(得分:1)

如果您想("tag"="A" OR "tag"="B") and "name"="cat",请执行以下操作:

 BoolQueryBuilder aOrB = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("tag","A"))
.should(QueryBuilders.matchQuery("tag","B"))

 BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery()
.must(aOrB);
.must(QueryBuilders.matchQuery("name","cat"));