ElasticSearch 2.0 NEST迁移 [英] ElasticSearch 2.0 NEST migration
问题描述
我使用了2.0版本中找不到的下一个属性 - ElasticProperty
与属性名称,Boost,OptOut
。
我找不到替换 settitgs.SetJsonSerializerSettingsModifier(x => x.DateParseHandling = DateParseHandling.DateTimeOffset)
在新的api。
我发现唯一有用的文档是 break changes 。可悲的是,嵌套示例已经过时了。可能我错过了一些简单的事情,请指出我正确的方向。
修改
所以 Name,Boost
是 String
属性
Ad1。
此部分已重构,现在您不能使用 ElasticProperty
。它已被一系列新的属性所取代(如 break 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;设置;}
等。
Ad2 。
您可以通过自定义 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设置):base(settings)
{
}
protected override void ModifyJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings)
{
settings.DateParseHandling = DateParseHandling.DateTimeOffset;
}
}
我希望它会使您的迁移更容易:)
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
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;
}
}
I hope it's gonna make your migration easier :)
这篇关于ElasticSearch 2.0 NEST迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!