本文整理汇总了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
示例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)