From 707dcc5ec35d1d33a2bfdcb4c41980c2794b5b79 Mon Sep 17 00:00:00 2001 From: Honza Kral Date: Tue, 24 Sep 2013 17:22:31 +0200 Subject: [PATCH] Follow our own advice and use kwargs --- README.rst | 4 ++-- docs/index.rst | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 16552995..c4d3222a 100644 --- a/README.rst +++ b/README.rst @@ -18,11 +18,11 @@ Simple use-case:: >>> es = Elasticsearch() # datetimes will be serialized - >>> es.index("my-index", "test-type", {"any": "data", "timestamp": datetime.now()}, id=42) + >>> es.index(index="my-index", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()}) {u'_id': u'42', u'_index': u'my-index', u'_type': u'test-type', u'_version': 1, u'ok': True} # but not deserialized - >>> es.get("my-index", 42, doc_type="test-type")['_source'] + >>> es.get(index="my-index", doc_type="test-type", id=42)['_source'] {u'any': u'data', u'timestamp': u'2013-05-12T19:45:31.804229'} diff --git a/docs/index.rst b/docs/index.rst index ee0f311c..b5bcd7ec 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -12,12 +12,10 @@ Example Usage .. testsetup:: - import os from datetime import datetime - index_name = os.environ.get('ES_TEST_INDEX', 'test-index') from elasticsearch import Elasticsearch es = Elasticsearch() - es.delete_index(index_name, ignore_missing=True) + es.delete_index("test_index", ignore_missing=True) .. testcode:: @@ -29,15 +27,15 @@ Example Usage 'text': 'Elasticsearch: cool. bonsai cool.', 'timestamp': datetime(2010, 10, 10, 10, 10, 10) } - res = es.index(index_name, 'tweet', doc, id=1) + res = es.index(index="test-index", doc_type='tweet', doc, id=1) print(res['ok']) - res = es.get(index_name, 1, doc_type='tweet') + res = es.get(index="test-index", doc_type='tweet', id=1) print(res['_source']) - es.refresh(index_name) + es.refresh(index="test-index") - res = es.search('cool', index=index_name) + res = es.search(index="test-index", body={"query": {"match_all": {}}}) print("Got %d Hits:" % res['hits']['total']) for hit in res['hits']['hits']: print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])