Allows to control how the _source
field is returned with every hit.
By default operations return the contents of the _source
field unless
you have used the fields parameter or if the _source
field is disabled.
See the Elasticsearch documentation on Source Filtering for more detail.
s => s
.Query(q => ProjectFilter)
.Source(src => src
.IncludeAll()
.Excludes(e => e
.Fields(
p => p.Description
)
)
)
new SearchRequest<Project>
{
Query = ProjectFilter,
Source = new SourceFilter
{
Includes = "*",
Excludes = new Field[] { "Description" }
}
}
Example json output
{
"query": {
"term": {
"type": {
"value": "project"
}
}
},
"_source": {
"includes": [
"*"
],
"excludes": [
"description"
]
}
}
response.ShouldBeValid();
foreach (var document in response.Documents)
{
document.Name.Should().NotBeNull();
document.StartedOn.Should().NotBe(default(DateTime));
document.Description.Should().BeNull();
}
s => s.Source(false)
new SearchRequest<Project>
{
Source = false
}
Example json output
{
"_source": false
}
response.ShouldBeValid();
foreach (var hit in response.Hits)
hit.Source.Should().BeNull();