diff --git a/docs/api.rst b/docs/api.rst index 839cc5cb..3e69437f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -11,6 +11,11 @@ API Documentation we, however, recommend that people use keyword arguments for all calls for consistency and safety. +.. note:: + + for compatibility with the Python ecosystem we use ``from_`` instead of + ``from`` and ``doc_type`` instead of ``type`` as parameter names. + .. py:module:: elasticsearch Elasticsearch diff --git a/elasticsearch/client/__init__.py b/elasticsearch/client/__init__.py index 2fdafa3d..00c0066e 100644 --- a/elasticsearch/client/__init__.py +++ b/elasticsearch/client/__init__.py @@ -294,7 +294,7 @@ class Elasticsearch(object): @query_params('_source', '_source_exclude', '_source_include', 'analyze_wildcard', 'analyzer', 'default_operator', 'df', 'explain', 'fields', 'ignore_indices', 'indices_boost', 'lenient', - 'lowercase_expanded_terms', 'offset', 'preference', 'q', 'routing', + 'lowercase_expanded_terms', 'from_', 'preference', 'q', 'routing', 'scroll', 'search_type', 'size', 'sort', 'source', 'stats', 'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text', 'timeout', 'version') @@ -330,7 +330,7 @@ class Elasticsearch(object): :arg lenient: Specify whether format-based query failures (such as providing text to a numeric field) should be ignored :arg lowercase_expanded_terms: Specify whether query terms should be lowercased - :arg offset: Starting offset (default: 0) + :arg from_: Starting offset (default: 0) :arg preference: Specify the node or shard the operation should be performed on (default: random) :arg q: Query in the Lucene query string syntax @@ -350,6 +350,10 @@ class Elasticsearch(object): :arg timeout: Explicit operation timeout :arg version: Specify whether to return document version as part of a hit """ + # from is a reserved word so it cannot be used, use from_ instead + if 'from_' in params: + params['from'] = params.pop('from_') + if doc_type and not index: index = '_all' _, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_search'), diff --git a/test_elasticsearch/test_client/__init__.py b/test_elasticsearch/test_client/__init__.py index caa77eda..800ecb0b 100644 --- a/test_elasticsearch/test_client/__init__.py +++ b/test_elasticsearch/test_client/__init__.py @@ -1,6 +1,6 @@ from elasticsearch.client import _normalize_hosts -from ..test_cases import TestCase +from ..test_cases import TestCase, ElasticsearchTestCase class TestNormalizeHosts(TestCase): def test_none_uses_defaults(self): @@ -17,3 +17,9 @@ class TestNormalizeHosts(TestCase): def test_dicts_are_left_unchanged(self): self.assertEquals([{"host": "local", "extra": 123}], _normalize_hosts([{"host": "local", "extra": 123}])) + +class TestClient(ElasticsearchTestCase): + def test_from_in_search(self): + self.client.search(index='i', doc_type='t', from_=10) + calls = self.assert_url_called('GET', '/i/t/_search') + self.assertEquals([({'from': '10'}, None)], calls)