【发布时间】:2016-01-13 17:10:45
【问题描述】:
我正在尝试使用 NEST 1.7.1 Get 来自 Elasticsearch 1.7.0 的结果。我的文档包含许多字段,但我只对其中一个感兴趣。我希望得到一个代表部分文档的类型化结果。
我正在使用与这段代码类似的东西:
var settings = new ConnectionSettings(new Uri(url)).SetDefaultIndex("MyIndex");
var client = new ElasticClient(settings);
var result = client.Get<MyDtoPartial>(g => g
.Type("myDocType")
.Id("abcdefg123456")
.Fields("doc.subids")
);
MyDtoPartial 目前看起来像这样:
public class MyDtoPartial
{
[JsonProperty("doc.subids")]
public IList<string> SubIds { get; set; }
// Other properties of my documents are not mapped, in this
// context I only want the SubIds.
}
在调试器中,我可以深入到 result.Fields 并看到该字典中的第一个具有由调试器按照以下行呈现的值:
{[doc.subids, [ "12354adsf-123fasd", "2134fa34a-213123" ...
我还可以看到发出的 Elasticsearch 请求,是这样的:
http://myserver:12345/MyIndex/myDocType/abcdefg123456?fields=doc.subids
它返回这种类型的json:
{
"_index": "MyIndex",
"_type": "myDocType",
"_id": "abcdefg123456",
"_version": 1,
"found": true,
"fields": {
"doc.subids": ["12354adsf-123fasd",
"2134fa34a-213123",
"adfasdfew324-asd"]
}
}
所以我觉得我的请求没问题,因为这是我期望的那种响应。
但是,我的目标是获得一个具有完全填充的SubIds 属性的MyDtoPartial 实例。但是,result 似乎不包含任何类型的 MyDtoPartial 类型的属性。
我已经通过the Nest Get docs,实际上导致了上面的代码。
Get 一个正确类型的单个文档的正确方法是什么,只有来自 Elastic with Nest 的一些字段?
【问题讨论】:
标签: c# elasticsearch nest