【发布时间】:2016-02-14 02:57:08
【问题描述】:
我正在尝试使用 NEST 客户端进行自动完成。
代码如下:
Poco(精简版):
public class Course
{
[ElasticProperty(Name="id")]
public int ID { get; set; }
public string Name { get; set; }
[ElasticProperty(Type = FieldType.Completion)]
public CompletionField Suggest { get; set; }
public Course(sm.Models.Course c)
{
if (c != null)
{
this.ID = c.ID;
this.Name = c.Name;
this.Suggest = new CompletionField
{
Input = new List<string>(this.Name.Split(' ')) { this.Name },
Output = this.Name,
Payload = new
{
id = this.Name
},
Weight = 1
};
}
}
}
索引:
Client.CreateIndex("myindex", c => c
.NumberOfReplicas(1)
.NumberOfShards(5)
.Settings(s => s
.Add("merge.policy.merge_factor", "10")
.Add("search.slowlog.threshold.fetch.warn", "1s")
)
.AddMapping<Course>(m => m.MapFromAttributes()
.Properties(props => props
.Completion(s=>s
.Name(p=>p.Suggest)
.IndexAnalyzer("simple")
.SearchAnalyzer("simple")
.MaxInputLength(20)
.Payloads()
.PreservePositionIncrements()
.PreserveSeparators()
)
)
));
我的建议查询:
GET _suggest
{
"course-suggest": {
"text": "Nothilfe",
"completion": {
"field": "suggest",
"size": 10
}
}
}
导致此错误的原因:
"failures": [
{
"shard": 1,
"index": "myindex",
"status": "INTERNAL_SERVER_ERROR",
"reason": {
"type": "exception",
"reason": "failed to execute suggest",
"caused_by": {
"type": "exception",
"reason": "Field [suggest] is not a completion suggest field"
}
}
}
为什么我的建议字段未被识别为完成字段?
获取_映射/课程
"suggest": {
"properties": {
"input": {
"type": "string"
},
"output": {
"type": "string"
},
"payload": {
"properties": {
"id": {
"type": "string"
}
}
},
"weight": {
"type": "long"
}
}
【问题讨论】:
-
也许this 会有帮助。
-
我的作品基于这个链接
-
您的索引映射看起来不正确,您可以重新创建索引吗?
-
我已经尝试重新索引整个内容。我该怎么做?什么看起来不对?
-
我的意思是,删除索引并再创建一次。我相信你的映射已经过时了。
标签: .net elasticsearch nest