-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Sort failing due to serialization error #1863
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
Comments
@curtismbeard What version of NEST are you using, 2.x? Do you have a minimum reproducible example that I can have a look at this with? |
This should reproduce the error I think.
|
I will work on a simple example that reproduces the issue. I am using 2.0.2. |
I ran into this issue last night. I am using v2.0.2 as well. I was sorting on both the _score field and a mapped date field. When sorting by the score only, I didn't receive the error but when I tried to sort on both the score and the date fields I received the same error listed in this ticket. In NEST 1.4 this worked. After doing some more reading on sorting, I see that scores will not be returned if you are sorting on a field unless you set TrackScores to true. This will ensure that the that scores will be tracked and computed. After I add this to my query, the query returned mixed type results using both _score and the mapped date field. All serialization worked as well. Hope this helps. |
Thank you all for reporting this. It'll be fixed in the next release. |
When I apply a sort, the response is throwing an error when trying to convert the hits back to concrete types.
After looking into the code, it appears that the _score is null when a sort is applied. However, it fails to convert and throws an error. If I set TrackScores to true, it works correctly (_score comes back as 0 in this case). This happens on line 125 in https://github.com/elastic/elasticsearch-net/blob/master/src/Nest/CommonAbstractions/SerializationBehavior/StatefulDeserialization/ConcreteTypeConverter.cs
Here is the exception:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException was unhandled by user code
HResult=-2146233088
Message=Cannot implicitly convert type 'Newtonsoft.Json.Linq.JValue' to 'double'. An explicit conversion exists (are you missing a cast?)
Source=Anonymously Hosted DynamicMethods Assembly
StackTrace:
at CallSite.Target(Closure , CallSite , Object )
at Nest.ConcreteTypeConverter.GetConcreteTypeUsingSelector[T](JsonSerializer serializer, ConcreteTypeConverter
1 realConcreteConverter, JObject jObject) in c:\code\elasticsearch-net\src\Nest\CommonAbstractions\SerializationBehavior\StatefulDeserialization\ConcreteTypeConverter.cs:line 125 at Nest.ConcreteTypeConverter.GetUsingConcreteTypeConverter[T](JsonReader reader, JsonSerializer serializer, ConcreteTypeConverter
1 realConcreteConverter) in c:\code\elasticsearch-net\src\Nest\CommonAbstractions\SerializationBehavior\StatefulDeserialization\ConcreteTypeConverter.cs:line 83at Nest.ConcreteTypeConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in c:\code\elasticsearch-net\src\Nest\CommonAbstractions\SerializationBehavior\StatefulDeserialization\ConcreteTypeConverter.cs:line 62
at Nest.DefaultHitJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in c:\code\elasticsearch-net\src\Nest\CommonAbstractions\SerializationBehavior\StatefulDeserialization\ConcreteTypeConverter.cs:line 24
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
InnerException:
The text was updated successfully, but these errors were encountered: