本文整理汇总了Python中nefertari.elasticsearch.ES.src2type方法的典型用法代码示例。如果您正苦于以下问题:Python ES.src2type方法的具体用法?Python ES.src2type怎么用?Python ES.src2type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nefertari.elasticsearch.ES
的用法示例。
在下文中一共展示了ES.src2type方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_es_mapping
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 别名]
def get_es_mapping(cls, _depth=None, types_map=None):
""" Generate ES mapping from model schema. """
from nefertari.elasticsearch import ES
if types_map is None:
types_map = TYPES_MAP
if _depth is None:
_depth = cls._nesting_depth
depth_reached = _depth <= 0
nested_substitutions = []
properties = {}
mapping = {
ES.src2type(cls.__name__): {
'properties': properties
}
}
mapper = class_mapper(cls)
columns = {c.name: c for c in mapper.columns}
relationships = {r.key: r for r in mapper.relationships}
for name, column in columns.items():
column_type = column.type
if isinstance(column_type, types.ChoiceArray):
column_type = column_type.impl.item_type
column_type = type(column_type)
if column_type not in types_map:
continue
properties[name] = types_map[column_type]
if hasattr(column, "_es_multi_field") and getattr(column, "_es_multi_field"):
multi_fields = getattr(column, "_es_multi_field")
properties[name] = properties[name].copy()
properties[name]["fields"] = {}
for multi_field_name in multi_fields:
properties[name]["fields"][multi_field_name] = multi_fields[multi_field_name].copy()
properties[name]["fields"][multi_field_name].update(types_map[column_type])
for name, column in relationships.items():
if name in cls._nested_relationships and not depth_reached:
column_type = {'type': 'nested', 'include_in_parent': True}
nested_substitutions.append(name)
submapping, sub_substitutions = column.mapper.class_.get_es_mapping(
_depth=_depth - 1)
column_type.update(list(submapping.values())[0])
properties[name + "_nested"] = column_type
rel_pk_field = column.mapper.class_.pk_field_type()
column_type = types_map[rel_pk_field]
properties[name] = column_type
properties['_pk'] = {'type': 'string'}
return mapping, nested_substitutions
示例2: _get_es_types
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 别名]
def _get_es_types(models):
""" Get ES types from document model classes.
:param models: List of document classes.
:returns: String with ES type names joing by comma.
"""
type_names = [t.__name__ for t in models
if getattr(t, '_index_enabled', False)]
es_types = [ES.src2type(name) for name in type_names]
return ','.join(es_types)
示例3: _set_object_self
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 别名]
def _set_object_self(self, obj):
""" Add '_self' key value to :obj: dict. """
from nefertari.elasticsearch import ES
location = self.request.path_url
try:
type_, obj_pk = obj['_type'], obj['_pk']
except KeyError:
return
resource = (self.model_collections.get(type_) or
self.model_collections.get(ES.src2type(type_)))
if resource is not None:
location = self.request.route_url(
resource.uid, **{resource.id_name: obj_pk})
obj.setdefault('_self', location)
示例4: determine_types
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 别名]
def determine_types(self):
""" Determine ES type names from request data.
In particular `request.matchdict['collections']` is used to
determine types names. Its value is comma-separated sequence
of collection names under which views have been registered.
"""
from nefertari.elasticsearch import ES
collections = self.get_collections()
resources = self.get_resources(collections)
models = set([res.view.Model for res in resources])
es_models = [mdl for mdl in models if mdl
and getattr(mdl, '_index_enabled', False)]
types = [ES.src2type(mdl.__name__) for mdl in es_models]
return types
示例5: get_es_mapping
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 别名]
def get_es_mapping(cls, _depth=None, types_map=None):
""" Generate ES mapping from model schema. """
from nefertari.elasticsearch import ES
if types_map is None:
types_map = TYPES_MAP
if _depth is None:
_depth = cls._nesting_depth
depth_reached = _depth <= 0
properties = {}
mapping = {
ES.src2type(cls.__name__): {
'properties': properties
}
}
fields = cls._fields.copy()
for name, field in fields.items():
if isinstance(field, RelationshipField):
field = field.field
if isinstance(field, (ReferenceField, RelationshipField)):
if name in cls._nested_relationships and not depth_reached:
field_mapping = {'type': 'nested'}
submapping = field.document_type.get_es_mapping(
_depth=_depth-1)
field_mapping.update(list(submapping.values())[0])
else:
field_mapping = types_map[
field.document_type.pk_field_type()]
properties[name] = field_mapping
continue
if isinstance(field, ChoiceField):
field = field._real_field
field_type = type(field)
if field_type is ListField:
field_type = field.item_type
if field_type not in types_map:
continue
properties[name] = types_map[field_type]
properties['_pk'] = {'type': 'string'}
return mapping
示例6: _set_object_self
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 别名]
def _set_object_self(self, obj):
""" Add '_self' key value to :obj: dict. """
from nefertari.elasticsearch import ES
location = self.request.path_url
route_kwargs = {}
""" Check for parents """
if self.request.matchdict:
route_kwargs.update(self.request.matchdict)
try:
type_, obj_pk = obj['_type'], obj['_pk']
except KeyError:
return
resource = (self.model_collections.get(type_) or
self.model_collections.get(ES.src2type(type_)))
if resource is not None:
route_kwargs.update({resource.id_name: obj_pk})
location = self.request.route_url(
resource.uid, **route_kwargs)
obj.setdefault('_self', location)
示例7: get_es_mapping
# 需要导入模块: from nefertari.elasticsearch import ES [as 别名]
# 或者: from nefertari.elasticsearch.ES import src2type [as 别名]
def get_es_mapping(cls, _depth=None, types_map=None):
""" Generate ES mapping from model schema. """
from nefertari.elasticsearch import ES
if types_map is None:
types_map = TYPES_MAP
if _depth is None:
_depth = cls._nesting_depth
depth_reached = _depth <= 0
properties = {}
mapping = {
ES.src2type(cls.__name__): {
'properties': properties
}
}
mapper = class_mapper(cls)
columns = {c.name: c for c in mapper.columns}
relationships = {r.key: r for r in mapper.relationships}
for name, column in columns.items():
column_type = column.type
if isinstance(column_type, types.ChoiceArray):
column_type = column_type.impl.item_type
column_type = type(column_type)
if column_type not in types_map:
continue
properties[name] = types_map[column_type]
for name, column in relationships.items():
if name in cls._nested_relationships and not depth_reached:
column_type = {'type': 'nested'}
submapping = column.mapper.class_.get_es_mapping(
_depth=_depth-1)
column_type.update(list(submapping.values())[0])
else:
rel_pk_field = column.mapper.class_.pk_field_type()
column_type = types_map[rel_pk_field]
properties[name] = column_type
properties['_pk'] = {'type': 'string'}
return mapping