Skip to content

Commit 2bb16fe

Browse files
committed
Make offset in search work. from is a reserved word in python so use from_
Fixes elastic#13 Thanks llonchj, danfairs, vanatteveldt and RonRothman!
1 parent 798778e commit 2bb16fe

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docs/api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ API Documentation
1111
we, however, recommend that people use keyword arguments for all calls for
1212
consistency and safety.
1313

14+
.. note::
15+
16+
for compatibility with the Python ecosystem we use ``from_`` instead of
17+
``from`` and ``doc_type`` instead of ``type`` as parameter names.
18+
1419
.. py:module:: elasticsearch
1520
1621
Elasticsearch

elasticsearch/client/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def update(self, index, doc_type, id, body=None, params=None):
294294
@query_params('_source', '_source_exclude', '_source_include',
295295
'analyze_wildcard', 'analyzer', 'default_operator', 'df',
296296
'explain', 'fields', 'ignore_indices', 'indices_boost', 'lenient',
297-
'lowercase_expanded_terms', 'offset', 'preference', 'q', 'routing',
297+
'lowercase_expanded_terms', 'from_', 'preference', 'q', 'routing',
298298
'scroll', 'search_type', 'size', 'sort', 'source', 'stats',
299299
'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text', 'timeout',
300300
'version')
@@ -330,7 +330,7 @@ def search(self, index=None, doc_type=None, body=None, params=None):
330330
:arg lenient: Specify whether format-based query failures (such as
331331
providing text to a numeric field) should be ignored
332332
:arg lowercase_expanded_terms: Specify whether query terms should be lowercased
333-
:arg offset: Starting offset (default: 0)
333+
:arg from_: Starting offset (default: 0)
334334
:arg preference: Specify the node or shard the operation should be
335335
performed on (default: random)
336336
:arg q: Query in the Lucene query string syntax
@@ -350,6 +350,10 @@ def search(self, index=None, doc_type=None, body=None, params=None):
350350
:arg timeout: Explicit operation timeout
351351
:arg version: Specify whether to return document version as part of a hit
352352
"""
353+
# from is a reserved word so it cannot be used, use from_ instead
354+
if 'from_' in params:
355+
params['from'] = params.pop('from_')
356+
353357
if doc_type and not index:
354358
index = '_all'
355359
_, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_search'),

test_elasticsearch/test_client/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from elasticsearch.client import _normalize_hosts
22

3-
from ..test_cases import TestCase
3+
from ..test_cases import TestCase, ElasticsearchTestCase
44

55
class TestNormalizeHosts(TestCase):
66
def test_none_uses_defaults(self):
@@ -17,3 +17,9 @@ def test_strings_are_parsed_for_port(self):
1717

1818
def test_dicts_are_left_unchanged(self):
1919
self.assertEquals([{"host": "local", "extra": 123}], _normalize_hosts([{"host": "local", "extra": 123}]))
20+
21+
class TestClient(ElasticsearchTestCase):
22+
def test_from_in_search(self):
23+
self.client.search(index='i', doc_type='t', from_=10)
24+
calls = self.assert_url_called('GET', '/i/t/_search')
25+
self.assertEquals([({'from': '10'}, None)], calls)

0 commit comments

Comments
 (0)