Skip to content

Commit

Permalink
Add support for the CombinedFields query
Browse files Browse the repository at this point in the history
  • Loading branch information
Telomeraz committed Jan 19, 2022
1 parent 523f831 commit e865d8a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions elasticsearch_dsl/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ class SpanWithin(Query):


# core queries
class CombinedFields(Query):
name = "combined_fields"


class Common(Query):
name = "common"

Expand Down
28 changes: 28 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit e865d8a

Please sign in to comment.