当前位置: 首页>>代码示例>>Python>>正文


Python ES.dump_curl方法代码示例

本文整理汇总了Python中pyes.ES.dump_curl方法的典型用法代码示例。如果您正苦于以下问题:Python ES.dump_curl方法的具体用法?Python ES.dump_curl怎么用?Python ES.dump_curl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyes.ES的用法示例。


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

示例1: get_es

# 需要导入模块: from pyes import ES [as 别名]
# 或者: from pyes.ES import dump_curl [as 别名]
def get_es(**overrides):
    """Return one pyes.es.ES object

    :arg overrides: Allows you to override defaults to create the ES.

    Things you can override:

    * default_indexes
    * timeout
    * dump_curl

    Values for these correspond with the arguments to pyes.es.ES.

    For example, if you wanted to create an ES for indexing with a timeout
    of 30 seconds, you'd do:

    >>> es = get_es(timeout=30)

    If you wanted to create an ES for debugging that dumps curl
    commands to stdout, you could do:

    >>> class CurlDumper(object):
    ...     def write(self, s):
    ...         print s
    ...
    >>> es = get_es(dump_curl=CurlDumper())
    """
    if overrides or not hasattr(_local, 'es'):
        defaults = {
            'default_indexes': DEFAULT_INDEXES,
            'timeout': DEFAULT_TIMEOUT,
            'dump_curl': DEFAULT_DUMP_CURL,
            }

        defaults.update(overrides)
        if (not thrift_enable and
            not settings.ES_HOSTS[0].split(':')[1].startswith('92')):
            raise ValueError('ES_HOSTS is not set to a valid port starting '
                             'with 9200-9299 range. Other ports are valid '
                             'if using pythrift.')
        es = ES(settings.ES_HOSTS, **defaults)

        # pyes 0.15 does this lame thing where it ignores dump_curl in
        # the ES constructor and always sets it to None. So what we do
        # is set it manually after the ES has been created and
        # defaults['dump_curl'] is truthy. This might not work for all
        # values of dump_curl.
        if VERSION[0:2] == (0, 15):
            es.dump_curl = (defaults['dump_curl']
                            if defaults['dump_curl'] else None)

        # Cache the es if there weren't any overrides.
        if not overrides:
            _local.es = es
    else:
        es = _local.es

    return es
开发者ID:aparo,项目名称:elasticutils,代码行数:60,代码来源:__init__.py

示例2: get_es

# 需要导入模块: from pyes import ES [as 别名]
# 或者: from pyes.ES import dump_curl [as 别名]
def get_es(hosts=None, default_indexes=None, timeout=None, dump_curl=None,
           **settings):
    """Create an ES object and return it.

    :arg hosts: list of uris; ES hosts to connect to, defaults to
        ``['localhost:9200']``
    :arg default_indexes: list of strings; the default indexes to use,
        defaults to 'default'
    :arg timeout: int; the timeout in seconds, defaults to 5
    :arg dump_curl: function or None; function that dumps curl output,
        see docs, defaults to None
    :arg settings: other settings to pass into `pyes.es.ES`

    Examples:

    >>> es = get_es()


    >>> es = get_es(hosts=['localhost:9200'])


    >>> es = get_es(timeout=30)  # good for indexing


    >>> es = get_es(default_indexes=['sumo_prod_20120627']


    >>> class CurlDumper(object):
    ...     def write(self, text):
    ...         print text
    ...
    >>> es = get_es(dump_curl=CurlDumper())

    """
    # Cheap way of de-None-ifying things
    hosts = hosts or DEFAULT_HOSTS
    default_indexes = default_indexes or DEFAULT_INDEXES
    timeout = timeout if timeout is not None else DEFAULT_TIMEOUT
    dump_curl = dump_curl or DEFAULT_DUMP_CURL

    if not isinstance(default_indexes, list):
        default_indexes = [default_indexes]

    es = ES(hosts,
            default_indexes=default_indexes,
            timeout=timeout,
            dump_curl=dump_curl,
            **settings)

    # pyes 0.15 does this lame thing where it ignores dump_curl in
    # the ES constructor and always sets it to None. So what we do
    # is set it manually after the ES has been created and
    # defaults['dump_curl'] is truthy. This might not work for all
    # values of dump_curl.
    if PYES_VERSION[0:2] == (0, 15) and dump_curl is not None:
        es.dump_curl = dump_curl

    return es
开发者ID:mt3,项目名称:elasticutils,代码行数:60,代码来源:__init__.py


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