Skip to content

Document Search.collapse() #1681

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

Merged
merged 2 commits into from
Nov 13, 2023
Merged
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
25 changes: 25 additions & 0 deletions docs/search_dsl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ The ``Search`` object represents the entire search request:

* pagination

* highlighting

* suggestions

* collapsing

* additional parameters

* associated client
Expand Down Expand Up @@ -433,7 +439,26 @@ keyword arguments will be added to the suggest's json as-is which means that it
should be one of ``term``, ``phrase`` or ``completion`` to indicate which type
of suggester should be used.

Collapsing
~~~~~~~~~~

To collapse search results use the ``collapse`` method on your ``Search`` object:

.. code:: python

s = Search().query("match", message="GET /search")
# collapse results by user_id
s = s.collapse("user_id")

The top hits will only include one result per ``user_id``. You can also expand
each collapsed top hit with the ``inner_hits`` parameter,
``max_concurrent_group_searches`` being the number of concurrent requests
allowed to retrieve the inner hits per group:

.. code:: python

inner_hits = {"name": "recent_search", "size": 5, "sort": [{"@timestamp": "desc"}]}
s = s.collapse("user_id", inner_hits=inner_hits, max_concurrent_group_searches=4)

More Like This Query
~~~~~~~~~~~~~~~~~~~~
Expand Down