def update(self, index, iterable, commit=True):
if not self.setup_complete:
try:
self.setup()
except TransportError as e:
if not self.silently_fail:
raise
self.log.error(u"Failed to add documents to Elasticsearch: %s", e, exc_info=True)
return
prepped_docs = []
for obj in iterable:
try:
prepped_data = index.full_prepare(obj)
# removing 'id' item from data
# Convert the data to make sure it's happy.
final_data = {
ELASTICSEARCH_ID if key == ID else key: self._from_python(value)
for key, value in prepped_data.items()
}
# end removing 'id' item from data
prepped_docs.append(final_data)
except SkipDocument:
self.log.debug(u"Indexing for object `%s` skipped", obj)
except TransportError as e:
if not self.silently_fail:
raise
# We'll log the object identifier but won't include the actual object
# to avoid the possibility of that generating encoding errors while
# processing the log message:
self.log.error(u"%s while preparing object for update" % e.__class__.__name__, exc_info=True,
extra={"data": {"index": index,
"object": get_identifier(obj)}})
bulk(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
if commit:
self.conn.indices.refresh(index=self.index_name)
评论列表
文章目录