# Lowercase property names from .NET using NEST

**URL:** <https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295>\
**Category:** Elasticsearch\
**Created:** [August 22, 2013, 11:26am UTC](https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295 "2013-08-22T11:26:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liron\_Cohen](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@Liron\_Cohen](https://discuss.elastic.co/u/Liron_Cohen)\
**Post date:** [August 22, 2013, 11:26am UTC](https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295/1 "2013-08-22T11:26:55Z")

</div>

Hello,

I'm VERY new to ES and I mainly use C# so I downloaded the NEST .net API.  
I indexed an object (named "Nation" -\> ES type "Nations") which has the  
following properties for example: Name, ISO.  
When I look at the \_source in ES I see it turned all my properties to  
lowercase: name. iSO.  
So I read a bit on NEST and saw they have an attribute for the property:

- [ElasticProperty(Name = "Name")]  
public stirng Name { get; set; }
- [ElasticProperty(Name = "ISO")]  
public stirng ISO { get; set; }  
But this is annoying since it's on the prop level, so I have to set it for  
all the hundreds of props I have in the project.

Isn't there an easier way to tel ES to stop lower-casing my fields?

Thanks.  
Liron

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Martijn\_Laarman\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman_2/32/2033_2.png) [@Martijn\_Laarman\_2](https://discuss.elastic.co/u/Martijn_Laarman_2)\
**Post date:** [August 23, 2013, 7:48am UTC](https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295/2 "2013-08-23T07:48:07Z")

</div>

Hi Liron,

Nests default behavior is to camelCase all the property names, you can  
easily override this globally by setting a custom TypeNameInferrer method.

var uri = new Uri("[http://localhost:9200](http://localhost:9200)");  
var settings = new ConnectionSettings(uri)  
.SetDefaultIndex("mydefaultindex")  
_.SetTypeNameInferrer(i=\>i);_  
var client = new ElasticClient(settings);

This leaves the original propertynames untouched. Be aware though that an  
explicit ElasticProperty Annotation always takes precedence so remove the  
annotations.

See also: [http://nest.azurewebsites.net/concepts/connecting.html](http://nest.azurewebsites.net/concepts/connecting.html)

On Thursday, August 22, 2013 1:26:55 PM UTC+2, Liron Cohen wrote:

> Hello,
> 
> I'm VERY new to ES and I mainly use C# so I downloaded the NEST .net API.  
> I indexed an object (named "Nation" -\> ES type "Nations") which has the  
> following properties for example: Name, ISO.  
> When I look at the \_source in ES I see it turned all my properties to  
> lowercase: name. iSO.  
> So I read a bit on NEST and saw they have an attribute for the property:
> 
> - [ElasticProperty(Name = "Name")]  
> public stirng Name { get; set; }
> - [ElasticProperty(Name = "ISO")]  
> public stirng ISO { get; set; }  
> But this is annoying since it's on the prop level, so I have to set it  
> for all the hundreds of props I have in the project.
> 
> Isn't there an easier way to tel ES to stop lower-casing my fields?
> 
> Thanks.  
> Liron

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Liron\_Cohen](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@Liron\_Cohen](https://discuss.elastic.co/u/Liron_Cohen)\
**Post date:** [August 23, 2013, 1:47pm UTC](https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295/3 "2013-08-23T13:47:16Z")

</div>

Thanks. But I meant the properties' names. no the object (/type) name.  
The correct syntax is:  
.SetDefaultTypeNameInferrer(p =\> p.Name);  
So .net' Location object turn into Location Type in ES.

Any thought as to how to make something similar for properties?

Thanks again,  
Liron

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Martijn\_Laarman\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman_2/32/2033_2.png) [@Martijn\_Laarman\_2](https://discuss.elastic.co/u/Martijn_Laarman_2)\
**Post date:** [August 23, 2013, 2:38pm UTC](https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295/4 "2013-08-23T14:38:58Z")

</div>

Argh, serves me right for writing code from the top of my head before the  
first cuppa.

See: [How to disable camelCase ? · Issue #275 · elastic/elasticsearch-net · GitHub](https://github.com/Mpdreamz/NEST/issues/275)

I'll be sure to improve the API for this in the next version!

On Fri, Aug 23, 2013 at 3:47 PM, Liron Cohen [cliron1@gmail.com](mailto:cliron1@gmail.com) wrote:

> Thanks. But I meant the properties' names. no the object (/type) name.  
> The correct syntax is:  
> .SetDefaultTypeNameInferrer(p =\> p.Name);  
> So .net' Location object turn into Location Type in ES.
> 
> Any thought as to how to make something similar for properties?
> 
> Thanks again,  
> Liron
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/kPjclYNfdGg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/kPjclYNfdGg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Liron\_Cohen](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@Liron\_Cohen](https://discuss.elastic.co/u/Liron_Cohen)\
**Post date:** [August 24, 2013, 11:48am UTC](https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295/5 "2013-08-24T11:48:31Z")

</div>

Ohh... You're a life saver.  
I almost gave up on this...  
Perfect.

So just to keep it all in this thread, here is the final solution:  
var settings = new ConnectionSettings(new Uri("localhost/9200"));  
settings  
.SetDefaultTypeNameInferrer(p =\> p.Name);  
var client = new ElasticClient(settings);  
client.ModifyJsonSerializationSettings(s =\>  
s.ContractResolver = new Nest.Resolvers.ElasticResolver(settings);  
);

Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:19am UTC](https://discuss.elastic.co/t/lowercase-property-names-from-net-using-nest/13295/6 "2017-07-06T02:19:55Z")

</div>


