Follow our own advice and use kwargs
This commit is contained in:
+2
-2
@@ -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'}
|
||||
|
||||
|
||||
|
||||
+5
-7
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user