gpt4 book ai didi

elasticsearch - 使用 Nest Client 在 Elasticsearch 中加载完成字段

转载 作者:行者123 更新时间:2023-11-29 02:47:32 26 4
gpt4 key购买 nike

我想使用 Nest 将完成建议字段填充到索引中。看完这篇ElasticSearch blog post about implementing a completion field我看到您可以具有以下属性:

  • 输入数组
  • 单一输出
  • 体重
  • 有效载荷

我假设要将此数据加载到索引中,我需要在包含上述字段的搜索对象中包含一个实体?

最佳答案

我终于能够通过创建几个类并遵循 FluentMappingFullExample 来加载完成字段单元测试,具体如下部分:

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

对于我的搜索类型实体,我创建了一个名为 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; }
}

在我使用 dapper 从数据库加载我的实体后,我循环遍历结果并使用我想要的适当输入加载我的完成字段。然后我能够成功调用建议 API 并查询此数据。我希望这对其他人有帮助。

关于elasticsearch - 使用 Nest Client 在 Elasticsearch 中加载完成字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21785425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com