Skip to content

Commit 087ac47

Browse files
committed
Added overload to type filter
1 parent 179e448 commit 087ac47

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/Nest.Tests.Unit/Search/Filter/ConditionLess/ConditionLessTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,8 @@ public void TermsTest()
247247
public void TypeTest()
248248
{
249249
this.DoConditionlessFilter(f => f.Type(string.Empty));
250-
this.DoConditionlessFilter(f => f.Type(null));
250+
this.DoConditionlessFilter(f => f.Type((string)null));
251251
}
252252

253-
254-
255253
}
256254
}

src/Nest/DSL/Filter/TypeFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using Nest.Resolvers;
56
using Newtonsoft.Json;
67

78
namespace Nest
@@ -18,6 +19,6 @@ internal override bool IsConditionless
1819
}
1920

2021
[JsonProperty(PropertyName = "value")]
21-
public string Value { get; set;}
22+
public TypeNameMarker Value { get; set; }
2223
}
2324
}

src/Nest/DSL/FilterDescriptor.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,23 @@ public BaseFilter Type(string type)
549549
this.TypeFilter = filter;
550550
return new FilterDescriptor<T>() { TypeFilter = filter };
551551
}
552+
553+
/// <summary>
554+
/// Filters documents matching the provided document / mapping type.
555+
/// Note, this filter can work even when the _type field is not indexed
556+
/// (using the _uid field).
557+
/// </summary>
558+
public BaseFilter Type(Type type)
559+
{
560+
var filter = new TypeFilter { Value = type };
561+
if (filter.IsConditionless)
562+
return CreateConditionlessFilterDescriptor("filter", filter);
563+
564+
this.SetCacheAndName(filter);
565+
this.TypeFilter = filter;
566+
return new FilterDescriptor<T>() { TypeFilter = filter };
567+
}
568+
552569
/// <summary>
553570
/// A filter that matches on all documents.
554571
/// </summary>

0 commit comments

Comments
 (0)