ElasticSearch 2.0 NEST迁移 [英] ElasticSearch 2.0 NEST migration

查看:169
本文介绍了ElasticSearch 2.0 NEST迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我使用了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 - 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

解决方案

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

这篇关于ElasticSearch 2.0 NEST迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