• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python elasticsearch.ES类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nefertari.elasticsearch.ES的典型用法代码示例。如果您正苦于以下问题:Python ES类的具体用法?Python ES怎么用?Python ES使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ES类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: index_models

    def index_models(self, model_names):
        self.log.info('Indexing models documents')
        params = self.options.params or ''
        params = dict([[k, v[0]] for k, v in urllib.parse.parse_qs(params).items()])

        for model_name in model_names:
            self.log.info('Processing model `{}`'.format(model_name))
            model = engine.get_document_cls(model_name)

            local_params = dict()
            local_params.update(params)

            if '_limit' not in local_params:
                limit = model.get_collection().count()
                local_params['_limit'] = limit

            chunk_size = int(self.options.chunk or local_params['_limit'])

            es = ES(source=model_name, index_name=self.options.index,
                    chunk_size=chunk_size)

            query_set = model.get_collection(**local_params)
            documents = to_indexable_dicts(query_set)
            self.log.info('Indexing missing `{}` documents'.format(
                model_name))
            es.index_missing_documents(documents)
开发者ID:oleduc,项目名称:nefertari,代码行数:26,代码来源:es.py


示例2: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    config.include("nefertari.engine")
    config.include("nefertari")
    config.include("nefertari.view")
    config.include("nefertari.elasticsearch")

    # Process nefertari settings
    if Settings.asbool("debug"):
        log.warning("*** DEBUG DEBUG DEBUG mode ***")
        config.add_tween("nefertari.tweens.get_tunneling")

    if Settings.asbool("cors.enable"):
        config.add_tween("nefertari.tweens.cors")

    if Settings.asbool("ssl_middleware.enable"):
        config.add_tween("nefertari.tweens.ssl")

    if Settings.asbool("request_timing.enable"):
        config.add_tween("nefertari.tweens.request_timing")

    # Set root factory
    config.root_factory = NefertariRootACL

    # Process auth settings
    root = config.get_root_resource()
    ramses_auth = Settings.asbool("ramses.auth", False)
    root.auth = ramses_auth

    log.info("Parsing RAML")
    parsed_raml = pyraml.parser.load(Settings["ramses.raml_schema"])

    log.info("Starting models generation")
    generate_models(config, raml_resources=parsed_raml.resources)

    if ramses_auth:
        if getattr(config.registry, "auth_model", None) is None:
            from nefertari.authentication.models import AuthUser

            config.registry.auth_model = AuthUser
        from .auth import setup_auth_policies

        setup_auth_policies(config, parsed_raml)

    log.info("Starting server generation")
    generate_server(parsed_raml, config)

    log.info("Running nefertari.engine.setup_database")
    from nefertari.engine import setup_database

    setup_database(config)

    from nefertari.elasticsearch import ES

    ES.setup_mappings()

    if ramses_auth:
        config.include("ramses.auth")

    log.info("Server succesfully generated\n")
开发者ID:mjhea0,项目名称:ramses,代码行数:60,代码来源:__init__.py


示例3: recreate_index

 def recreate_index(self):
     self.log.info('Deleting index')
     ES.delete_index()
     self.log.info('Creating index')
     create_index_with_settings(self.settings)
     self.log.info('Creating mappings')
     ES.setup_mappings()
开发者ID:geniusproject,项目名称:nefertari,代码行数:7,代码来源:es.py


示例4: on_post_bulk_insert

def on_post_bulk_insert(sender,documents,**kw):
    if not documents:
        return
    from nefertari.elasticsearch import ES
    es = ES(source=documents[0].__class__.__name__)
    docs = to_dicts(documents)
    es.index(docs)
开发者ID:kalyankuramana,项目名称:nefertari-mongodb,代码行数:7,代码来源:signals.py


示例5: getitem_es

 def getitem_es(self, key):
     es = ES(self.item_model.__name__)
     obj = es.get_item(id=key)
     obj.__acl__ = self.item_acl(obj)
     obj.__parent__ = self
     obj.__name__ = key
     return obj
开发者ID:alainlompo,项目名称:ramses,代码行数:7,代码来源:acl.py


