【发布时间】:2019-04-24 23:01:01
【问题描述】:
我是使用 NEST 使用 .NET 的 Elasticsearch 新手。 我正在尝试执行一个简单的搜索来匹配所有并且只对少数属性感兴趣。我无法获取源中几乎所有字段的值。全部显示为空值
该索引已存在于 elasticsearch 中。
我有一个代表类型的类。
public class DocType
{
public long CommunicationsDate { get; set; }
public string ControlNumber { get; set; }
public string Kind { get; set; }
public string PrimaryCommuncationsName { get; set; }
public float RiskScore { get; set; }
}
我的映射是:
PUT relativity
{
"mappings": {
"doctype": {
"properties": {
"comms_date": {
"type": "date"
},
"control_number": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"kind": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"primary_comms_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"risk_score": {
"type": "float"
}
}
}
}
}
以下查询正确返回 Hits 计数,但除了 Kind 属性之外的值为 null。不知道我在这里做错了什么。这是因为 c# 类中的属性名称不同还是其他什么?
return await _connection.Get<ElasticClient>().SearchAsync<DocType>(s =>
{
var searchDescriptor = s.Index("relativity")
.Type("DocType")
.Size(100)
.Source(sf => sf
.Includes(i => i
.Fields(
f => f.ControlNumber,
f => f.PrimaryCommuncationsName,
f => f.RiskScore,
f => f.Kind,
f => f.CommunicationsDate
)
)
);
}
【问题讨论】:
标签: c# elasticsearch nest