Skip to content

Commit c98b2df

Browse files
russcamMpdreamz
authored andcommitted
Allow SourceFiltering Disable to be set to false (#2496)
Fixes #2492
1 parent b8d5176 commit c98b2df

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/Nest/Search/Search/SourceFiltering/SourceFilterJsonConverter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
1919
writer.WriteValue(false);
2020
else
2121
{
22-
if (filter.Include == null && filter.Exclude == null)
23-
return;
24-
2522
writer.WriteStartObject();
2623
if (filter.Include != null)
2724
{

src/Tests/Search/Request/SourceFilteringUsageTests.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace Tests.Search.Request
1111
{
1212
/** Allows to control how the `_source` field is returned with every hit.
13-
* By default operations return the contents of the `_source` field unless
14-
* you have used the fields parameter or if the `_source` field is disabled.
13+
* By default, operations return the contents of the `_source` field unless
14+
* you have used the fields parameter, or if the `_source` field is disabled.
1515
*
1616
* See the Elasticsearch documentation on {ref_current}/search-request-source-filtering.html[Source Filtering] for more detail.
1717
*/
@@ -97,6 +97,34 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
9797
}
9898
}
9999

100+
//hide
101+
public class SourceFilteringEnabledUsageTests : SearchUsageTestBase
102+
{
103+
public SourceFilteringEnabledUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
104+
105+
protected override object ExpectJson =>
106+
new
107+
{
108+
_source = new {}
109+
};
110+
111+
protected override Func<SearchDescriptor<Project>, ISearchRequest> Fluent => s => s
112+
.Source();
113+
114+
protected override SearchRequest<Project> Initializer =>
115+
new SearchRequest<Project>
116+
{
117+
Source = new SourceFilter()
118+
};
119+
120+
protected override void ExpectResponse(ISearchResponse<Project> response)
121+
{
122+
response.ShouldBeValid();
123+
foreach (var hit in response.Hits)
124+
hit.Source.Should().NotBeNull();
125+
}
126+
}
127+
100128
//hide
101129
public class SourceFilteringSerializationTests : SerializationTestBase
102130
{

0 commit comments

Comments
 (0)