Skip to content

Commit 333aa5a

Browse files
authored
Document Search.collapse() (#1681)
1 parent 1a247fa commit 333aa5a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/search_dsl.rst

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ The ``Search`` object represents the entire search request:
1818

1919
* pagination
2020

21+
* highlighting
22+
23+
* suggestions
24+
25+
* collapsing
26+
2127
* additional parameters
2228

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

442+
Collapsing
443+
~~~~~~~~~~
444+
445+
To collapse search results use the ``collapse`` method on your ``Search`` object:
446+
447+
.. code:: python
448+
449+
s = Search().query("match", message="GET /search")
450+
# collapse results by user_id
451+
s = s.collapse("user_id")
452+
453+
The top hits will only include one result per ``user_id``. You can also expand
454+
each collapsed top hit with the ``inner_hits`` parameter,
455+
``max_concurrent_group_searches`` being the number of concurrent requests
456+
allowed to retrieve the inner hits per group:
457+
458+
.. code:: python
436459
460+
inner_hits = {"name": "recent_search", "size": 5, "sort": [{"@timestamp": "desc"}]}
461+
s = s.collapse("user_id", inner_hits=inner_hits, max_concurrent_group_searches=4)
437462
438463
More Like This Query
439464
~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)