Skip to content

Commit e865d8a

Browse files
authored
Add support for the CombinedFields query
1 parent 523f831 commit e865d8a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

elasticsearch_dsl/query.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ class SpanWithin(Query):
355355

356356

357357
# core queries
358+
class CombinedFields(Query):
359+
name = "combined_fields"
360+
361+
358362
class Common(Query):
359363
name = "common"
360364

tests/test_query.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,34 @@ def test_empty_Q_is_match_all():
2727
assert query.MatchAll() == q
2828

2929

30+
def test_combined_fields_to_dict():
31+
assert {
32+
"combined_fields": {
33+
"query": "this is a test",
34+
"fields": ["name", "body", "description"],
35+
"operator": "and",
36+
},
37+
} == query.CombinedFields(
38+
query="this is a test",
39+
fields=["name", "body", "description"],
40+
operator="and",
41+
).to_dict()
42+
43+
44+
def test_combined_fields_to_dict_extra():
45+
assert {
46+
"combined_fields": {
47+
"query": "this is a test",
48+
"fields": ["name", "body^2"],
49+
"operator": "or",
50+
},
51+
} == query.CombinedFields(
52+
query="this is a test",
53+
fields=["name", "body^2"],
54+
operator="or",
55+
).to_dict()
56+
57+
3058
def test_match_to_dict():
3159
assert {"match": {"f": "value"}} == query.Match(f="value").to_dict()
3260

0 commit comments

Comments
 (0)