Can you suggest how do I build a query based on multiple filter. Currently, I want to implement a search functionality using the following filters:
- ProductName
- Countries (array)
- Cities (array)
The requirements is that, when counties or cities has no selected value, the query assumes that you are searching all countries and cities. If there are selected counties and cities, then the result should be base on the selected counties and cities.
I have the query below to start with.
static void Main(string[] args)
{
var uri = new Uri("http://localhost:9200");
var connectionPool = new SingleNodeConnectionPool(uri);
var settings = new ConnectionSettings(connectionPool);
var client = new ElasticClient(settings);
if (counties.Count > 0)
{
foreach(string country in counties)
{
// Add a query to be added in client.Search
}
}
if (cities.Count > 0)
{
foreach(string city in cities)
{
// Add a query to be added in client.Search
}
}
client.Search<Product>(s => s
.Query(q => q
.Bool(b => b
.Must(mu => mu
.Match(m => m
.Field(f => f.ProductName)
.Query("some text")
),
.
)
)
)
);
}