Re-index after a configuration change
After you add fields to an entity type, change a search type, or import a configuration bundle, the search index no longer matches the data. The SAND specification's re-index recipe has three steps: create a new, not-yet-searchable index generation for every type, load it with a full index job, then promote the new generation, which also deletes the older ones.
import sasvi
client = sasvi.SVIClient.from_env()
indexing = client.admin.indexing
# 1. A fresh generation per type. Searches keep using the current one.
indices = indexing.ensure_indices(searchable=False)
print(f"{len(indices)} index generations created")
# 2. Load everything into the new generation.
job = indexing.start_full(name="Re-index after config change")
print(job.id, job.status) # e.g. 'a1b2...' 'pending'
# 3. Once the job has finished (VI admin > Jobs), switch searches over and
# drop the previous generations.
result = indexing.make_searchable()
print(result.to_dict())
Run step 3 only after the job reports completion. The SDK cannot poll the job. The
datahub spec publishes POST /admin/asyncJobs but no status or cancel endpoint, so
IndexingJob has no refresh(). Watch the Jobs page in the VI admin UI, or check
that indexing.refresh_configuration(status_only=True) reports
reindex_required=False.
Index only what changed
A full re-index of a large tenant takes a while. When you know which types were affected, scope the job instead:
from datetime import datetime, timedelta, timezone
# Everything that changed in the last hour, for two entities and one link.
job = indexing.start_incremental(
since=datetime.now(timezone.utc) - timedelta(hours=1),
entities=["person", "case"],
relationships=[("person_case", "person")], # (relationship, from entity)
)
# Or one type end to end, without the objects associated with it.
job = indexing.start_for(entities=["person"], index_associated_objects=False)
since must carry a UTC offset. A naive datetime is rejected before anything is
sent, because the server would read it in its own zone and shift the window.
Dry-run the job body
IndexingRequest builds the payload without a client, so you can review or snapshot
it first:
request = sasvi.IndexingRequest.scoped(entities=["person"], index_associated_objects=False)
print(request.to_payload())
# {'version': 1, 'name': 'Data indexing',
# 'parameters': {'type': 'SEARCH_INDEX_LOADER', 'indexAssociatedObjects': False},
# 'tasks': [{'version': 1, 'name': 'LOAD_DOCUMENT:person',
# 'parameters': {'type': 'LOAD_DOCUMENT', 'name': 'person'}}]}
job = indexing.start(request=request)
Go further
- Use configuration APIs. The full
client.admin.indexingsurface, includingindex_nameandformat_version. - Bulk operations. The generic
submit_async_jobescape hatch for other job types.