Skip to content

Commit b4914c5

Browse files
committed
fix #1292 allow sort() on fluent search descriptor to return null to or no field/script set to prevent sort being sent
1 parent 8e47bd3 commit b4914c5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Nest/DSL/SearchDescriptor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ public SearchDescriptor<T> Sort(Func<SortFieldDescriptor<T>, IFieldSort> sortSel
680680

681681
sortSelector.ThrowIfNull("sortSelector");
682682
var descriptor = sortSelector(new SortFieldDescriptor<T>());
683+
if (descriptor == null || descriptor.Field.IsConditionless())
684+
return this;
685+
683686
Self.Sort.Add(new KeyValuePair<PropertyPathMarker, ISort>(descriptor.Field, descriptor));
684687
return this;
685688
}
@@ -695,6 +698,8 @@ public SearchDescriptor<T> SortGeoDistance(Func<SortGeoDistanceDescriptor<T>, IG
695698

696699
sortSelector.ThrowIfNull("sortSelector");
697700
var descriptor = sortSelector(new SortGeoDistanceDescriptor<T>());
701+
if (descriptor == null || descriptor.Field.IsConditionless())
702+
return this;
698703
Self.Sort.Add(new KeyValuePair<PropertyPathMarker, ISort>("_geo_distance", descriptor));
699704
return this;
700705
}
@@ -710,6 +715,8 @@ public SearchDescriptor<T> SortScript(Func<SortScriptDescriptor<T>, IScriptSort>
710715

711716
sortSelector.ThrowIfNull("sortSelector");
712717
var descriptor = sortSelector(new SortScriptDescriptor<T>());
718+
if (descriptor == null || descriptor.Script.IsNullOrEmpty())
719+
return this;
713720
Self.Sort.Add(new KeyValuePair<PropertyPathMarker, ISort>("_script", descriptor));
714721
return this;
715722
}

0 commit comments

Comments
 (0)