如何在 Azure 搜索的主记录下索引多个 blob?
How to index multiple blobs under a main record in Azure Search?
我按照 this tutorial 中描述的步骤操作。我的情况有点不同:
- 我索引的不是酒店和房间,而是候选人和简历。
- 我没有使用 CosmosDB,而是使用了 Azure SQL 数据库。
按照教程,我能够创建索引、2 个索引器(一个用于 SQL 数据库,一个用于 Blob 存储)和 2 个数据源。
SQL 数据库包含我所有的候选人,并且存储包含他们所有的简历(PDF/DOC/DOCX 格式的文件)。每个 blob 都有一个元数据 "ResumeCandidateId",其中包含与候选 "CandidateId" 相同的值。
我的索引有以下字段:
[SerializePropertyNamesAsCamelCase]
public partial class Candidate
{
[Key]
[IsFilterable, IsRetrievable(true), IsSearchable]
public string CandidateId { get; set; }
[IsFilterable, IsRetrievable(true), IsSearchable, IsSortable]
public string LastName { get; set; }
[IsFilterable, IsRetrievable(true), IsSearchable, IsSortable]
public string FirstName { get; set; }
[IsFilterable, IsRetrievable(true), IsSearchable, IsSortable]
public string Notes { get; set; }
public ResumeBlob[] ResumeBlobs { get; set; }
}
[SerializePropertyNamesAsCamelCase]
public class ResumeBlob
{
[IsRetrievable(true), IsSearchable]
[Analyzer(AnalyzerName.AsString.StandardLucene)]
public string content { get; set; }
[IsRetrievable(true)]
public string metadata_storage_content_type { get; set; }
public long metadata_storage_size { get; set; }
public DateTime metadata_storage_last_modified { get; set; }
public string metadata_storage_name { get; set; }
[Key]
[IsRetrievable(true)]
public string metadata_storage_path { get; set; }
[IsRetrievable(true)]
public string metadata_content_type { get; set; }
public string metadata_author { get; set; }
public DateTime metadata_creation_date { get; set; }
public DateTime metadata_last_modified { get; set; }
public string ResumeCandidateId { get; set; }
}
如您所见,一个候选人可以有多个简历。挑战在于填充 ResumeBlob 属性...
来自 SQL 数据库的数据已被索引器正确索引和映射。当我 运行 Blob Indexer 时,它会加载文档,但不会映射它们并且它们永远不会出现在搜索中(ResumeBlobs 始终为空)。下面是用于创建 Blob 索引器的代码:
var blobDataSource = DataSource.AzureBlobStorage(
name: "azure-blob-test02",
storageConnectionString: "DefaultEndpointsProtocol=https;AccountName=yyy;AccountKey=xxx;EndpointSuffix=core.windows.net",
containerName: "2019");
await searchService.DataSources.CreateOrUpdateAsync(blobDataSource);
List<FieldMapping> map = new List<FieldMapping> {
new FieldMapping("ResumeCandidateId", "CandidateId")
};
Indexer blobIndexer = new Indexer(
name: "hotel-rooms-blobs-indexer",
dataSourceName: blobDataSource.Name,
targetIndexName: indexName,
fieldMappings: map,
//parameters: new IndexingParameters().SetBlobExtractionMode(BlobExtractionMode.ContentAndMetadata).IndexFileNameExtensions(".DOC", ".DOCX", ".PDF", ".HTML", ".HTM"),
schedule: new IndexingSchedule(TimeSpan.FromDays(1)));
bool exists = await searchService.Indexers.ExistsAsync(blobIndexer.Name);
if (exists)
{
await searchService.Indexers.ResetAsync(blobIndexer.Name);
}
await searchService.Indexers.CreateOrUpdateAsync(blobIndexer);
try
{
await searchService.Indexers.RunAsync(blobIndexer.Name);
}
catch (CloudException e) when (e.Response.StatusCode == (HttpStatusCode)429)
{
Console.WriteLine("Failed to run indexer: {0}", e.Response.Content);
}
我注释了 blobIndexer 的参数,但即使没有注释,我也得到了相同的结果。
当我 运行 搜索时,这是我得到的示例:
{
"@odata.context": "https://yyy.search.windows.net/indexes('index-test01')/$metadata#docs(*)",
"value": [
{
"@search.score": 1.2127206,
"candidateId": "363933d1-7e81-4ed2-b82e-d7496d98db50",
"lastName": "LAMLAST",
"firstName": "ZFIRST",
"notes": "MGA ; SQL ; T-SQL",
"resumeBlobs": []
}
]
}
"resumeBlobs" 为空。知道如何做这样的映射吗?
据我所知,Azure 搜索不支持 集合合并 功能,这似乎是实现您的方案所必需的。
另一种方法是为简历创建一个单独的索引,并将简历索引器指向该索引。这意味着您的某些搜索场景将不得不命中两个索引,但这是一条前进的道路。
我按照 this tutorial 中描述的步骤操作。我的情况有点不同:
- 我索引的不是酒店和房间,而是候选人和简历。
- 我没有使用 CosmosDB,而是使用了 Azure SQL 数据库。
按照教程,我能够创建索引、2 个索引器(一个用于 SQL 数据库,一个用于 Blob 存储)和 2 个数据源。
SQL 数据库包含我所有的候选人,并且存储包含他们所有的简历(PDF/DOC/DOCX 格式的文件)。每个 blob 都有一个元数据 "ResumeCandidateId",其中包含与候选 "CandidateId" 相同的值。
我的索引有以下字段:
[SerializePropertyNamesAsCamelCase]
public partial class Candidate
{
[Key]
[IsFilterable, IsRetrievable(true), IsSearchable]
public string CandidateId { get; set; }
[IsFilterable, IsRetrievable(true), IsSearchable, IsSortable]
public string LastName { get; set; }
[IsFilterable, IsRetrievable(true), IsSearchable, IsSortable]
public string FirstName { get; set; }
[IsFilterable, IsRetrievable(true), IsSearchable, IsSortable]
public string Notes { get; set; }
public ResumeBlob[] ResumeBlobs { get; set; }
}
[SerializePropertyNamesAsCamelCase]
public class ResumeBlob
{
[IsRetrievable(true), IsSearchable]
[Analyzer(AnalyzerName.AsString.StandardLucene)]
public string content { get; set; }
[IsRetrievable(true)]
public string metadata_storage_content_type { get; set; }
public long metadata_storage_size { get; set; }
public DateTime metadata_storage_last_modified { get; set; }
public string metadata_storage_name { get; set; }
[Key]
[IsRetrievable(true)]
public string metadata_storage_path { get; set; }
[IsRetrievable(true)]
public string metadata_content_type { get; set; }
public string metadata_author { get; set; }
public DateTime metadata_creation_date { get; set; }
public DateTime metadata_last_modified { get; set; }
public string ResumeCandidateId { get; set; }
}
如您所见,一个候选人可以有多个简历。挑战在于填充 ResumeBlob 属性...
来自 SQL 数据库的数据已被索引器正确索引和映射。当我 运行 Blob Indexer 时,它会加载文档,但不会映射它们并且它们永远不会出现在搜索中(ResumeBlobs 始终为空)。下面是用于创建 Blob 索引器的代码:
var blobDataSource = DataSource.AzureBlobStorage(
name: "azure-blob-test02",
storageConnectionString: "DefaultEndpointsProtocol=https;AccountName=yyy;AccountKey=xxx;EndpointSuffix=core.windows.net",
containerName: "2019");
await searchService.DataSources.CreateOrUpdateAsync(blobDataSource);
List<FieldMapping> map = new List<FieldMapping> {
new FieldMapping("ResumeCandidateId", "CandidateId")
};
Indexer blobIndexer = new Indexer(
name: "hotel-rooms-blobs-indexer",
dataSourceName: blobDataSource.Name,
targetIndexName: indexName,
fieldMappings: map,
//parameters: new IndexingParameters().SetBlobExtractionMode(BlobExtractionMode.ContentAndMetadata).IndexFileNameExtensions(".DOC", ".DOCX", ".PDF", ".HTML", ".HTM"),
schedule: new IndexingSchedule(TimeSpan.FromDays(1)));
bool exists = await searchService.Indexers.ExistsAsync(blobIndexer.Name);
if (exists)
{
await searchService.Indexers.ResetAsync(blobIndexer.Name);
}
await searchService.Indexers.CreateOrUpdateAsync(blobIndexer);
try
{
await searchService.Indexers.RunAsync(blobIndexer.Name);
}
catch (CloudException e) when (e.Response.StatusCode == (HttpStatusCode)429)
{
Console.WriteLine("Failed to run indexer: {0}", e.Response.Content);
}
我注释了 blobIndexer 的参数,但即使没有注释,我也得到了相同的结果。
当我 运行 搜索时,这是我得到的示例:
{
"@odata.context": "https://yyy.search.windows.net/indexes('index-test01')/$metadata#docs(*)",
"value": [
{
"@search.score": 1.2127206,
"candidateId": "363933d1-7e81-4ed2-b82e-d7496d98db50",
"lastName": "LAMLAST",
"firstName": "ZFIRST",
"notes": "MGA ; SQL ; T-SQL",
"resumeBlobs": []
}
]
}
"resumeBlobs" 为空。知道如何做这样的映射吗?
据我所知,Azure 搜索不支持 集合合并 功能,这似乎是实现您的方案所必需的。
另一种方法是为简历创建一个单独的索引,并将简历索引器指向该索引。这意味着您的某些搜索场景将不得不命中两个索引,但这是一条前进的道路。