Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tweak style and docs of multi_get. No behavior changes.

("id" is not a keyword, and it's very rarely used, so I don't generally give it the _ treatment.)
  • Loading branch information...
commit 8d8675ce62e002cf28c8229112878055ce7c085f 1 parent 8e83e7c
@erikrose erikrose authored
Showing with 13 additions and 15 deletions.
  1. +13 −15 pyelasticsearch/client.py
View
28 pyelasticsearch/client.py
@@ -452,19 +452,20 @@ def get(self, index, doc_type, id, query_params=None):
query_params=query_params)
@es_kwargs()
- def multi_get(self, ids, index=None, doc_type=None, fields=None, query_params=None):
+ def multi_get(self, ids, index=None, doc_type=None, fields=None,
+ query_params=None):
"""
Get multiple typed JSON documents from ES.
:arg ids: An iterable, each element of which can be either an a dict or
- an id (int or sting). Ids are taken to be document IDs. Dicts are
+ an id (int or string). IDs are taken to be document IDs. Dicts are
passed through the Multi Get API essentially verbatim, except that
any missing ``_type``, ``_index``, or ``fields`` keys are filled in
from the defaults given in the ``index``, ``doc_type``, and
``fields`` args.
- :arg index: optional index name from which to retrieve
- :arg doc_type: optional type of the document to get
- :arg fields: optionally only return the defined fields
+ :arg index: Default index name from which to retrieve
+ :arg doc_type: Default type of document to get
+ :arg fields: Default fields to return
See `ES's Multi Get API`_ for more detail.
@@ -474,22 +475,19 @@ def multi_get(self, ids, index=None, doc_type=None, fields=None, query_params=No
doc_template = dict(
filter(
itemgetter(1),
- [("_index", index), ("_type", doc_type), ("fields", fields)]
- )
- )
+ [('_index', index), ('_type', doc_type), ('fields', fields)]))
docs = []
- req = {"docs": docs}
-
- for id_ in ids:
+ for id in ids:
doc = doc_template.copy()
- if isinstance(id_, dict):
- doc.update(id_)
+ if isinstance(id, dict):
+ doc.update(id)
else:
- doc["_id"] = id_
+ doc['_id'] = id
docs.append(doc)
- return self.send_request('GET', ["_mget"], req, query_params=query_params)
+ return self.send_request(
+ 'GET', ['_mget'], {'docs': docs}, query_params=query_params)
@es_kwargs('routing', 'parent', 'timeout', 'replication', 'consistency',
'percolate', 'refresh', 'retry_on_conflict', 'fields')
Please sign in to comment.
Something went wrong with that request. Please try again.