elasticsearch 用java client 多个and or 条件 怎么写?

如题,求救
sql: select * from table where active=1 and ( name like '%?%' or code like '%?%' )
elasticsearch 用java client怎么写呢?
 
 
--------------------------------------
 
3Q!
我这么写的
QueryBuilder qb = QueryBuilders.boolQuery()
.must(new QueryStringQueryBuilder("1").field("active"))
.must(QueryBuilders.boolQuery()
    .should(QueryBuilders.matchQuery("name", "小李子"))
    .should(QueryBuilders.matchQuery("code", 小李子"))
);
已邀请:

helloes

赞同来自:

话说你的疑问号是查询条件还是神马?
QueryBuilder queryBuilder = QueryBuilders.filteredQuery(
QueryBuilders.matchAllQuery(),
FilterBuilders.boolFilter()
.must(
FilterBuilders.termFilter("active", 1),
FilterBuilders.boolFilter()
.should(
FilterBuilders.regexpFilter("name", "*xx*"),
FilterBuilders.regexpFilter("code", "*xxx*")
)
)
);

要回复问题请先登录注册