Loading...

Records are not getting updated/deleted in Search Index despite enabling Track Deletions in SQL DB

Records are not getting updated/deleted in Search Index despite enabling Track Deletions in SQL DB

Symptom:

The count of records in the indexer and the index did not align even after activating the change detection policy. Even with record deletions, the entries persisted in the Index Search Explorer.

 

To enable incremental indexing, configure the "dataChangeDetectionPolicy" property within your data source definition. This setting informs the indexer about the specific change tracking mechanism employed by your table or view.

 

For Azure SQL indexers, you can choose the change detection policy below:

"SqlIntegratedChangeTrackingPolicy" (applicable to tables exclusively)

It is recommended using "SqlIntegratedChangeTrackingPolicy" for its efficiency and its ability to identify deleted rows.

Database requirements:

Prerequisites:-

  1. SQL Server 2012 SP3 and later, if you're using SQL Server on Azure VMs
  2. Azure SQL Database or SQL Managed Instance
  3. Tables only (no views)
  4. On the database, enable change tracking for the table.
  5. No composite primary key (a primary key containing more than one column) on the table.
  6. No clustered indexes on the table. As a workaround, any clustered index would have to be dropped and re-created as NonClustered index, however, performance may be affected in the source compared to having a clustered index.
  7. When using SQL integrated change tracking policy, don't specify a separate data deletion detection policy. The SQL integrated change tracking policy has built-in support for identifying deleted rows.
  8. However, for the deleted rows to be detected automatically, the document key in your search index must be the same as the primary key in the SQL table.

 

Once you have done all the above steps, still you see the discrepancy in the count of Indexer and Index Count

 

Approach:

 

Enabling change tracking before or after inserting data can affect how the system tracks changes, and the order in which you enable it matters. It's important to understand how change tracking works in your specific context to resolve the issue. 

 

  • Check whether you have enabled Change tracking at the Table level as well along with Database level.
  • Check whether you have enabled Change Tracking before or after Data Insertion.

 

                            ALTER TABLE [TableName] ENABLE CHANGE_TRACKING

 

Here are some general guidelines on how change tracking typically works:

  1.  Enable Change Tracking Before Inserting Data:   - If you enable change tracking before inserting data, the system will start tracking changes from the beginning.   - This is the recommended approach if you want to track changes to existing data and any new data that will be added.
  2. Enable Change Tracking After Inserting Data:   - If you enable change tracking after inserting data, the system might not have a baseline for the existing data.   - You may encounter errors if you attempt to retrieve change information for data that was already in the system before change tracking was enabled.

Solution :

  1. To ensure that the Indexer starts tracking deletions from the beginning, it is important to enable Change Tracking before inserting data.
  2. This approach also helps to match the count of the Indexer and Index without having to reset the Indexer repeatedly.

Reference Links :–

Enable and Disable Change Tracking - SQL Server | Microsoft Learn

Azure SQL indexer - Azure AI Search | Microsoft Learn

 

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Azure Storage - TLS 1.0 and 1.1 retirement

Overview TLS 1.0 and 1.1 retirement on Azure Storage was previously announced for Nov 1st, 2024, and it was postponed recently to 1 year later...

1 year ago

Efficient Management of Append and Page Blobs Using Azure Storage Actions

  Overview In Azure Storage, Blob Lifecycle Management (BLM) allows you to automate the management of your data based on rules defined by...

1 year ago

[Azure AI Search] Internal Server Error when creating CMK encrypted objects

Scenario Customers follow the Microsoft doc to create CMK encrypted objects (data source, index etc.), but get the 500 Internal Serv...

1 year ago

Optimizing Azure Table Storage: Automated Data Cleanup using a PowerShell script with Azure Automate

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Optimizing Azure Table Storage: Automated Data Clean-up using a PowerShell script with Azure Automat

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Restoring Soft-Deleted Blobs with multithreading in Azure Storage Using C#

Blob soft delete is an essential feature that safeguards your data against accidental deletions or overwrites. By retaining deleted data for a...

1 year ago

Performing simple Azure Table Storage REST API operations using curl command.

The blog provides guidance to perform simple Table Storage REST API operations such as Create table, Delete Table, Insert entity, Delete entit...

1 year ago

Bulk delete all the old jobs from the batch account

Deleting a Job also deletes all Tasks that are part of that Job, and all Job statistics. This also overrides the retention period for Task dat...

1 year ago

Utilizing Azure Storage and Runbooks for scheduled automated backups of Azure SQL Databases

In this article, we are going to provide detailed steps to create a scheduled Azure SQL Database backup to storage account using automation. T...

2 years ago

[Azure Service Bus] JMS messages getting dead-lettered

The article discusses a problem where numerous messages end up in the dead letter queue (DLQ) when the JMS service bus consumer connects to th...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.