Fields Usageedit

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 exampleedit

s => s
.Query(q => ProjectFilter)
.StoredFields(fs => fs
    .Field(p => p.Name)
    .Field(p => p.StartedOn)
    .Field(p => p.NumberOfCommits)
    .Field(p => p.NumberOfContributors)
    .Field(p => p.DateString)
)

Object Initializer syntax exampleedit

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

Example json output.

{
  "query": {
    "term": {
      "type": {
        "value": "project"
      }
    }
  },
  "stored_fields": [
    "name",
    "startedOn",
    "numberOfCommits",
    "numberOfContributors",
    "dateString"
  ]
}