本文整理汇总了Python中nefertari.elasticsearch.ES.get_collection方法的典型用法代码示例。如果您正苦于以下问题:Python ES.get_collection方法的具体用法?Python ES.get_collection怎么用?Python ES.get_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nefertari.elasticsearch.ES
的用法示例。
在下文中一共展示了ES.get_collection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getitem_es
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import get_collection [as 别名]
def getitem_es(self, key):
""" Get item with ID of :key: from elasticsearch """
from nefertari.elasticsearch import ES
es = ES(self.__context_class__.__name__)
pk_field = self.__context_class__.pk_field()
kwargs = {
pk_field: key,
'_limit': 1,
'__raise_on_empty': True,
}
obj = es.get_collection(**kwargs)[0]
obj.__acl__ = self.context_acl(obj)
obj.__parent__ = self
obj.__name__ = key
return obj
示例2: get_collection_es
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import get_collection [as 别名]
def get_collection_es(self, **kwargs):
""" Get ES objects collection taking into account the generated
queryset of parent view.
This method allows working with nested resources properly. Thus a
queryset returned by this method will be a subset of its parent view's
queryset, thus filtering out objects that don't belong to the parent
object.
"""
from nefertari.elasticsearch import ES
es = ES(self.Model.__name__)
objects_ids = self._parent_queryset_es()
if objects_ids is not None:
objects_ids = self.get_es_object_ids(objects_ids)
if not objects_ids:
return []
self._query_params['id'] = objects_ids
return es.get_collection(
_raw_terms=self._get_raw_terms(),
**self._query_params)