Azure Search Service – Create an Azure Search Index programmatically – C# Programmatically

Sathish Nadarajan
SharePoint MVP
Published On :   22 Feb 2019
Visit Count
Today :  10    Total :   334

In the earlier article, we saw how to create a Data Source Programmatically. Now, as a continuation, let us see how to create an Index.

The code to create an index is straight forward.

 namespace CS.Help.Console
     using Microsoft.Azure.Search;
     using Microsoft.Azure.Search.Models;
     using Microsoft.WindowsAzure.Storage;
     using Microsoft.WindowsAzure.Storage.Blob;
     using System.Linq;
     class Program
         static void Main(string[] args)
         private static void CreateIndex()
             string searchServiceName = "Search Service Name";
             string searchQueryApiKey = "API Key";
             SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(searchQueryApiKey));
             string indexName = "myindex";
             var definition = new Index()
                 Name = indexName,
                 Fields = FieldBuilder.BuildForType<BlobDocuments>()
             Index index = serviceClient.Indexes.CreateOrUpdate(definition);

Happy Coding,

Sathish Nadarajan.