I've got list of objects called selected
which is this shape: List<{bool Selected, String Discriminator, List<int> Tags}>
.
I need to say if document.VgnItm.Discriminator
is one of selected[index].Discriminator
, AND document.VgnItm.Tags
has at least one tag from selected[index].Tags
, then select that document.
This works when selected
contains only one item:
for (var i = 0; i < selected.Count; i++)
{
QueryContainer &= Query<VgnItmEstSearchDto>.Bool(boolean => boolean.Must(booleanMust =>
booleanMust.Term(term => term.Field(termField => termField.VgnItm.Discriminator)
.Value(selected[i].Discriminator)),
booleanMust => booleanMust.Terms(terms => terms
.Field(p => p.VgnItm.Tags)
.Terms(selected[i].Tags)
))
);
}
But when selected
contains two or more items the QueryContainer &=
means that the document.VgnItm.Discriminator
must be selected[index1].Discriminator
, and also selected[index2].Discriminator
which is impossible. So it doesn't find any results.
What can I do here to make this work when selected contains multiple items? I can't just use QueryContainer |=
because the QueryContainer
has other clauses above. I tried wrapping Query<VgnItmEstSearchDto>.Bool(boolean => boolean.Must
in a Bool.Should
so it is a double Bool, but it had the same result.