ElasticSearch 2.0 NEST migration

最后都变了- 提交于 2019-12-13 02:25:27

问题


I have used elastic 1.7 before. After migration to 2.0 I have faced with several issues (here are those I am most focus currently): mapping attributes, json serialization.

I have used next attributes I can't find in 2.0 version - ElasticPropertywith property Name, Boost, OptOut .

I can't find replacement for settitgs.SetJsonSerializerSettingsModifier(x => x.DateParseHandling = DateParseHandling.DateTimeOffset) in new api.

The only useful document I found is breaking changes. Sadly, but nest examples are outdated. Possible I have missed something easy, please point me in right direction.

Edit

So, Name, Boost are part of String attribute


回答1:


Ad1.

This part has been refactored and right now you can't use ElasticProperty. It has been replaced with bunch of new attributes(as described in breaking changes notes)

For example

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

it's equivalent to

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

etc.

Ad2.

You can modify your serialization settings by passing custom JsonNetSerializer to ConnectionSettings, just like this:

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;
    }
}

More details here and here.

I hope it's gonna make your migration easier :)



来源:https://stackoverflow.com/questions/35502725/elasticsearch-2-0-nest-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!