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

Sathish Nadarajan
 
Solution Architect
February 22, 2019
 
Rate this article
 
Views
1447

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)
         {
             CreateIndex();
 
             
         }
 
         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.

Category : Azure, Search

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment