Tejaswini Utlapalli
Tejaswini Utlapalli

Reputation: 1

How to create an Azure Search Indexer using .net SDK (c#) to pull data from Azure blob storage

I read the documentation about Indexer and found a method below

public Indexer (string name, string dataSourceName, string targetIndexName, string description = null, string skillsetName = null, Microsoft.Azure.Search.Models.IndexingSchedule schedule = null, Microsoft.Azure.Search.Models.IndexingParameters parameters = null, System.Collections.Generic.IList<Microsoft.Azure.Search.Models.FieldMapping> fieldMappings = null, System.Collections.Generic.IList<Microsoft.Azure.Search.Models.FieldMapping> outputFieldMappings = null, Nullable<bool> isDisabled = null, string eTag = null);

Can anyone tell me how I can specify fieldMappings parameter in the method? Or give me any other code example to create an Indexer with given datasource and index?

I created an Index and data source but struggling with creating an Indexer in Azure search for blob storage data. I expect an Indexer to be created using c# .NET SDK.

Upvotes: 0

Views: 892

Answers (2)

Kevin
Kevin

Reputation: 2631

You can create a field mapping as follows:

//this creates a field mapping for they key assigned to the blob in blob storage
 var keyMapping = new FieldMapping("metadata_storage_name", "key", new FieldMappingFunction { Name = "base64Encode", Parameters = null });
 var mappings = new List<FieldMapping>();
 mappings.Add(keyMapping);

I have also written the following function to create blob indexers you may find useful to modify:

private static void CreateBlobIndexer(SearchServiceClient serviceClient
            , string IndexerName
            , string Description
            , string SourceName
            , string IndexName
            , IndexingSchedule Schedule
            , List<FieldMapping> Mappings)
        {
            var indexingParams = new IndexingParameters();

            indexingParams.MaxFailedItems = Convert.ToInt32(ConfigurationManager.AppSettings["MaxFailures"]);
            indexingParams.MaxFailedItemsPerBatch = Convert.ToInt32(ConfigurationManager.AppSettings["MaxFailures"]);
            indexingParams.DoNotFailOnUnsupportedContentType();
            indexingParams.IndexFileNameExtensions(new string[] { ".pdf" });

            var definition = new Indexer()
            {
                Name = IndexerName,
                Description = Description,
                DataSourceName = SourceName,
                TargetIndexName = IndexName,
                Schedule = Schedule,
                FieldMappings = Mappings,
                Parameters = indexingParams
            };

            serviceClient.Indexers.Create(definition);
        }

Upvotes: 0

Liam Cavanagh - MSFT
Liam Cavanagh - MSFT

Reputation: 1464

Does this sample help? It is Indexing a SQL database and does not actually show an example of FieldMapping, but hopefully it will help show the parts you will need.

Upvotes: 1

Related Questions