Skip to content

[BUG] Azure Search Service fails when sorting a field in descending order #44858

Open
@charles-smith

Description

@charles-smith

Library name and version

Azure.Search.Documents 11.5.1

Describe the bug

When attempting to execute a query that added story_publish_date desc to SearchOptions.OrderBy it generated an invalid odata expression.

Exception details:
Invalid expression: Syntax error: character '+' is not valid at position 18 in 'story_publish_date+desc'.
Parameter name: $orderby
Status: 400 (Bad Request)

Content:

{"error":{"code":"","message":"Invalid expression: Syntax error: character '+' is not valid at position 18 in 'story_publish_date+desc'.\r\nParameter name: $orderby"}}

Stack Trace:

[
{"assembly":"Azure.Search.Documents, Version=11.5.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8","method":"Azure.Search.Documents.SearchClient+<SearchInternal>d__41`1.MoveNext","level":0,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":1,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":2,"line":0},
{"assembly":"Azure.Search.Documents, Version=11.5.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8","method":"Azure.Search.Documents.SearchClient+<SearchInternal>d__40`1.MoveNext","level":3,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":4,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":5,"line":0},
{"assembly":"Azure.Search.Documents, Version=11.5.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8","method":"Azure.Search.Documents.SearchClient+<SearchAsync>d__37`1.MoveNext","level":6,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":7,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":8,"line":0},
{"assembly":"{{ProjectName}}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"{{ProjectName}}.Controllers.SearchController+<SearchDocuments>d__16.MoveNext","level":9,"line":365,"fileName":"D:\\a\\_work\\1\\s\\{{SolutionName}} [\\{{ProjectName}}\\Controllers\\SearchController.cs"},
{"assembly":"System.Private.CoreLib](file://{{projectname}}/Controllers/SearchController.cs%22%7d,%7b%22assembly%22:%22System.Private.CoreLib), Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":10,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":11,"line":0},
{"assembly":"{{ProjectName}}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"{{ProjectName}}.Controllers.SearchController+<Post>d__15.MoveNext","level":12,"line":227,"fileName":"D:\\a\\_work\\1\\s\\{{SolutionName}} [\\{{ProjectName}}\\Controllers\\SearchController.cs"},
{"assembly":"System.Private.CoreLib](file://{{projectname}}/Controllers/SearchController.cs%22%7d,%7b%22assembly%22:%22System.Private.CoreLib), Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":13,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":14,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+TaskOfIActionResultExecutor+<Execute>d__0.MoveNext","level":15,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":16,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":17,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker+<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext","level":18,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":19,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":20,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker+<<InvokeNextActionFilterAsync>g__Awaited|10_0>d.MoveNext","level":21,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":22,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow","level":23,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next","level":24,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker+<<InvokeInnerFilterAsync>g__Awaited|13_0>d.MoveNext","level":25,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":26,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":27,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+<<InvokeFilterPipelineAsync>g__Awaited|20_0>d.MoveNext","level":28,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":29,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":30,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+<<InvokeAsync>g__Logged|17_1>d.MoveNext","level":31,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":32,"line":0},
{"assembly":"Microsoft.AspNetCore.Mvc.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+<<InvokeAsync>g__Logged|17_1>d.MoveNext","level":33,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":34,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":35,"line":0},
{"assembly":"Microsoft.AspNetCore.Routing, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Routing.EndpointMiddleware+<<Invoke>g__AwaitRequestTask|7_0>d.MoveNext","level":36,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":37,"line":0},
{"assembly":"System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":38,"line":0},
{"assembly":"Microsoft.AspNetCore.Diagnostics, Version=8.0.0.0, Culture=neutral,  #PublicKeyToken=adb9793829ddae60","method":"Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl+<<Invoke>g__Awaited|10_0>d.MoveNext","level":39,"line":0}
]

Expected behavior

Search result to be sorted.

Actual behavior

Exception is thrown when sort parameter is included.

Reproduction Steps

public void IssueReproduction(string searchServiceUrl, string indexName, string searchText)
{
    var searchOptions = new SearchOptions { SearchMode = SearchMode.All };

    // setup sorting
    searchOptions.OrderBy.Add("story_publish_date desc");

    //execute search
    var searchIndexClient = new SearchClient(searchServiceUrl, indexName, new DefaultAzureCredential());
    var searchResults = await searchIndexClient.SearchAsync<Dictionary<string, object>>(searchText, searchOptions);
}

Environment

No response

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.Searchcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

Status

Untriaged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions