elasticsearch - 修改 Nest 和 Elastic Search 的序列化器设置

标签 elasticsearch json.net nest

我正在尝试更改 Newtonsoft 在使用 Nest 序列化对象时处理自引用循环的方式。我正在使用 Newtonsoft.Json 4.5.11 并且我坚持使用该版本,Nest 是 0.11.7.0 版,我使用的代码片段是

var searchBoxUri = new Uri("Url");

var elasticSettings = new ConnectionSettings(searchBoxUri)
    .SetDefaultIndex("sample");

elasticSettings.SetJsonSerializerSettingsModifier(s => {
    s.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});

var client = new ElasticClient(elasticSettings);

client.Index(currentPage);

使用这段代码,我在堆栈跟踪中得到以下异常

[JsonSerializationException: Self referencing loop detected with type 'some type'.]

那么,为什么客户端不使用我配置的设置或者我在这里遗漏了什么?

最佳答案

这是 0.11.7.0 版本中的一个错误,经过一些重大重构以使序列化更精简。

另见 https://github.com/Mpdreamz/NEST/pull/382

将在 0.11.8/0 中修复

关于elasticsearch - 修改 Nest 和 Elastic Search 的序列化器设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19775611/

相关文章:

c# - 如何使用 JSON.NET 序列化静态或 const 成员变量?

c# - 确定 JToken 是否为叶

c# - 在 JsonConvert.SerializeObject 中自定义标识参数

Elasticsearch 许可证.过期.功能安全状态 403

java - 在Windows 7上安装运行elasticsearch : Error in path

elasticsearch - elasticsearch短语_前缀预期结果

elasticsearch - 术语过滤器的 Elasticsearch 连字符问题

elasticsearch - Elasticsearch 中默认禁用字段分析

elasticsearch - 在ElasticSearch 5中将C#枚举另存为字符串而不是int

elasticsearch - NEST是否支持基于脚本的排序?