ElasticSearch 2.0 NEST migration

634 Views Asked by At

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

There are 1 best solutions below

1
Rob On BEST ANSWER

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 :)