Skip to content

Runtime exception when specifying FieldSortOrderDescriptor #7074

Closed
@kleanthis

Description

@kleanthis

Elastic.Clients.Elasticsearch version:
8.0.1

Elasticsearch version:
8.5.2

.NET runtime version:

$ dotnet --version
7.0.100

$ dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

This is an AspNetCore 6.0.11

Operating system version:
macOS Ventura 13.0.1 (22A400)

Description of the problem including expected versus actual behavior:
Cannot set Sort order in SortOptionsDescriptor<T>

Steps to reproduce:

var response = await client.SearchAsync<SomeType>(
    s => s
        .Index("...")
        .Size(100)
        .Sort(
            srt => srt.Field(
                f => f.SomeFieldHere,
                cfg => cfg.Order(SortOrder.Desc)
            )

        ), cancellationToken
);

The above compiles fine. When invoked at runtime, there is an exception:

Stacktrace (partial)

Elastic.Transport.UnexpectedTransportException: Value cannot be null. (Parameter 'propertyName')
       ---> System.ArgumentNullException: Value cannot be null. (Parameter 'propertyName')
         at System.Text.Json.Utf8JsonWriter.WritePropertyName(String propertyName)
         at Elastic.Clients.Elasticsearch.SortOptionsDescriptor`1.Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) in /_/src/Elastic.Clients.Elasticsearch/_Generated/Types/SortOptions.g.cs:line 165
         at Elastic.Clients.Elasticsearch.Fluent.SerializableDescriptor`1.Elastic.Clients.Elasticsearch.Serialization.ISelfSerializable.Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) in /_/src/Elastic.Clients.Elasticsearch/Core/Fluent/Descriptor.cs:line 71
         at Elastic.Clients.Elasticsearch.Serialization.SelfSerializableConverterFactory.SelfSerializableJsonConverter.Write(Utf8JsonWriter writer, ISelfSerializable value, JsonSerializerOptions options) in /_/src/Elastic.Clients.Elasticsearch/Serialization/SelfSerializableConverterFactory.cs:line 34
         at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
         at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
         at System.Text.Json.Serialization.JsonConverter`1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
         at System.Text.Json.JsonSerializer.WriteUsingSerializer[TValue](Utf8JsonWriter writer, TValue& value, JsonTypeInfo jsonTypeInfo)
         at System.Text.Json.JsonSerializer.Serialize[TValue](Utf8JsonWriter writer, TValue value, JsonSerializerOptions options)
         at Elastic.Clients.Elasticsearch.SearchRequestDescriptor`1.Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) in /_/src/Elastic.Clients.Elasticsearch/_Generated/Api/SearchRequest.g.cs:line 1629
         at Elastic.Clients.Elasticsearch.Requests.RequestDescriptor`2.Elastic.Clients.Elasticsearch.Serialization.ISelfSerializable.Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) in /_/src/Elastic.Clients.Elasticsearch/Core/Request/RequestDescriptor.cs:line 22
...

If I omit the FieldSortOrderDescriptor (i.e., the second argument), everything works as expected. But then, how can I specify the sort order?

Surely, I am doing something wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xRelates to a 8.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions