I want to build an ElasticSearch Nest SearchDescriptor dynamically using conditional Match. The UI has two check boxes "Exclude Email" and "Exclude Loose Files". If both are checked, the search result will match 0 hits.
These 4 queries work, but I can't figure out how to make the Match parts dynamic based on conditions (other than just having 'if-elseif-else' statements for each permutation of UI check-boxes).
Thank you for any suggestions you have.
var searchDescriptor = new SearchDescriptor<MyDocument>()
.Query(q => q
.Match(m => m.OnField(p => p.isemail).Query("true"))
&& q.Match(m => m.OnField(p => p.isemail).Query("false"))
&& q.QueryString(p => p.Query(searchParameters.query).DefaultOperator(Operator.And))
&& q.Term(p => p.Author, searchParameters.author == null ? null : searchParameters.author.ToLower())
);
var searchDescriptor = new SearchDescriptor<MyDocument>()
.Query(q => q
.Match(m => m.OnField(p => p.isemail).Query("true"))
&& q.QueryString(p => p.Query(searchParameters.query).DefaultOperator(Operator.And))
&& q.Term(p => p.Author, searchParameters.author == null ? null : searchParameters.author.ToLower())
);
var searchDescriptor = new SearchDescriptor<MyDocument>()
.Query(q => q
.Match(m => m.OnField(p => p.isemail).Query("false"))
&& q.QueryString(p => p.Query(searchParameters.query).DefaultOperator(Operator.And))
&& q.Term(p => p.Author, searchParameters.author == null ? null : searchParameters.author.ToLower())
);
var searchDescriptor = new SearchDescriptor<MyDocument>()
.Query(q => q
.QueryString(p => p.Query(searchParameters.query).DefaultOperator(Operator.And))
&& q.Term(p => p.Author, searchParameters.author == null ? null : searchParameters.author.ToLower())
);