Using Nest Client to load completion fields in Elasticsearch

风格不统一 提交于 2019-11-30 13:54:20

I was able to finally load the completion field by creating several classes, and following the FluentMappingFullExample unit test, specifically the following part:

                    .Completion(s=>s
                    .Name(p=>p.Name.Suffix("completion"))
                    .IndexAnalyzer("standard")
                    .SearchAnalyzer("standard")
                    .MaxInputLength(20)
                    .Payloads()
                    .PreservePositionIncrements()
                    .PreserveSeparators()
                )

For my search type entity, I created a field called suggest and made it of type 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; }
}

After I loaded my entity from the db using dapper, I then looped over the results and loaded my completion field with the appropriate inputs that I wanted. I was then able to successfully call the suggest API and query on this data. I hope this helps someone else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!