【发布时间】:2014-03-14 04:07:55
【问题描述】:
我想使用 Nest 将完成建议字段填充到索引中。读完这个ElasticSearch blog post about implementing a completion field我看到你可以拥有以下属性:
- 输入数组
- 单输出
- 重量
- 有效载荷
我假设要将这些数据加载到索引中,我需要在包含上述字段的搜索对象上包含一个实体?
【问题讨论】:
标签: elasticsearch nest
我想使用 Nest 将完成建议字段填充到索引中。读完这个ElasticSearch blog post about implementing a completion field我看到你可以拥有以下属性:
我假设要将这些数据加载到索引中,我需要在包含上述字段的搜索对象上包含一个实体?
【问题讨论】:
标签: elasticsearch nest
我终于能够通过创建几个类并遵循FluentMappingFullExample 单元测试来加载完成字段,特别是以下部分:
.Completion(s=>s
.Name(p=>p.Name.Suffix("completion"))
.IndexAnalyzer("standard")
.SearchAnalyzer("standard")
.MaxInputLength(20)
.Payloads()
.PreservePositionIncrements()
.PreserveSeparators()
)
对于我的搜索类型实体,我创建了一个名为建议的字段并将其设置为 CompletionField 类型。
public class CompletionField
{
public CompletionField()
{
Input = new List<string>();
}
public List<string> Input { get; set; }
//public string Output { get; set; }
public int Weight { get; set; }
public Payload Payload { get; set; }
}
public class Payload
{
public int ID { get; set; }
}
在我使用 dapper 从 db 加载我的实体后,然后我循环遍历结果并使用我想要的适当输入加载我的完成字段。然后,我能够成功调用建议 API 并查询此数据。我希望这对其他人有帮助。
【讨论】: