C# 是否可以在Azure搜索索引中填充集合?
我目前正在使用Azure Search,我偶然发现了一个场景,其中我有两个表:一个表描述了一个地方,另一个表中每个地方都有多张照片 我想使用两个索引器来填充同一个索引,其中一个将填充位置的详细信息(名称、坐标等),而另一个将获取照片,运行一个自定义的C# 是否可以在Azure搜索索引中填充集合?,c#,azure,indexing,azure-sql-database,azure-cognitive-search,C#,Azure,Indexing,Azure Sql Database,Azure Cognitive Search,我目前正在使用Azure Search,我偶然发现了一个场景,其中我有两个表:一个表描述了一个地方,另一个表中每个地方都有多张照片 我想使用两个索引器来填充同一个索引,其中一个将填充位置的详细信息(名称、坐标等),而另一个将获取照片,运行一个自定义的WebApiSkill,从照片中获取某些详细信息,并将它们添加到索引上的复杂集合中 问题是,我不知道如何在索引上填充照片集合。我已尝试将我的outputFieldMappings定义为Photos/*/Details,或仅定义为Photos/Deta
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 Search中填充这样一个复杂的集合,如果有,我将如何进行
表:
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; }
}
目标字段名称必须是顶级索引字段名称,因此Photos/*/PhotoURI
无效,您必须直接将Photos
作为目标
要“塑造”要映射的照片
值,可以使用
和输出字段映射
new FieldMapping("/document/photos/*/shapedValue", "Photos")
注意-您可能需要重新安排输出URI和详细信息的技能,以便它们共享一个共同的
上下文
。从上面的代码片段来看,似乎每个文档
只有一张照片,这与您的索引定义不同。谢谢您的回答。只有一个细节我不明白:像这样的映射会有效地填充一个复杂的字段吗?如果我将多张照片中的多个值生成到一个photos
字段中,它们仍然会在每次重写时覆盖该字段,否?Place
类定义了public List Photos
,因此Photos
是一个复杂类型的集合,需要一个Photo
s数组。这是否意味着多张照片可以映射到该集合而不相互覆盖?类中定义的顶级Photos
位置
必须是唯一的(每个文档1个),但是每个照片
值可以包含零个或多个类照片
值(并且每个照片
将在不覆盖的情况下存储)。由于照片
被定义为列表照片
,因此它对应于索引字段类型集合(Edm.ComplexType)-请参阅。因此它们不会相互覆盖。。那是我的恐惧。谢谢你的解释!
{
"@odata.type": "#Microsoft.Skills.Util.ShaperSkill",
"context": "/document/photos/*",
"inputs": [
{
"name": "PhotoURI",
"source": "/document/photos/*/PhotoURI"
},
{
"name": "Details",
"source": "/document/photos/*/Details"
}
],
"outputs": [
{
"name": "output",
"targetName": "shapedValue"
}
]
}
new FieldMapping("/document/photos/*/shapedValue", "Photos")