I am creating dynamic ES query with NEST like this:
var q1 = new MatchQuery() { Field = "similarto.keyword", Query = "55445" };
var q2 = new MatchQuery() { Field = "metatag.keyword", Query = "hot" };
var q3 = q1 || q2;
var response = client.Search<Recommendation>(s => s
.AllTypes().From(0).Size(10)
.Query(q => q3));
This works fine.
But doing the same with the MatchQueryDescriptor<T>
it isn't working:
var q1x = new MatchQueryDescriptor<Recommendation>();
q1x.Field(f => f.Similarto.Suffix("keyword"));
q1x.Query("55445");
var q2x = new MatchQueryDescriptor<Recommendation>();
q2x.Field(f => f.Metatag.Suffix("keyword"));
q2x.Query("hot");
var q3x = q1x || q2x;
On the last line, the compiler complains about: Operator '||' cannot be applied to operands of type 'MatchQueryDescriptor<Recommendation>' and 'MatchQueryDescriptor<Recommendation>'
I can live with the first version. But the second is nicer because of the strongly typed arguments.
Is it somehow possible to use the binary operators ||
, &&
, etc. on *QueryDescriptor<T>
?
Or is it somehow possible to use binary operators with strongly typed arguments?