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

Cannot sort with nullable long - "No mapping found" #8035

Open
develorem opened this issue Feb 7, 2024 · 0 comments
Open

Cannot sort with nullable long - "No mapping found" #8035

develorem opened this issue Feb 7, 2024 · 0 comments
Labels
8.x Relates to 8.x client version

Comments

@develorem
Copy link

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:

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}

@develorem develorem added the 8.x Relates to 8.x client version label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version
Projects
None yet
Development

No branches or pull requests

1 participant