elasticsearch-net
elasticsearch-net copied to clipboard
Cannot sort with nullable long - "No mapping found"
Elastic.Clients.Elasticsearch version: 8.12
Elasticsearch version: 8.11
.NET runtime version: 6.0
Operating system version: Windows 10
Description of the problem including expected versus actual behavior:
Sorting mostly works. However a field with a mapping as 'long' in ES cannot be sorted using the non-fluent api. Sorting other fields like Keyword and Date work fine.
Steps to reproduce: This code crates the sort options:
return SortOptions.Field("rating", new FieldSort() { Order = order });
The mapping for the field according to the index is as follows:
"rating": {
"type": "long"
},
Looking at this issue in StackOverFlow, it suggest setting "ignore_unmapped" : true
However the code api for new FieldSort() does not support this ability.
I tried instead to set the 'Missing' value as follows:
return SortOptions.Field("rating", new FieldSort() { Order = order, Missing = FieldValue.Long(0) });
My assumption is that if the field "rating" is null, it would use the value "0" when sorting?
Its possible the mapping is wrong, however this mapping was inferred by either ES or the .NET client when I created the index and stored this object.
In the .NET model, "rating" is of type "nullable
Expected behavior Sorting to occur on numeric fields
Provide DebugInformation
(if relevant):
This is the error returned on the response object debug info:
Invalid Elasticsearch response built from a unsuccessful (400) low level call on POST: /search_team_34930/_search Exception: Request failed to execute. Call: Status code 400 from: POST /search_team_34930/_search. ServerError: Type: search_phase_execution_exception Reason: "all shards failed"
Audit trail of this API call:
- [1] BadResponse: Node: https://f16c2da0d5eb4aa78b15d770bb0cdda2.westus2.azure.elastic-cloud.com/ Took: 00:00:00.7681911
OriginalException: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: POST /search_team_34930/_search. ServerError: Type: search_phase_execution_exception Reason: "all shards failed"
Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on TransportConfiguration to force it to be set on the response.>
Response:
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"No mapping found for [rating] in order to sort on","index_uuid":"1W2pikh8Qm-18msta8u8AQ","index":"search_team_34930"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"search_team_34930","node":"JrpMzMvVTs6xBk4Wd0Vkcw","reason":{"type":"query_shard_exception","reason":"No mapping found for [rating] in order to sort on","index_uuid":"1W2pikh8Qm-18msta8u8AQ","index":"search_team_34930"}}]},"status":400}