【发布时间】:2019-08-12 16:43:27
【问题描述】:
我在为我的用户模型创建索引时遇到问题。我的 C# 模型是-
public sealed class User
{
public long Id { get; set; }
public string FullName { get; set; }
public HashSet<Reference> References { get; set; }
}
public sealed class Reference
{
public string Type { get; set; }
public string Id { get; set; }
}
我正在使用 NEST nuget 创建索引。
var newIndexResponse = await _elasticClient.CreateIndexAsync(aliasData.NewIndex, i => i
.Mappings(mappingsDescriptor => mappingsDescriptor
.Map<User>(m => m
.Properties(ps => ps
.Text(p => p
.Name(u => u.References)
.Analyzer(ElasticConstants.TwoLetterAnalyzerName)
.SearchAnalyzer(ElasticConstants.NameSearchAnalyzerName))
.Object<HashSet<Reference>>(p => p // This throws error
.Name(up => up.References)
.Properties(up => up.Object<Reference>(sp => sp
.Properties(so => so
.Keyword(eri => eri
.Name(ei => ei.Id)))
.Properties(so => so
.Keyword(ert => ert.Name(t => t.Type)))
))
)
)
)));
当我尝试运行此代码时,我在映射 Hashset 时遇到错误。
无法获取 ObjectTypeDescriptor
2 mapping: ArgumentException at Nest.PropertiesDescriptor1.SetProperty(IProperty) 的字段名称 类型)在 Nest.ObjectPropertyDescriptorBase4.<>c.<Properties>b__21_0(TInterface a, Func2 v) 在 Nest.Fluent.Assign[TDescriptor,TInterface,TValue](TDescriptor self, TValue 值,Action`2 赋值)
用户模型是一个 AWS DynamoDb 实体,所以我使用 Hashset 代替 List。我的最终目标是在 Reference 类中按 Type 和 Id 搜索用户。我需要帮助来确定HashSet<Reference> 的映射。
【问题讨论】:
标签: c# nest aws-elasticsearch