Source Filtering Usage

edit

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.

Fluent DSL example

edit
s => s
.Source(src => src
    .IncludeAll()
    .Exclude(e => e
        .Fields(
            p => p.Description
        )
    )
)

Object Initializer syntax example

edit
new SearchRequest<Project>
{
    Source = new SourceFilter
    {
        Include = "*",
        Exclude = Fields<Project>(p => p.Description)
    }
}

Example json output.

{
  "_source": {
    "include": [
      "*"
    ],
    "exclude": [
      "description"
    ]
  }
}

Handling Responses

edit
response.ShouldBeValid();

foreach (var document in response.Documents)
{
    document.Name.Should().NotBeNull();
    document.StartedOn.Should().NotBe(default(DateTime));
    document.Description.Should().BeNull();
}

Disable Source Retrieval

edit

Source filtering can be disabled by setting disable to true.

Fluent DSL example

edit
s => s
.Source(src => src.Disable())

Object Initializer syntax example

edit
new SearchRequest<Project>
{
    Source = new SourceFilter
    {
        Disable = true
    }
}

Example json output.

{
  "_source": false
}

Handling Responses

edit
response.ShouldBeValid();
foreach (var hit in response.Hits)
    hit.Source.Should().BeNull();