$fields public property
The fields being retrieved from the documents. For example, ['id', 'name']
. If not set, this option will not be applied to the query and no fields will be returned. In this case the _source
field will be returned by default which can be configured using source(). Setting this to an empty array will result in no fields being retrieved, which means that only the primaryKey of a record will be available in the result.
For each field you may also add an array representing a script field. Example:
$query->fields = [ 'id', 'name', 'value_times_two' => [ 'script' => "doc['my_field_name'].value * 2", ], 'value_times_factor' => [ 'script' => "doc['my_field_name'].value * factor", 'params' => [ 'factor' => 2.0 ], ], ]
Note: Field values are always returned as arrays even if they only have one value.
See also:
Please login to continue.