feat: Add a collapse method to opensearchpy.helpers.search.Search (#409)

Signed-off-by: Quentin Coumes <[email protected]>
Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
This commit is contained in:
C. Quentin
2023-06-26 19:19:15 -04:00
committed by GitHub
co-authored by Daniel Doubrovkine
parent e5789c7b52
commit db972e615b
3 changed files with 62 additions and 0 deletions
@@ -266,6 +266,40 @@ def test_sort_by_score():
s.sort("-_score")
def test_collapse():
s = search.Search()
inner_hits = {"name": "most_recent", "size": 5, "sort": [{"@timestamp": "desc"}]}
s = s.collapse(
field="user.id", inner_hits=inner_hits, max_concurrent_group_searches=4
)
assert {
"field": "user.id",
"inner_hits": {
"name": "most_recent",
"size": 5,
"sort": [{"@timestamp": "desc"}],
},
"max_concurrent_group_searches": 4,
} == s._collapse
assert {
"collapse": {
"field": "user.id",
"inner_hits": {
"name": "most_recent",
"size": 5,
"sort": [{"@timestamp": "desc"}],
},
"max_concurrent_group_searches": 4,
}
} == s.to_dict()
s = s.collapse()
assert {} == s._collapse
assert search.Search().to_dict() == s.to_dict()
def test_slice():
s = search.Search()
assert {"from": 3, "size": 7} == s[3:10].to_dict()