示例6: on_after_delete

def on_after_delete(mapper, connection, target):
    from nefertari.elasticsearch import ES
    model_cls = target.__class__
    es = ES(model_cls.__name__)
    obj_id = getattr(target, model_cls.pk_field())
    es.delete(obj_id)
    es.index_refs(target)
开发者ID:karthikmm,项目名称:nefertari-sqla,代码行数:7,代码来源:signals.py


示例7: on_after_delete

def on_after_delete(mapper, connection, target):
    from nefertari.elasticsearch import ES
    request = getattr(target, '_request', None)
    model_cls = target.__class__
    es = ES(model_cls.__name__)
    obj_id = getattr(target, model_cls.pk_field())
    es.delete(obj_id, request=request)
    es.index_relations(target, request=request)
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:8,代码来源:signals.py


示例8: includeme

def includeme(config):
    Settings = dictset(config.registry.settings)
    config.include('nefertari.engine')
    config.include('nefertari')
    config.include('nefertari.view')

    # Process nefertari settings
    if Settings.asbool('debug'):
        log.warning('*** DEBUG DEBUG DEBUG mode ***')
        config.add_tween('nefertari.tweens.get_tunneling')

    if Settings.asbool('cors.enable'):
        config.add_tween('nefertari.tweens.cors')

    if Settings.asbool('ssl_middleware.enable'):
        config.add_tween('nefertari.tweens.ssl')

    if Settings.asbool('request_timing.enable'):
        config.add_tween('nefertari.tweens.request_timing')

    # Set root factory
    config.root_factory = NefertariRootACL

    # Process auth settings
    root = config.get_root_resource()
    ramses_auth = Settings.asbool('ramses.auth', False)
    root.auth = ramses_auth

    log.info('Parsing RAML')
    parsed_raml = pyraml.parser.load(Settings['ramses.raml_schema'])

    log.info('Starting models generation')
    generate_models(config, raml_resources=parsed_raml.resources)

    if ramses_auth:
        if getattr(config.registry, 'auth_model', None) is None:
            from nefertari.authentication.models import get_authuser_model
            config.registry.auth_model = get_authuser_model()
        from .auth import setup_auth_policies
        setup_auth_policies(config, parsed_raml)

    config.include('nefertari.elasticsearch')

    log.info('Starting server generation')
    generate_server(parsed_raml, config)

    log.info('Running nefertari.engine.setup_database')
    from nefertari.engine import setup_database
    setup_database(config)

    from nefertari.elasticsearch import ES
    ES.setup_mappings()

    if ramses_auth:
        config.include('ramses.auth')

    log.info('Server succesfully generated\n')
开发者ID:gitter-badger,项目名称:ramses,代码行数:57,代码来源:__init__.py


示例9: run

 def run(self):
     ES.setup(self.settings)
     if self.options.recreate:
         self.recreate_index()
         models = engine.get_document_classes()
         model_names = [
             name for name, model in models.items()
             if getattr(model, '_index_enabled', False)]
     else:
         model_names = split_strip(self.options.models)
     self.index_models(model_names)
开发者ID:mkdir404,项目名称:nefertari,代码行数:11,代码来源:es.py


示例10: on_bulk_delete

def on_bulk_delete(model_cls, objects, request):
    if not getattr(model_cls, '_index_enabled', False):
        return

    pk_field = model_cls.pk_field()
    ids = [getattr(obj, pk_field) for obj in objects]

    from nefertari.elasticsearch import ES
    es = ES(source=model_cls.__name__)
    es.delete(ids, request=request)

    # Reindex relationships
    es.bulk_index_relations(objects, request=request)
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:13,代码来源:signals.py


示例11: on_bulk_update

def on_bulk_update(model_cls, objects, request):
    if not getattr(model_cls, '_index_enabled', False):
        return

    if not objects:
        return

    from nefertari.elasticsearch import ES
    es = ES(source=model_cls.__name__)
    documents = to_dicts(objects)
    es.index(documents, request=request)

    # Reindex relationships
    es.bulk_index_relations(objects, request=request, nested_only=True)
