0
对于我而言,我无法弄清楚为什么Nest只在索引实例时序列化下面的基类的属性,即使我告诉它索引派生类。索引派生的[ElasticType]只能序列化基类的属性
的基类:
[ElasticType(Name = "activity")]
public class Activity
{
[ElasticProperty(Name = "name")]
public string Name { get; set; }
[ElasticProperty(OptOut = true)]
public DateTimeOffset Timestamp
{
get { return DateTimeOffset.ParseExact(TimestampAsString, "yyyyMMddTHHmmssZ", CultureInfo.InvariantCulture).ToUniversalTime(); }
set { TimestampAsString = value.ToString("yyyyMMddTHHmmssZ"); }
}
[Obsolete("Use Timestamp, instead.")]
[ElasticProperty(Name = "timestamp")]
public string TimestampAsString { get; set; }
[ElasticProperty(Name = "application")]
public string Application { get; set; }
[ElasticProperty(Name = "application_version")]
public string ApplicationVersion { get; set; }
[ElasticProperty(OptOut = true)]
public IPAddress RemoteIpAddress
{
get { return IPAddress.Parse(RemoteIpAddressAsString); }
set { RemoteIpAddressAsString = value.ToString(); }
}
[Obsolete("Use RemoteIpAddress, instead.")]
[ElasticProperty(Name = "remote_ip_address")]
public string RemoteIpAddressAsString { get; set; }
}
派生类:
private class SearchCountsRetrievedActivity : Activity
{
[ElasticProperty(OptOut = true)]
public PunctuationlessGuid? PrincipalIdentityId
{
set { PrincipalIdentityIdAsString = value; }
}
[ElasticProperty(Name = "principal_identity_id")]
public string PrincipalIdentityIdAsString { get; set; }
}
我的索引包装方法:
public Task IndexActivityAsync<TActivity>(TActivity activity)
where TActivity : Activity
{
return _client.IndexAsync(activity);
}
不管我做什么,序列化JSON发送过来的线只包括Activity
类的属性。我已经试过:
- 使派生类的公共
- 添加
[ElasticType]
的派生类 - 检查鸟巢的源代码(这是因为源代码是很复杂很困难的,而且的NuGet包我引用,即使它是最新的一个,似乎是最新的源代码不向前兼容)