diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 642ce2c88..ea58a44da 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -355,6 +355,10 @@ class SpanWithin(Query): # core queries +class CombinedFields(Query): + name = "combined_fields" + + class Common(Query): name = "common" diff --git a/tests/test_query.py b/tests/test_query.py index 2c9823eff..4b7650375 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -27,6 +27,34 @@ def test_empty_Q_is_match_all(): assert query.MatchAll() == q +def test_combined_fields_to_dict(): + assert { + "combined_fields": { + "query": "this is a test", + "fields": ["name", "body", "description"], + "operator": "and", + }, + } == query.CombinedFields( + query="this is a test", + fields=["name", "body", "description"], + operator="and", + ).to_dict() + + +def test_combined_fields_to_dict_extra(): + assert { + "combined_fields": { + "query": "this is a test", + "fields": ["name", "body^2"], + "operator": "or", + }, + } == query.CombinedFields( + query="this is a test", + fields=["name", "body^2"], + operator="or", + ).to_dict() + + def test_match_to_dict(): assert {"match": {"f": "value"}} == query.Match(f="value").to_dict()