簡體   English   中英

如何使用.net SDK(C#)創建Azure搜索索引器以從Azure Blob存儲中提取數據

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

我閱讀了有關Indexer的文檔,並下面找到了一種方法

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);

誰能告訴我如何在方法中指定fieldMappings參數? 還是給我其他代碼示例,以使用給定的數據源和索引創建索引器?

我創建了索引和數據源,但是在Azure搜索中為創建Blob存儲數據而苦苦掙扎。 我希望使用c#.NET SDK創建索引器。

此樣本有幫助嗎? 它正在為SQL數據庫建立索引,實際上並未顯示FieldMapping的示例,但希望它將有助於顯示您需要的部分。

您可以如下創建字段映射:

//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);

我還編寫了以下函數來創建可能對修改有用的Blob索引器:

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);
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM