INNER CODE UNIT · Python
add_objects
defiprime/defiprime1 · scripts/algolia-index.py:169
def add_objects(self, index, batches, report=print):
for position, batch in enumerate(batches, 1):
response = self.post(f"/1/indexes/{index}/batch", batch_body(batch))
self.wait(index, response["taskID"])
report(f"batch {position}/{len(batches)}: {len(batch)} records")
def push(client, index, records, temp_index, report=print):
report(f"copying settings, synonyms and rules from {index} to {temp_index}")
client.operation(index, "copy", temp_index, scope=COPY_SCOPE)
batches = batch_records(records, MAX_BATCH_BYTES, MAX_BATCH_RECORDS)
report(f"uploading {len(records)} records in {len(batches)} batches")
client.add_objects(temp_index, batches, report=report)
report(f"moving {temp_index} onto {index}")
client.operation(temp_index, "move", index)
report(f"done: {index} now holds {len(records)} records")