如何NEST禁用骆驼外壳Elasticsearch字段名? [英] How to disable camel casing Elasticsearch field names in NEST?

查看:448
本文介绍了如何NEST禁用骆驼外壳Elasticsearch字段名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下,将NEST发送对象时Elasticsearch索引骆驼情况下对象和属性名。如何能驼峰大小写字段名巢被禁用的Elasticsearch文件?我做的研究相当数量,并有一个的邮件列表线程,但因为一些方法已重命名或不再似乎已经过时存在。

By default, NEST will camel case object and property names when sending an object to Elasticsearch for indexing. How can camel casing field names be disabled in NEST for Elasticsearch documents? I've done a fair amount of research and there's a mailing list thread on the subject, but it seems outdated as some of the methods have been renamed or no longer exist.

IConnectionPool connectionPool = new SniffingConnectionPool(m_ElasticsearchNodeUris);
ConnectionSettings settings = new ConnectionSettings(connectionPool);
settings.SetDefaultTypeNameInferrer(p => p.Name); //This disables camel casing for object type names
ElasticClient client = new ElasticClient(settings);

在邮件列表中的信息表示该代码应该加处理事情的字段名称,但客户端的方法似乎并不存在:

The info in the mailing list indicates this code should be added to handle things for field names, but the client method doesn't seem to exist:

client.ModifyJsonSerializationSettings(s => s.ContractResolver = new Nest.Resolvers.ElasticResolver(settings);

没有人有任何更新的语法来处理此感谢

Does anyone have any updated syntax to handle this? Thanks.

推荐答案

ConnectionSettings.SetDefaultPropertyNameInferrer()就是你要找的东西。这个方法接受这需要一个属性名和转换适用于它的功能。该功能被当时称为在每个属性之前请求被发送到Elasticsearch。

ConnectionSettings.SetDefaultPropertyNameInferrer() is what you're looking for. This method accepts a function that takes a property name and applies a transformation to it. The function is then called on each of your properties before requests are sent to Elasticsearch.

如果你想保持你的属性名称不变,那么你可以这样做:

If you want to keep your property names untouched, then you can do this:

settings.SetDefaultPropertyNameInferrer(p => p)

p => p 这里只是简单地作为一个函数,它接受一个字符串(您的属性名)并返回相同的字符串修改。

p => p here just simply being a function that takes a string (your property name) and returns the same string unmodified.

这篇关于如何NEST禁用骆驼外壳Elasticsearch字段名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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