【问题标题】:Nest 6.2.0 Self Referencing LoopNest 6.2.0 自引用循环
【发布时间】:2018-08-10 06:12:40
【问题描述】:

我正在使用 Nest v6.2.0 连接到弹性搜索。

当我尝试将 A 类型的文档添加到索引时,我收到自引用循环错误,因为 A 类型的对象具有 B 类型的属性,而 B 类型的对象具有 A 类型的属性。这两个类型的对象A & B 是数据库对象。

我可以在 JsonParser 上将 ReferenceLoopHandling 设置设置为 ReferenceLoopHandling.Ignore,它可以很好地解析对象,但我似乎无法将该 json 字符串发送到弹性搜索。那么如何在 Nest 使用的 Json Parser 上设置相同的设置呢?这样我就可以将对象发送到弹性搜索,Nest 可以正确解析对象而不会出现自引用循环错误。

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    您可能希望使用不同的、更简单的 POCO 对您发送到 Elasticsearch 的文档进行建模,以避免通过自引用循环产生潜在的大型对象图。

    可以参考Nest.JsonNetSerializer nuget packagehook up Json.NET as the serializer to use with NEST,配置ReferenceLoopHandling属性

    var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
    
    var settings = new ConnectionSettings(pool, (builtInSerializer, connectionSettings) =>
        new JsonNetSerializer(builtInSerializer, connectionSettings, () => new JsonSerializerSettings
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        }));
    
    var client = new ElasticClient(settings);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 2017-10-17
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多