-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This commit updates SortFormatter to be able to deserialize sorts that specify only the field name as a string, or only specify a sort order value. Fixes #4797 Co-authored-by: Russ Cam <[email protected]>
- Loading branch information
1 parent
41959c3
commit 6533731
Showing
2 changed files
with
113 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Text; | ||
using Elastic.Elasticsearch.Xunit.XunitPlumbing; | ||
using FluentAssertions; | ||
using Nest; | ||
using Tests.Core.Client; | ||
|
||
namespace Tests.Reproduce | ||
{ | ||
public class GitHubIssue4797 | ||
{ | ||
[U] | ||
public void DeserializeSortWithOnlyFieldAndOrder() | ||
{ | ||
var json = @" | ||
{ | ||
""sort"" : [ | ||
{ ""post_date"" : {""order"" : ""asc""}}, | ||
""user"", | ||
{ ""name"" : ""desc"" }, | ||
{ ""age"" : ""desc"" }, | ||
""_score"" | ||
], | ||
""query"" : { | ||
""term"" : { ""user"" : ""kimchy"" } | ||
} | ||
} | ||
"; | ||
|
||
var bytes = Encoding.UTF8.GetBytes(json); | ||
var client = TestClient.FixedInMemoryClient(bytes); | ||
|
||
using var stream = client.ConnectionSettings.MemoryStreamFactory.Create(bytes); | ||
var request = client.RequestResponseSerializer.Deserialize<SearchRequest>(stream); | ||
|
||
request.Should().NotBeNull(); | ||
request.Sort.Should().NotBeNull().And.HaveCount(5); | ||
request.Sort[1].SortKey.Should().Be("user"); | ||
request.Sort[2].SortKey.Should().Be("name"); | ||
request.Sort[2].Order.Should().Be(SortOrder.Descending); | ||
} | ||
} | ||
} |