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


Python ES.exists_index方法代码示例

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


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

示例1: index

# 需要导入模块: from pyes import ES [as 别名]
# 或者: from pyes.ES import exists_index [as 别名]
def index(fname, index_name, keys_to_tag):
    fptr = open(fname, 'rb')
    line_count = 0
    conn = ES(["localhost:9200"])
    if not conn.exists_index(index_name):
        conn.create_index(index_name)
    start = time.clock()
    numb_exceptions = 0

    for line in fptr:
        if ((line_count % 10000) == 0):
            end = time.clock()
            minutes = (end - start) / 60.0
            print 'File: %s Done with %d took %f min. ' %(fname, line_count, minutes)
            print 'number of exceptions ', numb_exceptions
        line_count += 1
        data = json.loads(line)
        if not data.get('tags'):
            continue
        post_id = int(data['post_id'])
        found_content = False
        for k in keys_to_tag:
            if data.get(k):
                found_content = True
        if not found_content:
            continue
        index_data = dict()
        for k in keys_to_tag:
            value = data.get(k)
            if (value and (k == 'content')):
                try:
                    stripped_value = utils.strip_tags(value)
                except Exception:
                    stripped_value = value
                index_data[k] = stripped_value
        if post_id and data:
            try:
                conn.index(index_data, index_name, "test-type", post_id)
            except Exception:
                numb_exceptions += 1
                continue

    print 'number of exceptions ', numb_exceptions
开发者ID:gvenkataraman,项目名称:experiments,代码行数:45,代码来源:mpx_pyes_index.py

示例2: ES

# 需要导入模块: from pyes import ES [as 别名]
# 或者: from pyes.ES import exists_index [as 别名]
from __future__ import unicode_literals

from pyes import ES


if __name__ == "__main__":
    conn = ES(["localhost:9200"])
    indices = ("content_index", "title_index")
    for index in indices:
        if not conn.exists_index(index):
            conn.create_index(index)
开发者ID:gvenkataraman,项目名称:experiments,代码行数:13,代码来源:create_indices.py


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