let index be batchly. (#733)

### What problem does this PR solve?

let index be batchly.

### Type of change


- [x] Refactoring
This commit is contained in:
KevinHuSh 2024-05-11 19:47:53 +08:00 committed by GitHub
parent 04a9e95161
commit ffe5737f7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -285,7 +285,12 @@ def main():
init_kb(r)
chunk_count = len(set([c["_id"] for c in cks]))
st = timer()
es_r = ELASTICSEARCH.bulk(cks, search.index_name(r["tenant_id"]))
es_r = ""
for b in range(0, len(cks), 32):
es_r = ELASTICSEARCH.bulk(cks[b:b+32], search.index_name(r["tenant_id"]))
if b % 128 == 0:
callback(prog=0.8 + 0.1 * (b + 1) / len(cks), msg="")
cron_logger.info("Indexing elapsed({}): {}".format(r["name"], timer()-st))
if es_r:
callback(-1, "Index failure!")