【发布时间】:2019-12-18 22:04:24
【问题描述】:
我目前一直在使用 Azure 搜索,我偶然发现了一个场景,其中我有两张表:一张描述一个地点,另一张为每个地点提供多张照片。
我想使用两个索引器来填充相同的索引,其中一个会填充地点的详细信息(名称、坐标等),而另一个会获取照片,运行自定义 WebApiSkill,从照片,并将它们添加到索引上的复杂集合中。
问题是,我不知道如何在索引中填充该照片集。我尝试将我的outputFieldMappings 定义为Photos/*/Details,或者只是Photos/Details,但我一直收到同样的错误:
Microsoft.Rest.Azure.CloudException: 'Output field mapping specifies target field 'Photos/*/PhotoURI' that doesn't exist in the index'
考虑到这一点,我想知道是否可以在 Azure 搜索中填充这样的复杂集合,如果可以,我将如何去做?
表格:
CREATE TABLE Places
(
Id bigint not null IDENTITY(1,1) PRIMARY KEY,
Name nvarchar(50) not null,
Location nvarchar(50) not null
);
CREATE TABLE PlacePhotos
(
PhotoURI nvarchar(200) not null PRIMARY KEY,
PlaceId bigint not null REFERENCES Places (Id)
);
用于创建索引的类:
public partial class Photo
{
[IsSearchable]
public string PhotoURI { get; set; }
public List<Details> Details { get; set; }
}
public partial class Place
{
[System.ComponentModel.DataAnnotations.Key]
public string Id { get; set; }
[IsSearchable, IsFilterable, IsSortable, IsFacetable]
public string Name { get; set; }
[IsSearchable, IsFilterable]
public string Location { get; set; }
[IsSearchable, IsFilterable, IsSortable]
public List<Photo> Photos { get; set; }
}
索引器(以PlacePhotos 表作为其数据源):
private static void Create_PlacePhotos_Indexer(SearchServiceClient serviceClient)
{
var indexerDef = new Indexer(
name: placePhotosIndexer,
dataSourceName: placePhotosDataSource,
targetIndexName: index,
skillsetName: skillset,
schedule: new IndexingSchedule
{
Interval = new TimeSpan(0, 30, 0)
},
fieldMappings: new List<FieldMapping>
{
new FieldMapping("PlaceId", "Id"),
new FieldMapping("PhotoURI", "PhotoURI")
},
outputFieldMappings: new List<FieldMapping>
{
new FieldMapping("/document/Id", "Id"),
new FieldMapping("/document/PhotoURI", "Photos/*/PhotoURI"),
new FieldMapping("/document/Details", "Photos/*/Details")
}
);
serviceClient.Indexers.CreateOrUpdate(indexerDef);
}
【问题讨论】:
标签: c# azure indexing azure-sql-database azure-cognitive-search