本文整理汇总了Python中pyes.ES.flush_bulk方法的典型用法代码示例。如果您正苦于以下问题:Python ES.flush_bulk方法的具体用法?Python ES.flush_bulk怎么用?Python ES.flush_bulk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyes.ES
的用法示例。
在下文中一共展示了ES.flush_bulk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ElasticSearchSink
# 需要导入模块: from pyes import ES [as 别名]
# 或者: from pyes.ES import flush_bulk [as 别名]
class ElasticSearchSink(object):
def __init__(self, server, index, type):
from pyes import ES
self.cxn = ES(server)
self.index = index
self.type = type
def __call__(self, event):
if isinstance(event, list):
self.cxn.bulk_size = len(event)
for e in event:
self.cxn.index(e, self.index, self.type, bulk=True)
self.cxn.flush_bulk()
else:
self.cxn.index(event, self.index, self.type)
示例2: Importer
# 需要导入模块: from pyes import ES [as 别名]
# 或者: from pyes.ES import flush_bulk [as 别名]
class Importer(object):
base_filename = "TicketNetworkDataFeed"
model_map = {
"performers": {
"file": "Performers.csv",
"model": Performer,
},
"events": {
"file": "Events.csv",
"model": Event,
},
"venues": {
"file": "Venues.csv",
"model": Venue,
}
}
def __init__(self, data_type, csv_path="/tmp/", es_hosts=("http://localhost:9200",)):
self.data_type = data_type
self.doc_type = "ticketnetwork_%s" % self.data_type
self.csv_path = csv_path
self.es = ES(es_hosts)
def model(self):
return self.model_map[self.data_type]["model"]
def filepath(self):
return os.path.join(self.csv_path,
'-'.join([self.base_filename, self.model_map[self.data_type]["file"]]))
def __call__(self, *args, **kwargs):
with open(self.filepath()) as f:
reader = DictReader(f)
for entry in reader:
sanitize(entry)
model = self.model()(entry)
d = model.dict()
self.es.index(d, "oedi_sources", self.doc_type, model.hash(), bulk=True)
self.es.flush_bulk(True)