Hi,
I have a MustJunction that is not doing what I think it should
Let's say we want to select a bunch of documents based on ids.
AFAIK, the following way would be the way to do it.
Code:
BooleanJunction sj = qb.bool();
for(String id : ids){
sj = sj.should(
qb.keyword().onField("id").matching(id).createQuery()
);
}
Query q = mj.bool().must(
sj.createQuery()
).createQuery();
I would expect Query q to be: +(id:1 id:2 id:3)
However, it is: id:1 id:2 id:3
Returning all records
When I add the following, everything works as expected:
Code:
BooleanJunction sj = qb.bool();
for(String id : ids){
sj = sj.should(
qb.keyword().onField("id").matching(id).createQuery()
);
}
MustJunction mj = qb.bool().must(sj.createQuery());
Query q = mj.must(
qb.keyword().onField("abc").matching("true").createQuery()
).must(
sj.createQuery()
).createQuery();
Query q to be: +(id:1 id:2 id:3) +abc:true
Even though it can be argued that a MustJunction should at least contain two queries, I think this should be considered a bug. Unless, there is a different way to achieve what I want.
Kind regards,
Marc