Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding index creation/configuration in a Azure search ARM Template

There is ways to create a Azure Search Service via ARM template (Example: https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-azure-search-create/azuredeploy.json).

What I want to know is there a way to define a specific index within the ARM template (fields, data sources, indexers etc)?

I know that there are REST services that you can use in order to create and modify indexes but I do not want a separate script/application to handle that after my resource group and Azure Search Service is created.

like image 681
disco Avatar asked Sep 14 '25 12:09

disco


2 Answers

+1 to Don's comment. You will need to create the index either using the REST API or the .NET SDK. If you happen to be using PowerShell to create the service, you might find the following code helpful which calls the REST API using Invoke-RestMethod and a set of .JSON files that contain the schema for the index and some documents.

#------------------------#
# Setting up search index#
#------------------------#
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", 'application/json')
$headers.Add("api-key", $searchApiKey)

Write-Host 
Write-Host "Creating Index..."
$schemaFile = "$(Split-Path $MyInvocation.MyCommand.Path)\zipcodes.schema"
$response = Invoke-RestMethod -TimeoutSec 10000 $searchServiceUrl"/indexes/zipcodes2?api-version=2015-02-28-Preview" -Method Put -Headers $headers -Body "$(get-content $schemaFile)"
Write-Host $response

$jsonFile = "$(Split-Path $MyInvocation.MyCommand.Path)\zipcodes1.json"
Write-Host 
Write-Host "Adding Documents from $jsonFile..."
$response = Invoke-RestMethod -TimeoutSec 10000 $searchServiceUrl"/indexes/zipcodes2/docs/index?api-version=2015-02-28-Preview" -Method Post -Headers $headers -Body "$(get-content $jsonFile)"
Write-Host $response
like image 157
Liam Cavanagh - MSFT Avatar answered Sep 16 '25 08:09

Liam Cavanagh - MSFT


No, you cannot create an index within an ARM template. The terminology I've read before is that ARM is for managing the Azure control plane.

like image 42
Don Lockhart Avatar answered Sep 16 '25 07:09

Don Lockhart