NEST映射组

时间:2014-05-13 15:58:37

标签: nest

我从NEST开始,我想对我的属性进行分组。

namespace Prototype.Logs
{
    [ElasticType(Name = "msglogs")]
    internal class Msg : BaseLog
    {
        [ElasticProperty(Name = "exception")]
        public string BaseException { get; set; }
        public string InnerException { get; set; }

我想映射类似

的组
  "exception" : {
    "baseexception" : "blablabla() : blabla",
    "innerexception" : "blablabla() : blabla",
  },

相反,我得到一份平面文件:

"baseexception" : "blablabla() : blabla",
"innerexception" : "blablabla() : blabla",

我试图搜索NEST文档,但我没有找到任何内容。

非常感谢

1 个答案:

答案 0 :(得分:0)

您的异常对象应该分解为它自己的类,并映射为Msg的内部或嵌套对象。

这样的事情:

class MyExceptionClass
{
    [ElasticProperty(Name = "baseexception")]
    public string BaseException { get; set; }

    [ElasticProperty(Name = "innerexception")]
    public string InnerException { get; set; }
}

...然后在你的Msg类中:

[ElasticType(Name = "msglogs")]
internal class Msg : BaseLog
{
    [ElasticProperty(Name = "exception")]
    public MyExceptionClass Exception { get; set; }
}
相关问题