[英]Elastic/NEST will not handle null values
I am currently limited to NEST v2.4.6. 我目前仅限于NEST v2.4.6。
I have objects with attributes that can sometimes be null and must be persisted with those null attributes. 我有一些属性有时可能为null的对象,必须将这些null属性保留下来。
According to the documentation: https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/modifying-default-serializer.html#_modifying_settings_using_serializerfactory 根据文档: https : //www.elastic.co/guide/zh-CN/elasticsearch/client/net-api/2.x/modifying-default-serializer.html#_modifying_settings_using_serializerfactory
This should allow me to serialize Null values. 这应该允许我序列化Null值。 Unfortunately, once setting this up, all my ElasticDB queries start to return nothing.
不幸的是,一旦进行了设置,我所有的ElasticDB查询都开始不返回任何内容。
This is confusing as when I put the 当我把
[JsonProperty(NullValueHandling = NullValueHandling.Include)]
attribute, it works fine. 属性,效果很好。
I obviously however would like to enable this globally. 但是,我显然希望在全球范围内启用此功能。
This is what my implementation looks like: 这是我的实现形式:
var pool = new SingleNodeConnectionPool(new Uri(ConfigurationManager.AppSettings["ElasticInstanceAddress"]));
var connection = new HttpConnection();
var settings = new ConnectionSettings(pool, connection,
new SerializerFactory((s, values) =>
{
s.NullValueHandling = NullValueHandling.Include;
}));
An example NEST query that suddenly starts to return nothing after the NullValueHandling
is enabled on the serializer is as below: 在序列化
NullValueHandling
上启用NullValueHandling
后,突然开始不返回任何内容的示例NEST查询如下:
var dog = _client.Get<Dog>(query.DogName).Source;
Any ideas? 有任何想法吗?
Why should your object be persisted with null values? 为什么您的对象应该保留为空值? Persisted or not, the value should be
null
when deserialized back from _source
because the field is either missing or actually set to null
. 是否持久化,从
_source
反序列化时,该值应为null
,因为该字段丢失或实际上设置为null
。 In any case, it should work by default. 无论如何,默认情况下它应该工作。 Checking for null in a query can be done with an Exists Query, see : https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-exists-query.html
可以使用“存在查询”完成查询中的null检查,请参阅: https : //www.elastic.co/guide/zh-CN/elasticsearch/reference/2.4/query-dsl-exists-query.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.