ElastiSearch NEST - $更新期间的类型反转映射

时间:2017-01-17 18:30:23

标签: elasticsearch nest

我在索引创建过程中使用动态映射:

 var node = new Uri(_settings.ElasticSearchEndPoint);
            var connectionPool = new SingleNodeConnectionPool(node);
            var _settings = new ConnectionSettings(
                connectionPool,
                new HttpConnection(),                    
                new SerializerFactory((jsonSettings, nestSettings) => jsonSettings.TypeNameHandling = TypeNameHandling.Auto));

            _settings
                .MapDefaultTypeNames(m => m.Add(typeof(Activity), _settings.ElasticSearchDefaultType))
                .DefaultIndex(_settings.ElasticSearchDefaultIndex); 

            _esClient = new ElasticClient(_settings);
            var responseMap = _esClient.Map<Activity>(ms => ms
                                .AutoMap()
                                .Properties(ps => ps
                                    .Nested<IActivityDetail>(n => n
                                        .Name(c => c.Details)
                                    .AutoMap()
                                    )
                                )
                            );

感谢这一行:

new SerializerFactory((jsonSettings, nestSettings) => jsonSettings.TypeNameHandling = TypeNameHandling.Auto));

当我插入一个包含详细信息的新活动时,将使用正确的类型映射详细信息:

"details": [
            {
              "$type": "XXX.Plugin.Domain.Service, XXX.Plugin.Test",
              "id": 1,
              "itemInstanceId": 3650,
              "defect": 1,
              "operation": 1
            }

但是当我使用:

更新文档时
var status = esClient.Update<Activity>(  
                 new DocumentPath<Activity>(activity), u => 
                        u.Doc(activity));

文档定期更新,但$ Type将结束详细信息类型,如:

"details": [
        {              
          "id": 1,
          "itemInstanceId": 3650,
          "defect": 1,
          "operation": 1
          "$type": "XXX.Plugin.Domain.Service, XXX.Plugin.Test",
        }

Json无法正确映射文档。 有什么想法吗?

0 个答案:

没有答案