> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Price and inventory delta indexing

> Send only changed prices and inventory data to Algolia with scheduled B2C delta exports.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

The `AlgoliaProductPriceDeltaIndex_v2` and `AlgoliaProductInventoryDeltaIndex_v2` jobs update your Algolia product <Records /> when prices or inventory data change.
They only process the products whose price books or inventory lists changed since the last run,
and they work with all [record models](/doc/integration/salesforce-commerce-cloud-b2c/indexing/product-indexing/indexing-attributes#record-models).

## How the delta jobs work

Each Algolia delta job reads the output of a B2C delta export.
The two processes run on separate schedules and communicate through a folder in WebDAV:

1. **The producer:** A B2C **delta export** collects the price book or inventory list changes made since its last run and writes them as numbered archives (`000001.zip`, `000002.zip`, and so on) to `Impex/src/platform/outbox/CONSUMER/DELTA_EXPORT_NAME/`.
2. **The consumer:** The **Algolia job** reads the archives from that folder, extracts the IDs of the changed products, rebuilds each product's record from your site's current data, and sends the records to Algolia.

B2C Commerce tracks the changes in its Change Log, regardless of their origin:
Business Manager edits, feed imports, and API writes are all included.

Price book and inventory list delta exports have no job step, unlike catalog delta exports, so the Algolia jobs can't trigger them.
Each delta export runs on its own schedule, which you define when you create it.

The job doesn't copy the prices and quantities from the archives into the records.
It uses them only to determine which products changed.
Each record is rebuilt from the product's current data,
so the result is the same as a [full reindex](/doc/integration/salesforce-commerce-cloud-b2c/indexing/product-indexing/full-indexing) of the changed products.

* The job sends each changed product as a full record that replaces the existing record with the same `objectID`, or creates it if it doesn't exist.
* If a changed product no longer qualifies for the index, the job deletes its record.
  For example, when [**Index out of stock products**](/doc/integration/salesforce-commerce-cloud-b2c/getting-started/custom-preferences) is off, the job removes a product that sells out from the index, and re-adds it as a full record once it's back in stock.
* The job matches the changed product IDs to your record model.
  With the **Base product** and **Attribute-sliced** record models, a changed variant updates its base product's record.
  With the **Variation product** record model, a changed base product updates the records of the variants that inherit from it.

In a [multi-instance setup](/doc/integration/salesforce-commerce-cloud-b2c/guides/multi-instance-indexing), the full records sent by these jobs would overwrite the attributes indexed from the other instance.
In that case, use `AlgoliaProductPriceIndex_v2` and `AlgoliaProductInventoryIndex_v2` on the production instance instead.

### Consumed archives

Each job records the archives it has processed in `AlgoliaConsumedDeltaArchive` custom objects and leaves the archives in place.
B2C Commerce deletes files under `Impex` after 30 days, and the custom objects expire after 33 days, so neither requires cleanup.

Each job tracks consumption separately for each site.
Several sites, or several jobs on the same site, can consume the same delta export independently,
which supports price books and inventory lists shared between sites.

<Note>
  If you delete a delta export and recreate it under the same name, its archive numbering restarts at `000001.zip`,
  and the consumption records from the old delta export prevent the jobs from processing the new archives with the same names.
  Use a different name, or delete the site's `AlgoliaConsumedDeltaArchive` custom objects first.
</Note>

## Before you begin

* Create a support ticket with Salesforce to activate the **Delta Export** and **Change Log** features on your instances.
  For details, see [Enable delta export](/doc/integration/salesforce-commerce-cloud-b2c/indexing/product-indexing/ongoing-indexing#enable-delta-export).
* Upgrade your Algolia cartridge to [version 26.5.0](https://github.com/algolia/algoliasearch-sfcc-b2c/releases/tag/26.5.0) or later.
* Run the `AlgoliaProductIndex_v2` job at least once to populate your indices.
  The delta exports only contain changes made after you create them,
  so the delta jobs maintain existing records but can't build the initial index.

## Create the delta exports

<Steps>
  <Step title="Open the Delta Exports page">
    In Business Manager, go to **Administration > Site Development > Delta Exports**.
  </Step>

  <Step title="Create the price book delta export">
    Create a delta export with the following settings:

    * **Name**: `pricebookDeltaExport`
    * **Consumers**: `algolia`
    * Select the price books used by the sites you index.

    Enable the delta export's schedule and set its interval.
    For guidance, see [Recommended schedules](#recommended-schedules).
  </Step>

  <Step title="Create the inventory list delta export">
    Create a second delta export with the following settings:

    * **Name**: `inventoryDeltaExport`
    * **Consumers**: `algolia`
    * Select the inventory lists used by the sites you index.

    Enable this delta export's schedule as well, with its own interval.
  </Step>
</Steps>

<Note>
  The name and consumer of each delta export must exactly match the `deltaExportJobName` and `consumer` parameters of the corresponding Algolia job.
  A mismatch doesn't cause an error:
  the job finds no archives and processes nothing.
</Note>

## Configure the Algolia jobs

Importing the cartridge's [job definitions](/doc/integration/salesforce-commerce-cloud-b2c/getting-started/set-up-the-algolia-cartridge) creates both jobs.

<Steps>
  <Step title="Set the scope">
    In Business Manager, go to **Administration > Operations > Jobs** and open `AlgoliaProductPriceDeltaIndex_v2`.

    On the **Job Steps** tab, change the scope to **Specific Sites** and select the sites you want to index.
  </Step>

  <Step title="Check the job parameters">
    The job's parameters must match the delta export you created:

    * **consumer** (default: `algolia`): the delta export's consumer.
    * **deltaExportJobName** (default: `pricebookDeltaExport`): the delta export's name.

    The job step also accepts the `failureThresholdPercentage` and `localesForIndexing` parameters.
    For details, see the [step parameters](/doc/integration/salesforce-commerce-cloud-b2c/indexing/product-indexing/ongoing-indexing#algoliaproductdeltaindex-job-step-parameters).
  </Step>

  <Step title="Schedule the job">
    On the **Schedule and History** tab, enable the job and set its interval.
    Start it 5 to 10 minutes after the delta export runs,
    so each run picks up the export's output without waiting for the next cycle.
  </Step>

  <Step title="Repeat for the inventory job">
    Configure `AlgoliaProductInventoryDeltaIndex_v2` the same way.
    Its **deltaExportJobName** parameter defaults to `inventoryDeltaExport`.
  </Step>
</Steps>

## Verify the setup

A mismatch between the delta export and the job parameters doesn't produce an error,
so verify each pair end to end:

1. Change a price in one of the exported price books.
2. After the delta export's next run, check over WebDAV that a numbered archive, such as `000001.zip`, appears in `Impex/src/platform/outbox/algolia/pricebookDeltaExport/`.
3. After the Algolia job's next run, check in the job history that the run processed products, and confirm in the Algolia dashboard that the product's record shows the price change.
4. Repeat with an inventory change to verify the inventory pair.

## Recommended schedules

Each delta export and job pair has its own schedule.
Match it to how often the data changes:

* **Inventory**: schedule the delta export and the job frequently, for example every 15 to 30 minutes, to keep availability accurate between full reindexes.
* **Prices**: price changes often come in batches, from price feed imports or price book activations. Use a longer interval, for example every 2 to 4 hours, or schedule the pair right after your price imports.

Keep the following in mind:

* The Change Log retains changes for seven days.
  If you pause the delta export or the job for longer than that, the missed changes are only sent to Algolia with the next full reindex.
* Keep your periodic `AlgoliaProductIndex_v2` full reindex scheduled.
  It corrects any changes the delta jobs miss.
