Skip to content

Commit a4454a4

Browse files
author
Liam Costello
committed
Added logic to allow for multiple slices
1 parent 6af6b8c commit a4454a4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

elasticsearch_dsl/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def __getitem__(self, n):
326326
raise ValueError("Search does not support negative slicing.")
327327
# Elasticsearch won't get all results so we default to size: 10 if
328328
# stop not given.
329-
s._extra['from'] = n.start or 0
329+
s._extra['from'] = (n.start or 0) + s._extra.get('from', 0)
330330
s._extra['size'] = n.stop - (n.start or 0) if n.stop is not None else 10
331331
return s
332332
else: # This is an index lookup, equivalent to slicing by [n:n+1].

test_elasticsearch_dsl/test_search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ def test_slice():
246246
assert {'query': {'match_all': {}}, 'from': 0, 'size': 5} == s[:5].to_dict()
247247
assert {'query': {'match_all': {}}, 'from': 3, 'size': 10} == s[3:].to_dict()
248248
assert {'query': {'match_all': {}}, 'from': 0, 'size': 0} == s[0:0].to_dict()
249+
assert {'query': {'match_all': {}}, 'from': 10, 'size': 5} == s[10:][:5].to_dict()
250+
assert {'query': {'match_all': {}}, 'from': 15, 'size': 10} == s[10:][:5][5:].to_dict()
249251

250252
def test_index():
251253
s = search.Search()

0 commit comments

Comments
 (0)