【问题标题】:ElasticSearch 2.0 NEST migrationElasticSearch 2.0 NEST 迁移
【发布时间】:2016-05-31 20:58:25
【问题描述】:

我以前用过 elastic 1.7。迁移到 2.0 后,我遇到了几个问题(以下是我目前最关注的问题):映射属性json 序列化

我使用了在 2.0 版本中找不到的下一个属性 - ElasticPropertywith property Name, Boost, OptOut

我在新 api 中找不到 settitgs.SetJsonSerializerSettingsModifier(x => x.DateParseHandling = DateParseHandling.DateTimeOffset) 的替代品。

我找到的唯一有用的文档是breaking changes。可悲的是,但nest examples 已经过时了。可能我错过了一些简单的事情,请指出正确的方向。

编辑

所以,Name, BoostString 属性的一部分

【问题讨论】:

    标签: elasticsearch nest elasticsearch-2.0


    【解决方案1】:

    广告 1。

    这部分已经重构,现在你不能使用ElasticProperty。它已被一堆新属性取代(如breaking changes notes 中所述)

    例如

    [ElasticProperty(Name="name", Boost = 1.1, OptOut = true)]
    public string Name {get; set;}
    

    相当于

    [String(Name="name", Boost = 1.1, Ignore = true)]
    public string Name {get; set;}
    

    等等

    广告 2。

    您可以通过将自定义JsonNetSerializer 传递给ConnectionSettings 来修改您的序列化设置,就像这样:

    var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
    var settings = new ConnectionSettings(connectionPool, connectionSettings => new MyJsonNetSerializer(connectionSettings))
        .DefaultIndex(indexName)
        .DisableDirectStreaming()
        .PrettyJson();
    
    public class MyJsonNetSerializer : JsonNetSerializer
    {
        public MyJsonNetSerializer(IConnectionSettingsValues settings) : base(settings)
        {
        }
    
        protected override void ModifyJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings)
        {
            settings.DateParseHandling = DateParseHandling.DateTimeOffset;
        }
    }
    

    更多详情herehere

    我希望它能让你的迁移更容易:)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2017-08-29
    • 1970-01-01
    相关资源
    最近更新 更多