Using the DSL query syntax, you can simply do this:
var results = client.Search(s=>s .Fields(new string[0]) .Query(q=> q.Term(ESFields.City, city) && q.Term(ESFields.State, state) ) );
which relies on conditionless query support added in 0.9.10.0.
This will only trigger a city query if city contains a value and only a state expression query if state not null or empty.
- If both values โโare valid, it will execute a bool request
- If only one is valid, it will execute only one term request
- If none of them is valid, it returns to match_all.
source share