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.
+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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With