diff --git a/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs b/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs index a6482589a83..133e1b97603 100644 --- a/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs +++ b/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs @@ -65,7 +65,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s break; case "_geo_distance": var geo = s as IGeoDistanceSort; - writer.WritePropertyName("_geo_distance"); + writer.WritePropertyName(geo.SortKey.Name); base.Reserialize(writer, s, serializer, w => { writer.WritePropertyName(settings.Inferrer.Field(geo.Field)); diff --git a/src/Nest/Search/Search/Sort/SortGeoDistance.cs b/src/Nest/Search/Search/Sort/SortGeoDistance.cs index 6e3d5ea5b9d..98a103fcfe9 100644 --- a/src/Nest/Search/Search/Sort/SortGeoDistance.cs +++ b/src/Nest/Search/Search/Sort/SortGeoDistance.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using Newtonsoft.Json; namespace Nest { @@ -8,7 +9,11 @@ public interface IGeoDistanceSort : ISort { Field Field { get; set; } IEnumerable Points { get; set; } + + [JsonProperty(PropertyName = "unit")] DistanceUnit? GeoUnit { get; set; } + + [JsonProperty(PropertyName = "distance_type")] GeoDistanceType? DistanceType { get; set; } } diff --git a/src/Tests/Search/Request/SortUsageTests.cs b/src/Tests/Search/Request/SortUsageTests.cs index 36198732c6c..bf3ab2a9b09 100644 --- a/src/Tests/Search/Request/SortUsageTests.cs +++ b/src/Tests/Search/Request/SortUsageTests.cs @@ -39,17 +39,19 @@ public SortUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust new { _geo_distance = new { location = new [] { - new { - lat = 70.0, - lon = -70.0 - }, - new { - lat = -12.0, - lon = 12.0 - } + new { + lat = 70.0, + lon = -70.0 + }, + new { + lat = -12.0, + lon = 12.0 + } }, order = "asc", - mode = "min" + mode = "min", + distance_type = "arc", + unit = "cm" } }, new { @@ -84,7 +86,7 @@ public SortUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust ) .GeoDistance(g => g .Field(p => p.Location) - .DistanceType(GeoDistanceType.SloppyArc) + .DistanceType(GeoDistanceType.Arc) .Order(SortOrder.Ascending) .Unit(DistanceUnit.Centimeters) .Mode(SortMode.Min)