Skip to content

Azure-Samples/azure-search-deployment-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bicep deployment of Azure Cognitive Search

This repository contains a template that deploys Azure Cognitive Search and automatically creates an index, data source, and indexer.

The sample uses the Azure CLI and Bicep.

The template creates a billable Azure Cognitive Search. You can't use the free tier for this scenario.

Azure Cognitive Search is configured with Azure Cosmos DB NoSQL. the search resource is created with an an index, data source, and indexer. The indexer runs every 5 minutes on a schedule to synchronize the index with the Cosmos database.

How it works

The Bicep script creates the following resources:

Bicep Diagram

Prerequisites

Sample set up

  1. Install the Azure CLI or another supported tool for Bicep deployment.

  2. Clone or download this sample repository.

  3. Extract contents if the download is a zip file. Make sure the files are read-write.

  4. Sign in to your Azure account:

    az login

  5. If you have multiple Azure subscriptions, list them and get the subscription ID of the one you want to use.

    az account show
    
  6. Set it to the correct subscription ID:

     az account set --subscription <YOUR-SUBSCRIPTION-ID>
    
  7. Create a resource group to contain all of the resources. If you're deploying and comparing more than one option, create a separate resource group for each one.

    az group create --name demoResourceGroup --location westus
    

Run the sample

The deployment imports data from Cosmos DB NoSQL into a search index on a search service using an indexer.

For synchronization, this sample uses a scheduled indexer to pull data into a search index. On the search service, the indexer runs at a 5 minute interval. A 5-minute interval is considered the minimum for indexer schedules.

Cosmos DB Indexer Sync Architecture

  1. From the command line, navigate to the bicep directory in the sample.

  2. Optionally, review the bicep file (cosmosdb-indexer-sync.bicep) or parameters file (cosmosdb-indexer-sync.parameters.json). Feel free to change attributes such as the SKU (tier).

  3. Run the next CLI command to create the Cosmos DB account, database, and search resource:

    az deployment group create --resource-group <YOUR-RESOURCE-GROUP> --template-file cosmosdb-indexer-sync.bicep --mode Incremental --parameters @cosmosdb-indexer-sync.parameters.json
    

You can use the same resource group you created earlier (demoResourceGroup). It takes several minutes to deploy all of the resources. The script outputs status to the command line once everything is deployed. The following output is trimmed for brevity.

{
  "id": "/subscriptions/000000000000000000000000000000000/resourceGroups/demoResourceGroup/providers/Microsoft.Resources/deployments/cosmosdb-indexer-sync",
  "location": null,
  "name": "cosmosdb-indexer-sync",
  "properties": {
    "correlationId": "ecbecc70-c3f4-476c-b5a1-e804f3489775",
    "debugSetting": null,
    "dependencies": [
      {
        "dependsOn": [
          {
            "id": "/subscriptions/00000000000000000000000/resourceGroups/demoResourceGroup/providers/Microsoft.DocumentDB/databaseAccounts/wmada6ilf3yneaccount",
            "resourceGroup": "demoResourceGroup",
            "resourceName": "wmada6ilf3yneaccount",
            "resourceType": "Microsoft.DocumentDB/databaseAccounts"
          }
        ],
. . . 
    "provisioningState": "Succeeded",
    "templateHash": "9404979489974435321",
    "templateLink": null,
    "timestamp": "2023-06-29T17:33:03.504780+00:00",
    "validatedResources": null
  },
  "resourceGroup": "demoResourceGroup",
  "tags": null,
  "type": "Microsoft.Resources/deployments"
}

Test the deployment

The indexer is configured to use the built-in Cosmos DB ToDo sample database. To test the deployment:

  1. Navigate to the demoResourceGroup to find the Cosmos DB and search resource.

  2. In search, verify the index, indexer, data source are created and that the index has zero documents.

  3. In Cosmos DB, use Data Explorer to add a few items to the built-in sample ToDo database. The ToDo database has an "id" field and metadata. The search index on Azure Cognitive Search has two fields ("rid", "description").

    • The "rid" field in the search index is populated from the _rid metadata field that's autopopulated in Cosmos DB.

    • For "description, add a "description" in each ToDo item that you add in Cosmos DB. Note that the "id" field isn't used in this sample.

      {
         "id": "first",
         "description": "hello world"
      }
  4. Wait for five minutes, and then check the indexes in the search services. You should see the newly added content.

Sample clean up

This sample creates billable Azure resourcess. After completing this exercise, delete any resources you no longer need.

  1. Sign in to the Azure portal.

  2. To delete all of the resources, find and delete the resource group that you created.

Resources

About

Create a search service with an index using a bicep template.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published