Purge stale records from the AI Search index
Execute a scheduled job to delete stale records from the AI Search index.
Before you begin
Role required: admin
Note: If the glide.script_processor.admin system property's value has been changed from the default value, you need the role specified by that property value. For details on this property value and its effects, see Restrict access to background script.
About this task
If either of these conditions is satisfied for a record in the AI Search index, AI Search marks the record as stale.
- The time since the record's last update exceeds the age limit from its indexed source's retention policy
- The record no longer satisfies the filter conditions defined for its indexed source
AI Search automatically purges stale records from the index daily. Administrators can purge records manually by running a background script.
For more information on running background scripts, see Scripts - Background module.
Procedure
-
Navigate to All > System Definition > Scripts - Background.
Note: If the glide.script_processor.admin system property's value is set to security_admin, you must elevate to that privileged role to access this module. For more information on elevating privileges, see Elevated privilege roles.
-
In the Run script (JavaScript executed on server) text field, enter one of the following background scripts.
-
To purge stale records indexed from a specific table, enter this script, replacing
TABLE_NAMEwith the name of your chosen table:JavaScriptnew sn_ais.IndexEvent().purgeFilteredDocuments('TABLE_NAME');For example, to purge all stale records indexed from the Knowledge Table indexed source, replace
TABLE_NAMEwithkb_knowledgein the script. -
To purge all stale records in the index, regardless of which table they were indexed from, enter this script:
JavaScriptnew sn_ais.IndexEvent().purgeFilteredDocuments();
-
-
Select Run script.
The script creates an event that the index handler processes, so the script completes without blocking on completion of the purge job.
Result
The background script executes, deleting stale records from the AI Search index.
Parent Topic:Indexed source retention policies and filter conditions
---
title: Purge stale records from the AI Search index
description: Execute a scheduled job to delete stale records from the AI Search index.
locale: en-US
canonical_url: https://www.servicenow.com/docs/r/australia/platform-administration/ai-search/purge-stale-records-ais-index.html
release: australia
product: AI Search
classification: ai-search
topic_type: task
last_updated: "2026-09-10"
reading_time_minutes: 1
breadcrumb: [Indexed source retention policies and filter conditions, Indexed sources, Configure, AI Search, Search administration, Configure core features, Administer the ServiceNow AI Platform]
---
# Purge stale records from the AI Search index
Execute a scheduled job to delete stale records from the AI Search index.
## Before you begin
Role required: admin
**Note:** If the **glide.script\_processor.admin** system property's value has been changed from the default value, you need the role specified by that property value. For details on this property value and its effects, see [Restrict access to background script](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/sc-restrict-access-to-background-script.md).
## About this task
If either of these conditions is satisfied for a record in the AI Search index, AI Search marks the record as stale.
- The time since the record's last update exceeds the age limit from its indexed source's retention policy
- The record no longer satisfies the filter conditions defined for its indexed source
AI Search automatically purges stale records from the index daily. Administrators can purge records manually by running a background script.
For more information on running background scripts, see [Scripts - Background module](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/scripts/c_ScriptsBackground.md).
## Procedure
1. Navigate to **All** > **System Definition** > **Scripts - Background**.
**Note:** If the **glide.script\_processor.admin** system property's value is set to security\_admin, you must elevate to that privileged role to access this module. For more information on elevating privileges, see [Elevated privilege roles](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/c_ElevatedPrivilege.md).
2. In the **Run script \(JavaScript executed on server\)** text field, enter one of the following background scripts.
- To purge stale records indexed from a specific table, enter this script, replacing `TABLE_NAME` with the name of your chosen table:
```
new sn_ais.IndexEvent().purgeFilteredDocuments('TABLE_NAME');
```
For example, to purge all stale records indexed from the Knowledge Table indexed source, replace `TABLE_NAME` with `kb_knowledge` in the script.
- To purge all stale records in the index, regardless of which table they were indexed from, enter this script:
```
new sn_ais.IndexEvent().purgeFilteredDocuments();
```
3. Select **Run script**.
The script creates an event that the index handler processes, so the script completes without blocking on completion of the purge job.
## Result
The background script executes, deleting stale records from the AI Search index.
**Parent Topic:**[Indexed source retention policies and filter conditions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-administration/ai-search/retention-policies-conditions-ais.md)
| title | Purge stale records from the AI Search index |
| description | Execute a scheduled job to delete stale records from the AI Search index. |
| locale | en-US |
| canonical_url | https://www.servicenow.com/docs/r/australia/platform-administration/ai-search/purge-stale-records-ais-index.html |
| release | australia |
| product | AI Search |
| classification | ai-search |
| topic_type | task |
| last_updated | 2026-09-10 |
| reading_time_minutes | 1 |
| breadcrumb | Indexed source retention policies and filter conditionsIndexed sourcesConfigureAI SearchSearch administrationConfigure core featuresAdminister the ServiceNow AI Platform |