How to set DataChangePolicy Azure search sdk 3.0.3

70 views Asked by At

I have enabled change policy my db

ALTER Database EMR
SET CHANGE_TRACKING = ON  
(CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON)  

ALTER TABLE EMR.dbo.ICDCodePCS  
ENABLE CHANGE_TRACKING  
WITH (TRACK_COLUMNS_UPDATED = OFF)  

and on azure index side i use below for Datasource.AzureSql

 DataChangePolicy = new SqlIntegratedChangeTrackingPolicy()

when i insert a new row to this table it does not seem to update the index automatically in azure search side. i have to pretty much run the index job after i add new row. how do i trace or debug what am i doing wrong?

i am using azure sql and azure search with sdk 3.0.3

var dataIndexer = new AzureDataIndexer()
            {
                DataSource = $"{EMRConsts.EMRAzureIndexNameICD10PCS}-datasource",
                Description = "ICD10 Procedueral Code",
                IndexName = EMRConsts.EMRAzureIndexNameICD10PCS,
                Indexer = $"{EMRConsts.EMRAzureIndexNameICD10PCS}-indexer",
                TableName = EMRConsts.EMRAzureIndexNameICD10PCS,
                DataChangePolicy = new SqlIntegratedChangeTrackingPolicy(),
                Settings = new AzureDataIndexerSettings()
                {
                    ServiceName = _settingManager.GetSettingValue(EMRSettingNames.EmrSearchServiceName),
                    ApiKey = _settingManager.GetSettingValue(EMRSettingNames.EmrSearchServiceApiKeyAdmin)
                },
                Definition = new Index()
                {
                    Name = EMRConsts.EMRAzureIndexNameICD10PCS,
                    Fields = new[]
                    {
                        new Field("ICDCodePCSId", DataType.String)
                        {
                            IsKey = true,
                            IsSearchable = true,
                            IsFilterable = true,
                            IsSortable = true,
                            IsFacetable = false,
                            IsRetrievable = true
                        },
                        new Field("ICDCodePCSName", DataType.String)
                        {
                            IsKey = false,
                            IsSearchable = true,
                            IsFilterable = true,
                            IsSortable = false,
                            IsFacetable = false,
                            IsRetrievable = true
                        },
                        new Field("ICDCodePCSShortName", DataType.String)
                        {
                            IsKey = false,
                            IsSearchable = true,
                            IsFilterable = true,
                            IsSortable = false,
                            IsFacetable = false,
                            IsRetrievable = true
                        }
                    },
                    Suggesters = new[]
                    {
                        new Suggester()
                        {
                            Name = SuggesterName,
                            SearchMode = SuggesterSearchMode.AnalyzingInfixMatching,
                            SourceFields = new List<string>() {"ICDCodePCSName", "ICDCodePCSId", "ICDCodePCSShortName" }
                        },
                    }

DataSource

    var dataSource =
        DataSource.AzureSql(
            name: dataIndexer.DataSource,
            sqlConnectionString: _appConfigSqlConnection.GetConnection().ConnectionString,
            tableOrViewName: dataIndexer.TableName,
           changeDetectionPolicy: dataIndexer.DataChangePolicy,
            description: dataIndexer.Description);

    try
    {
            _searchClient.Indexes.Create(dataIndexer.Definition);
   var indexer =
            new Indexer()
            {
                Name = dataIndexer.Indexer,
                Description = dataIndexer.Description,
                DataSourceName = dataSource.Name,
                TargetIndexName = dataIndexer.IndexName
            };

            _searchClient.Indexers.Create(indexer);
        _searchClient.DataSources.Create(dataSource);
    }
0

There are 0 answers