Search code examples
c#azureazure-cognitive-search

Azure Search SDK Create DataSource


I've been created a datasource by Azure Search SDK.

The Datasource from Azure sql which is a View.

I tyr to setting the DataChangeDetectionPolicy and DataDeletionDetectionPolicy, but i can't understand how to set this two property.

When i think this two property doesn't supported on the preview sdk,so i try to use REST API to solve this.

I read the article: MSDN Create Data Source (Azure Search Service REST API)

And use Chrome Extension Postman to set the Data Change Detection Policies.

Url : https://domain.search.windows.net/datasources/temp1?api-version=2015-02-28

body :

{ 
    "@odata.type" : "#Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy",
    "highWaterMarkColumnName" : "ModifiedDatetime" 
} 

then i get the 400 bad request .

error message:

 {
   "error": 
  {
   "code": "",
   "message": "The request is invalid. Details: dataSource : Incompatible type kinds were found. The type 'Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy' was found to be of kind 'Complex' instead of the expected kind 'Entity'.\r\n"
  }
 }

So,i have two questions.

1.Is the SDK are not support this function Now?

2.with the REST API , how to solve the error?

Thanks for reply.


Solution

  • Based on the official article, the way to create the datasource for SQL integration for Views is:

    { 
        "name" : "myazuresqldatasource",
        "type" : "azuresql",
        "credentials" : { "connectionString" : "connection string" },
        "container" : { "name" : "table or view name" }, 
        "dataChangeDetectionPolicy" : {
           "@odata.type" : "#Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy",
           "highWaterMarkColumnName" : "[a row version or last_updated column name]" 
      }
    }