如何禁用骆驼套装NEST中的弹性搜索字段名称? [英] How to disable camel casing Elasticsearch field names in NEST?

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

问题描述

默认情况下,当将对象发送到Elasticsearch进行索引时,NEST将会将case对象和属性名称加载。如何在NEST中弹性搜索文件禁用骆驼套装字段名称?我做了大量的研究,并且有一个邮件列表线程,但是似乎已经过时了,因为某些方法已被重命名或不再存在。

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中的弹性搜索字段名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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