Bra*_*onG 7 elasticsearch nest
我想使用Nest将完成建议字段填充到索引中.在阅读有关实现完成字段的ElasticSearch博客文章后,我发现您可以拥有以下属性:
我假设将这些数据加载到索引中我需要在我的搜索对象中包含一个包含上述字段的实体?
我最终通过创建几个类来加载完成字段,并按照FluentMappingFullExample单元测试,特别是以下部分:
.Completion(s=>s
.Name(p=>p.Name.Suffix("completion"))
.IndexAnalyzer("standard")
.SearchAnalyzer("standard")
.MaxInputLength(20)
.Payloads()
.PreservePositionIncrements()
.PreserveSeparators()
)
Run Code Online (Sandbox Code Playgroud)
对于我的搜索类型实体,我创建了一个名为suggest的字段,并使其类型为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; }
}
Run Code Online (Sandbox Code Playgroud)
在我使用dapper从db加载我的实体之后,然后我循环结果并使用我想要的相应输入加载了我的完成字段.然后,我能够成功调用建议API并查询此数据.我希望这有助于其他人.
| 归档时间: |
|
| 查看次数: |
2357 次 |
| 最近记录: |