Currently I query ES for a single key value pair like this:
String query_key = "abc";
String query_val = "def";
searchRequestBuilder.setQuery(QueryBuilders.matchQuery(query_key, query_val)).execute().actionGet();
Now, instead of single key-value pair, I have the following key-value pair map: Map<String,String> query_list
How do I modify the same for this?
You can use MuliMatchQuery or Boolean Query to fulfill your requirement.
ex:-
BoolQueryBuilder boolQuery = new BoolQueryBuilder();
for (Map.Entry<String, String> entry : fields.entrySet()){
boolQuery.must(QueryBuilders.matchQuery(entry.getKey(), entry.getValue()));
}
Set this boolQuery in your searchRequest read the elasticsearch boolQueries and use one which fits for your requirement.
The Above example will perform the AND operation among the provided fields. the field1 and field2 must match. if you want to perform the OR operation then you should use sould query you have an option to set minimum_should_match in that you can specify the minimum fields should match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With