Signed-off-by: Lu Weitao luweitaobe@163.com --- lib/es_query.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/es_query.rb b/lib/es_query.rb index 8c5a28fe..9d596bb2 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -15,17 +15,20 @@ class ESQuery end
# Example @items: { key1 => value1, key2 => [value2, value3, ..], ...} + # Example @unmatch_items: { key1 => value1, key2 => [value2, value3, ..], ...} # means to query: key1 == value1 && (key2 in [value2, value3, ..]) - def multi_field_query(items, size: 10_000, desc_keyword: nil) + def multi_field_query(items, unmatch_items: {}, size: 10_000, desc_keyword: nil) unless items warn 'empty filter!' exit end query_fields = build_multi_field_subquery_body items + unmatch_fields = build_multi_field_subquery_body unmatch_items query = { query: { bool: { - must: query_fields + must: query_fields, + must_not: unmatch_fields } }, size: size }