This post was most recently updated on October 19th, 2022
To begin with Azure Cognitive Search, first we need to create an azure cognitive search service through portal and also keep the API Keys in hand as both the name of the search service and primary api key are required for every api calls through postman. Creating datasource is one of the primary steps where we need to establish the connection and providing relevant connection information.
- Method: PUT / POST
- URL: (PUT) https://[name of the search service].search.windows.net/datasources/[name of the data source]?api-version=[api version]
(POST) https://[name of the search service].search.windows.net/datasources?api-version=[api version] - Authorization:
Type – API Key
Value- [Value of the Primary Key]
Add to- Header
- Headers:
Content-Type- “application/json”
API-Key – [value of the api key]
(The api-key is used to authenticate the request to your Search service) - Body:
{
“name”: (optional on PUT; required on POST) “Name of the data source”,
“description”: (optional) “Anything you want, or nothing at all”,
“type”: (required) “Must be a supported data source”,
“credentials”: (required) {“connectionString”: “Connection string for your data source”},
“container”: (required) {“name”: “Name of the table, collection, or blob container you wish to index”},
“dataChangeDetectionPolicy”: (optional) {See below for details},
“dataDeletionDetectionPolicy”: (optional) {See below for details},
“encryptionKey”:(optional) {}
}
N.B.:
- The “type” of the data source is a mandatory field where we need to mention what kind of data source we need to store and fetch our data. PFB the type names:
azuresql for Azure SQL Database
cosmosdb for the Azure Cosmos DB SQL API
azureblob for Azure Blob Storage
adlsgen2 for Azure Data Lake Storage Gen2
azuretable for Azure Table Storage - The “container” specifies the data to index using the name (required) and query (optional) properties:
E.g.:
Name:
For Azure SQL, specifies the table or view. For Azure Blob Storage, specifies the storage container.
Query:
For Azure Blob Storage, allows you to specify a virtual folder within the blob container. For Azure SQL, query is not supported, we can use views instead. - The “dataDeletionDetectionPolicy” is used to identify deleted data items.
- Response: 201 Created