开发者ID:oleduc,项目名称:nefertari-mongodb,代码行数:14,代码来源:signals.py


示例12: getitem_es

 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
开发者ID:gitter-badger,项目名称:ramses,代码行数:15,代码来源:acl.py


示例13: get_es_mapping

    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
开发者ID:oleduc,项目名称:nefertari-sqla,代码行数:59,代码来源:documents.py


示例14: on_bulk_update

def on_bulk_update(update_context):
    request = getattr(
        update_context.query, '_request', None)
    model_cls = update_context.mapper.entity
    if not getattr(model_cls, '_index_enabled', False):
        return

    objects = update_context.query.all()
    if not objects:
        return

    from nefertari.elasticsearch import ES
    es = ES(source=model_cls.__name__)
    es.index(objects, request=request)

    # Reindex relationships
    es.bulk_index_relations(objects, request=request, nested_only=True)
开发者ID:geniusproject,项目名称:nefertari-sqla,代码行数:17,代码来源:signals.py


示例15: run

    def run(self, quiet=False):
        from nefertari.elasticsearch import ES
        ES.setup(self.settings)
        models_paths = split_strip(self.options.models)

        for path in models_paths:
            model = resolve(path)
            model_name = path.split('.')[-1]

            params = self.options.params or ''
            params = dict([
                [k, v[0]] for k, v in urlparse.parse_qs(params).items()
            ])
            params.setdefault('_limit', params.get('_limit', 10000))
            chunk_size = self.options.chunk or params['_limit']

            es = ES(source=model_name, index_name=self.options.index)
            query_set = model.get_collection(**params)
            documents = to_dicts(query_set)

            if self.options.force:
                es.index(documents, chunk_size=chunk_size)
            else:
                es.index_missing(documents, chunk_size=chunk_size)

        return 0
开发者ID:howaryoo,项目名称:nefertari,代码行数:26,代码来源:es.py


示例16: index_models

    def index_models(self, model_names):
        self.log.info('Indexing models documents')
        params = self.options.params or ''
        params = dict([
            [k, v[0]] for k, v in urllib.parse.parse_qs(params).items()
        ])
        params.setdefault('_limit', params.get('_limit', 10000))
        chunk_size = self.options.chunk or params['_limit']

        for model_name in model_names:
            self.log.info('Processing model `{}`'.format(model_name))
            model = engine.get_document_cls(model_name)
            es = ES(source=model_name, index_name=self.options.index,
                    chunk_size=chunk_size)
            query_set = model.get_collection(**params)
            documents = to_dicts(query_set)
            self.log.info('Indexing missing `{}` documents'.format(
                model_name))
            es.index_missing_documents(documents)
开发者ID:mkdir404,项目名称:nefertari,代码行数:19,代码来源:es.py


示例17: on_post_save

def on_post_save(sender, document, **kw):
    """ Add new document to index or update existing. """
    from nefertari.elasticsearch import ES
    common_kw = {'request': getattr(document, '_request', None)}
    created = kw.get('created', False)
    if created:
        es = ES(document.__class__.__name__)
        es.index(document.to_dict(), **common_kw)
    elif not created and document._get_changed_fields():
        es = ES(document.__class__.__name__)
        es.index(document.to_dict(), **common_kw)
        es.index_relations(document, nested_only=True, **common_kw)
开发者ID:oleduc,项目名称:nefertari-mongodb,代码行数:12,代码来源:signals.py


示例18: _get_es_types

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)
开发者ID:geniusproject,项目名称:nefertari-guards,代码行数:10,代码来源:acl_utils.py


示例19: get_collection_es

    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)
开发者ID:gitter-badger,项目名称:ramses,代码行数:22,代码来源:views.py


示例20: _set_object_self

 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)
开发者ID:mbijon,项目名称:nefertari,代码行数:14,代码来源:wrappers.py



注:本文中的nefertari.elasticsearch.ES类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.dictset函数代码示例发布时间:2022-05-27
下一篇:
Python staging.tnm_stage函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap