Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CombinedFields query #1557

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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