Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting rid of some of the hairy parts in NEST part 1/2 #349

Merged
merged 12 commits into from
Sep 20, 2013

Conversation

Mpdreamz
Copy link
Member

NEST is pretty old the first commit was in 2010! 2010-10-07T09:32:05-07:00 to be exact, thats only 8 months after elasticsearch's first commit 2010-02-08T05:22:27-08:00 for those who are wandering.

This PR is about getting rid of some of the fluff gathered in the past three years.

Serialization

Back when NEST first started serializing JSON.NET left dictionary keys alone but in between version 4.0r1 and 4.0r2 of Json.NET this changed (for more info see: http://json.codeplex.com/workitem/20923)

At the time I "solved" this by having two serializers one that does camelCasing and one that doesn't. This was a bad bad mistake on my part as it created a very confusing codebase as to when to use which serializationsettings.

This PR finally rectifies this and introduces ElasticSerializer with only one Serialize and one Deserialize<T> method.

Because of this we can now write this:

var connectionStatus = this._client.Raw.SearchPost(index, typeName, query);
return connectionStatus.Deserialize<QueryResponse<T>>();

or go even more low level:

var connectionStatus = this._client.Connection.PostSync("/myindex/mytype/_search", "{}");
return connectionStatus.Deserialize<QueryResponse<T>>();

RawClient

Not technically part of this commit as i already pushed it to master but the past example shows how NEST will now seperate the Raw calls to elastic search using a .Raw property which exposes a IRawElasticClient (which you can ofcourse new as well if thats all you need`.

The cool thing is that this rawclient is automatically generated from scanning all the REST endpoints in the elasticsearch source code so it should be fairly easy to keep it up to date.

This means that all the *Raw() methods on IElasticClient are now gone.

Property name handling

You can now finally hook into how NEST should handle unspecified propertynames, meaning those not marked with an [ElasticProperty(Name="")] or (I)Dictionary<T,K> properties who should be treated verbatim by calling:

    //Do not do anything to properties
    .SetDefaultPropertyNameInferrer(a=>a)

On ConnectionSettings.

Sayanora .IsValid and .TryConnect(), hello .RootNodeInfo()

The first 2 features of ElasticClient I wrote nearly three years ago which seemed like a good idea at the time. TryConnect() and .IsValid() are two confusing ways to check if your node is up, RootNodeInfo() now returns a mapped response of the info elasticsearch returns when you hit a node at the root (version, lucene_version etc), or you can call client.Raw.MainGet() or perhaps even better client.Raw.MainHead() or even client.Connection.HeadSync("/").

You catch my drift: with so many ways of querying the root .IsValid and TryConnect() is just fluff that only introduces confusion.

Next up: (AKA part 2)

Not part of this PR but serves as a heads up of coming changes

PathResolver

This class is used to make all the url endpoints, since we have IRawClient now which already has all the urls in it this class needs to go. Instead descriptors should be responsible for returning the querystring parameters.

All the calls on IElasticClient should then use the IRawClient instead of going directly to IConnection.

Missing Async Methods on IElasticClient

Not all the methods on IElasticClient have an Async counterpart.

Mpdreamz added a commit that referenced this pull request Sep 20, 2013
Getting rid of some of the hairy parts in NEST part 1/2
@Mpdreamz Mpdreamz merged commit 757b279 into master Sep 20, 2013
@Mpdreamz Mpdreamz deleted the serialization-consolidation branch September 20, 2013 20:09
Mpdreamz added a commit that referenced this pull request Sep 20, 2013
…sponse, everything flows to Deserialize noticed after writing PR notes for #349
@paradigmshifted
Copy link

You might want to update the documentation on Azure to clarify that .TryConnect and .IsValid is no longer supported. (http://nest.azurewebsites.net/concepts/connecting.html)

@jakejscott
Copy link

@paradigmshifted You should send him a pull request :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants