Java es should_@Es问题--should和must同时使用

问题描述:caseopened、confirmed、phoneopened三个字段。当caseopened和confirmed同时为true时,或者当phoneopened为true时返回数据。

caseopened:true、false

confirmed:true、false

phoneopened:true、false

Java Api:

BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery();

//处理caseopend confirmed phoneopend

BoolQueryBuilder filterCaseBuilder = QueryBuilders.boolQuery();

filterCaseBuilder.must(QueryBuilders.termQuery("confirmed", true));

filterCaseBuilder.must(QueryBuilders.termQuery("caseopened", true));

BoolQueryBuilder filterPhoneBuilder = QueryBuilders.boolQuery();

filterPhoneBuilder.must(QueryBuilders.termQuery("phoneopened", true));

filterBuilder.should(filterCaseBuilder).should(filterPhoneBuilder);

BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();

boolQueryBuilder.must(filterBuilder);

{

"bool":{

"should":[

{

"bool":{

"must":[

{

"term":{

"confirmed":{

"value":1,

"boost":1

}

}

},

{

"term":{

"caseopened":{

"value":true,

"boost":1

}

}

}

],

"adjust_pure_negative":true,

"boost":1

}

},

{

"bool":{

"must":[

{

"term":{

"phoneopened":{

"value":true,

"boost":1

}

}

}

],

"adjust_pure_negative":true,

"boost":1

}

}

],

"adjust_pure_negative":true,

"boost":1

}

}

你可能感兴趣的:(Java,es,should)