繁体   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