0

In 2.0 alpha for nest I am struggling to set the DefaultFieldNameInferrer to camelCase.

After figuring out how to view the 'request body' (by explicity setting the DisableDirectStreaming to true, despite the default is true...), I can see that for a request like:

...fil.Bool(b2 => b2.Must(m => m.Term(t => t.DomainName, host))))...

it is sending DomainName with a captial D:

...{"term":{"DomainName":{"value":"example.com"}}}]}...

Version 1.7 always sent camelCase and hence my mappings are all camelCase.

How can I change this back to camelCase?

Edit

Connection:

ElasticClient = new ElasticClient
            (new ConnectionSettings(new Uri(WebConfigMethods.GetElasticSearchUri())).MapDefaultTypeIndices
                 (new ElasticsearchMethods().ElasticSearchDefaultTypeIndices)
                                                                                    .DisableDirectStreaming(true)
                                                                                    .DefaultFieldNameInferrer
                 (s =>
                     {
                         if (string.IsNullOrEmpty(s))
                             return s;

                         if (!char.IsUpper(s[0]))
                             return s;

                         string camelCase = char.ToLower(s[0], CultureInfo.InvariantCulture)
                                                .ToString(CultureInfo.InvariantCulture);
                         if (s.Length > 1)
                             camelCase += s.Substring(1);

                         return camelCase;
                     }));

Request:

var result = elasticClient.Search<ADocType>
                (s => s.Take(1)
                       .Query
                          (qu =>
                           qu.Bool
                               (b => b.Filter(fil => fil.Bool(b2 => b2.Must(m => m.Term(t => t.DomainName, host)))))));

What nest actually sends:

{"size":1,"query":{"bool":{"filter":[{"bool":{"must":[{"term":{"DomainName":{"value":"example.com"}}}]}}]}}}
Robin Rieger
  • 1,204
  • 1
  • 16
  • 37
  • This should help: http://stackoverflow.com/questions/27282865/how-to-disable-camel-casing-elasticsearch-field-names-in-nest/27296871#27296871 – Val Jan 15 '16 at 06:41
  • @Val I tried to override it as seen in edit... no luck.... :S – Robin Rieger Jan 15 '16 at 06:50
  • How about using [ElasticAttibute(Name="") or JsonProperty(Name="")](http://nest.azurewebsites.net/nest/index-type-inference.html)? – Val Jan 15 '16 at 06:55
  • `[JsonProperty("DomainName")] public string DomainName{ get; set; }` -- as it has always been...... i.e. on nest 1.7 my connection string only goes up to an NOT including `DisableDirectStreaming` and it works with camel case.... the `DefaultFieldNameInferrer` even says the default is camelCase, but I can not get it to work. Json is 7.01 – Robin Rieger Jan 15 '16 at 06:58
  • @Val Changing `JsonProperty` to `domainName` does in fact change the request. Given but that I have several thousand of these setup and they are all capitals, is there a setting I can pass in nest to force camelCase and ignore the `JsonProperty` as in nest 1.7? – Robin Rieger Jan 15 '16 at 07:58
  • @Val I think I found the code that 'changes' this. [Here](https://github.com/elastic/elasticsearch-net/blob/21606e55ff3ac5e54b80b3c6a5d617d97904c392/src/Tests/ClientConcepts/HighLevel/Inferrence/FieldNames/FieldInference.doc.cs) at line 149 and [here](https://github.com/elastic/elasticsearch-net/pull/1692) for the 'reason'..... It feels like this should be a 'option' whether to read the `JsonProperty` or not. I mean in my case it just breaks everything..... – Robin Rieger Jan 15 '16 at 08:32
  • Good find! It breaks everything, indeed, but there must be a way as the precedence is 1) NEST mapping attributes, 2) Ask serializer (default looks for JsonProperty) and 3) PropertyNameInferrer(MemberInfo.Name) (default camelCase). – Val Jan 15 '16 at 08:34

1 Answers1

1

Just adding this as a reference in case anyone stumbles across this question later.

Github issue reported here.

See 'Mpdreamz' comment.

I see two options:

  1. implement a subclass of our JsonNetSerailizer that returns what you need for CreatePropertyName

  2. Add a hook at the beginning of the resolve cascading flow. e.g another func on connectionsettings.

Community
  • 1
  • 1
Robin Rieger
  • 1,204
  • 1
  • 16
  • 37