Search code examples
c#azureazure-cognitive-searchazure-search-.net-sdk

Azure Search SDK: how to specify data source


We're getting tired of creating our Azure Search index manually during development, so I'm writing a console app to do it for us. We already have a data source in Azure which is a database view. That view will feed the index. My question is how do I specify that data source when I create the index? Here's my code so far (not including the Employee class definition):

using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;

namespace AdvancedSearchIndexGenerator
{
    class Program
    {
        static void Main()
        {
            SearchServiceClient client = new SearchServiceClient(Util.AzureSearchServiceName, new SearchCredentials(Util.AzureSearchApiKey));

            var definition = new Index()
            {
                Name = Util.AzureSearchIndexName,
                Fields = FieldBuilder.BuildForType<Employee>()
            };

            client.Indexes.Create(definition);
        }
    }
}

Solution

  • You don't specify the data source when you create the index. You can specify the data source when you create an indexer that will extract data from the data source and push it into the index.

    You will notice that you can pass the dataSourceName as an argument to the Indexer creation.

    Thanks,

    Luis Cabrera | Azure Search