问题
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 - ElasticProperty
with 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