Fields Usage

edit

Allows to selectively load specific stored fields for each document represented by a search hit.

The fields parameter is about fields that are explicitly marked as stored in the mapping, which is off by default and generally not recommended. Use source filtering instead to select subsets of the original source document to be returned.

See the Elasticsearch documentation on Fields for more detail.

Fluent DSL example

edit
s => s
.StoredFields(fs => fs
    .Field(p => p.Name)
    .Field(p => p.StartedOn)
    .Field(p => p.NumberOfCommits)
    .Field(p => p.DateString)
)

Object Initializer syntax example

edit
new SearchRequest<Project>
{
    StoredFields = Fields<Project>(
        p => p.Name,
        p => p.StartedOn,
        p => p.NumberOfCommits,
        p => p.DateString)
}

Example json output.

{
  "stored_fields": [
    "name",
    "startedOn",
    "numberOfCommits",
    "dateString"
  ]
}