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

Allow params to be added to FacetedSearches #1500

Merged
merged 1 commit into from
Apr 23, 2024
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
9 changes: 9 additions & 0 deletions elasticsearch_dsl/faceted_search_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@ def sort(self, search):
search = search.sort(*self._sort)
return search

def params(self, **kwargs):
"""
Specify query params to be used when executing the search. All the
keyword arguments will override the current values. See
https://elasticsearch-py.readthedocs.io/en/master/api.html#elasticsearch.Elasticsearch.search
for all available parameters.
"""
self._s = self._s.params(**kwargs)

def build_search(self):
"""
Construct the ``Search`` object.
Expand Down
7 changes: 7 additions & 0 deletions tests/_async/test_faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,10 @@ def test_date_histogram_no_interval_keyerror():
with pytest.raises(KeyError) as e:
dhf.get_value_filter(datetime.now())
assert str(e.value) == "'interval'"


def test_params_added_to_search():
bs = BlogSearch("python search")
assert bs._s._params == {}
bs.params(routing="42")
assert bs._s._params == {"routing": "42"}
7 changes: 7 additions & 0 deletions tests/_sync/test_faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,10 @@ def test_date_histogram_no_interval_keyerror():
with pytest.raises(KeyError) as e:
dhf.get_value_filter(datetime.now())
assert str(e.value) == "'interval'"


def test_params_added_to_search():
bs = BlogSearch("python search")
assert bs._s._params == {}
bs.params(routing="42")
assert bs._s._params == {"routing": "42"}
Loading