NEST automatically camelcases all field names (as stated in the documentation https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/field-inference.html#camel-casing). There is also a way to define a connection-wide delegate (by using DefaultFieldNameInferrer) for customizing field naming. However, this setting is global for the whole connection.
Is there a way to customize naming only for specific (dynamically mapped) property/field?
I am mapping a dictionary into ElasticSearch and currently NEST camelcases all the keys of the dictionary which has huge side-effects for me. I would like to preserve the naming of dictionary keys so that the dictionary data would be stored without any modifications.
NOTE: This was working as intended in ElasticSearch 2 (dictionary keys were not camelcased when they were mapped to ES). We recently upgraded to ElasticSearch 6 and this new behavior broke our system.
Example:
public class Entity
{
public string Name { get; set; }
public Dictionary<string, string> Data { get; set; }
}
var entity = new Entity()
{
Name = "Foo",
Data = new Dictionary<string, string>()
{
{ "First", "Data1" },
{ "Second", "Data2" }
}
};
// .... Insert entity into ES ....
// Actual result (note lowercase f and s)
{
"name": "Foo",
"data": {
"first": "Data1",
"second": "Data2"
}
}
// Desired result (note uppercae F and S). This is the way how ElasticSearch 2 worked.
{
"name": "Foo",
"data": {
"First": "Data1",
"Second": "Data2"
}