Skip to content

Commit

Permalink
Document Search.collapse() (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Nov 13, 2023
1 parent 1a247fa commit 333aa5a
Showing 1 changed file with 25 additions and 0 deletions.
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

0 comments on commit 333aa5a

Please sign in to comment.