Skip to content

Commit a7aa397

Browse files
committed
Include unit and distance_type when set
See #1836
1 parent 8f81232 commit a7aa397

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

Diff for: src/Nest/CommonOptions/Sorting/SortJsonConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
6565
break;
6666
case "_geo_distance":
6767
var geo = s as IGeoDistanceSort;
68-
writer.WritePropertyName("_geo_distance");
68+
writer.WritePropertyName(geo.SortKey.Name);
6969
base.Reserialize(writer, s, serializer, w =>
7070
{
7171
writer.WritePropertyName(settings.Inferrer.Field(geo.Field));

Diff for: src/Nest/Search/Search/Sort/SortGeoDistance.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq.Expressions;
4+
using Newtonsoft.Json;
45

56
namespace Nest
67
{
78
public interface IGeoDistanceSort : ISort
89
{
910
Field Field { get; set; }
1011
IEnumerable<GeoLocation> Points { get; set; }
12+
13+
[JsonProperty(PropertyName = "unit")]
1114
DistanceUnit? GeoUnit { get; set; }
15+
16+
[JsonProperty(PropertyName = "distance_type")]
1217
GeoDistanceType? DistanceType { get; set; }
1318
}
1419

Diff for: src/Tests/Search/Request/SortUsageTests.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ public SortUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
3939
new {
4040
_geo_distance = new {
4141
location = new [] {
42-
new {
43-
lat = 70.0,
44-
lon = -70.0
45-
},
46-
new {
47-
lat = -12.0,
48-
lon = 12.0
49-
}
42+
new {
43+
lat = 70.0,
44+
lon = -70.0
45+
},
46+
new {
47+
lat = -12.0,
48+
lon = 12.0
49+
}
5050
},
5151
order = "asc",
52-
mode = "min"
52+
mode = "min",
53+
distance_type = "arc",
54+
unit = "cm"
5355
}
5456
},
5557
new {
@@ -84,7 +86,7 @@ public SortUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
8486
)
8587
.GeoDistance(g => g
8688
.Field(p => p.Location)
87-
.DistanceType(GeoDistanceType.SloppyArc)
89+
.DistanceType(GeoDistanceType.Arc)
8890
.Order(SortOrder.Ascending)
8991
.Unit(DistanceUnit.Centimeters)
9092
.Mode(SortMode.Min)

0 commit comments

Comments
 (0)