Repository: elastic/elasticsearch-dsl-py

Issue:
Add support for "combined_fields" query
Dear team,

could you please consider adding support to the "combind_fields" query? I could see a similar request is raised in #1512, and a PR #1534  for adding the functionality is still open.

Thanks in advance!

Discussion:

Patch:
diff --git a/docs/search_dsl.rst b/docs/search_dsl.rst
index d76f53f..e15b1ea 100644
--- a/docs/search_dsl.rst
+++ b/docs/search_dsl.rst
@@ -445,7 +445,7 @@ A simple example is below
 .. code:: python
 
     from elasticsearch_dsl.query import MoreLikeThis
-    from elasticsearch_dsl Search
+    from elasticsearch_dsl import Search
 
     my_text = 'I want to find something similar'
 
diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py
index 642ce2c..ea58a44 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"
 


Test patch:
diff --git a/tests/test_query.py b/tests/test_query.py
index 2c9823e..4b76503 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()