Skip to content

using new Field does not set ComparisonValue #1964

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

Closed
thespatt opened this issue Mar 29, 2016 · 6 comments
Closed

using new Field does not set ComparisonValue #1964

thespatt opened this issue Mar 29, 2016 · 6 comments

Comments

@thespatt
Copy link

I just upgraded from 2.0.2 to 2.0.5 and discovered an issue in our code to create a highlight request. When converting Highlights to the Fields dictionary on HighlightRequest it was throwing an ArgumentNullException in Equals (elasticsearch-net/src/Nest/CommonAbstractions/Infer/Field/Field.cs line 101) and finally discovered that I had to change
return new Nest.Field { Boost = field.Boost, Name = field.Name };
to
return Nest.Field.Create(field.Name, field.Boost);

@gmarz
Copy link
Contributor

gmarz commented Mar 30, 2016

Thanks for raising this @thespatt.

Field is implicitly convertible from a string or expression, which will set ComparisonValue, so you shouldn't have to instantiate one directly, or use the static Create() method. For instance, you can pass the string literal "myfield" (or with a boost value: "myfield^1.2") to any method that takes a Field, or cast (Field)"myfield".

That said, we shouldn't allow Field to be misused like this (e.g. Nest.Field { Boost = field.Boost, Name = field.Name };) and should enforce the string/expression via constructors that call Create() internally. That however would be a binary breaking change, so we'll have to target this for 5.0.

@gmarz gmarz added Bug labels Mar 30, 2016
@gmarz
Copy link
Contributor

gmarz commented Mar 30, 2016

As a temporary solution in 2.x we could hack the property setters.

Thoughts @Mpdreamz @russcam ?

@russcam
Copy link
Contributor

russcam commented Mar 30, 2016

It'll address the problem for 2.x, so I'm 👍 for it there.

Can we make the ctor private in 5.x so that you have to use .Create() or implicit conversion, both of which set ComparisonValue?

@gmarz gmarz removed the v5.0.0 label Mar 30, 2016
@gmarz
Copy link
Contributor

gmarz commented Mar 30, 2016

Cool. Removed the 5.0 label :).

Can we make the ctor private in 5.x so that you have to use .Create() or implicit conversion, both of which set ComparisonValue?

I'd rather make Create() private and call it in the constructors.

@gmarz
Copy link
Contributor

gmarz commented Mar 30, 2016

...or just remove Create() entirely and move the implementation to the ctors.

@russcam
Copy link
Contributor

russcam commented Apr 4, 2016

I can see a slight issue with hacking the property accessors for 2.x - if an API consumer were to set more than one of Name, Expression or PropertyInfo, then the last set accessor will be the one used for ComparisonValue. This seems like a reasonable compromise to fix this bug without breaking binary compatibility?

@russcam russcam added the v2.1.1 label Apr 4, 2016
russcam added a commit that referenced this issue Apr 5, 2016
Throw an exception if more than one of Name, Property or Expression is set with a non-null value
Add documented tests for the changes
Regenerate docs

Fixes #1964
@russcam russcam closed this as completed Apr 5, 2016
Mpdreamz pushed a commit that referenced this issue Jul 26, 2016
Throw an exception if more than one of Name, Property or Expression is set with a non-null value
Add documented tests for the changes
Regenerate docs

Fixes #1964
Mpdreamz pushed a commit that referenced this issue Sep 30, 2016
Throw an exception if more than one of Name, Property or Expression is set with a non-null value
Add documented tests for the changes
Regenerate docs

Fixes #1964
russcam added a commit that referenced this issue Feb 8, 2017
Throw an exception if more than one of Name, Property or Expression is set with a non-null value
Add documented tests for the changes
Regenerate docs

Fixes #1964
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

No branches or pull requests

3 participants