Document Refresh
-
The Refresh feature increments a document's change vector, triggering its re-indexation as well as other features that react to document updates.
-
Refresh is scheduled using the
@refresh
flag in a document's metadata. -
In this page:
Overview
To refresh a document, add a @refresh
flag to the document's metadata specifying datetime in UTC format.
This indicates when the document should be refreshed.
This will cause the document to refresh only once! The refresh operation removes
the @refresh
flag.
The exact time that the document refreshes is not determined by the value of @refresh
- rather, the server refreshes documents at regular intervals determined by the Refresh
Configuration. The default interval is 60 seconds.
Refreshing a document causes its change vector to increment the same way it would after any other kind of update to the document. This triggers any features that react to documents updating, including but not limited to:
- The document is re-indexed by any indexes that cover it.
- Replication, Subscriptions, and ETL are triggered.
- A revision of the document is created.
Examples
Setting the refresh configuration for a database:
To activate and/or configure document refreshing, the server needs to be sent a configuration object using the ConfigureRefreshOperation
operation.
// Enable document refreshing and set the refresh interval to 5 minutes:
// =====================================================================
// Define the refresh configuration object
const refreshConfiguration = {
disabled: false, // Enable refreshing
refreshFrequencyInSec: 300 // Set interval to 5 minutes
};
// Define the configure refresh operation, pass the configuration to set
const configureRefreshOp = new ConfigureRefreshOperation(refreshConfiguration);
// Execute the operation by passing it to maintenance.send
await documentStore.maintenance.send(configureRefreshOp);
Set a document to refresh 1 hour from now:
// Setting a document to refresh after 1 hour:
// ==========================================+
// Load a document
const session = documentStore.openSession();
const employee = await session.load("employees/1-A");
// Get the metadata of the document
const metadata = session.advanced.getMetadataFor(employee);
// Set the "@refresh" metadata property with the refresh date in UTC format
const refreshAt = new Date(new Date().getTime() + (60_000 * 60))
metadata[CONSTANTS.Documents.Metadata.REFRESH] = refreshAt.toISOString();
// Save the document
await session.saveChanges();
Syntax
const configureRefreshOp = new ConfigureRefreshOperation(refreshConfiguration);
// The refreshConfiguration object
{
disabled,
refreshFrequencyInSec
}
Parameter | Type | Description |
---|---|---|
disabled | boolean |
true - document refreshing is disabled for the entire database (Default).false - document refreshing is enabled. |
refreshFrequencyInSec | number |
Set how often the server checks for documents that need to be refreshed. Default: 60 |
Configure from Studio
Alternatively, document refreshing can also be configured in the studio, under Settings > Document Refresh.
Document Refresh Settings