attributesToRetrieve
*
(all attributes)
'attributesToRetrieve' => [ 'attribute1', // list of attributes to retrieve 'attribute2' ] 'attributesToRetrieve' => [ '*' // retrieves all attributes ] 'attributesToRetrieve' => [ '*', // retrieves all attributes '-attribute1', // except this list of attributes (starting with a '-') '-attribute2' ]
Can be used in these methods:
search,
setSettings,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
set_settings,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
setSettings,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
set_settings,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
setSettings,
browse,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
setSettings,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
searchAsync,
setSettingsAsync,
browseAsync,
searchForFacetValues
Search,
SetSettings,
Browse,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
setSettings,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
SetSettings,
BrowseObjects,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
setSettings,
browse index,
search into facet values,
generateSecuredApiKey,
add key,
update key
About this parameter
Gives control over which attributes to retrieve and which not to retrieve.
You don’t always need to retrieve a full response that includes every attribute in your index. Sometimes you may only want to receive the most relevant attributes, or exclude attributes used only for internal purposes.
This setting helps reduce your response size and improve performance.
Usage notes:
- Special Characters:
-
Use
*
to retrieve all values. -
Append a dash (
-
) to an attribute that you do NOT wish to retrieve. Example below. Without prefixing an attribute with-
, the attribute will be retrieved. -
Note that negative attributes (
-
) only work when using*
. For example, [“*”, “-title”] retrieves every attribute except “title”.
-
-
objectID
is always retrieved, even when not specified. -
Also note that using negative attributes doesn’t make them unsearchable. If your users make queries that match an attribute not to retrieve, they will still get the same results, but the attribute won’t be part of the response.
- Attributes listed in
unretrievableAttributes
will not be retrieved even if requested, unless the request is authenticated with the admin API key.
Examples
Set default list of retrievable attributes
1
2
3
4
5
6
7
$index->setSettings([
'attributesToRetrieve' => [
'author',
'title',
'content'
]
]);
Make all attributes as retrievable by default
1
2
3
4
5
$index->setSettings([
'attributesToRetrieve' => [
"*"
]
]);
Override default list of retrievable attributes for the current search
1
2
3
4
5
6
$results = $index->search('query', [
'attributesToRetrieve' => [
'title',
'content'
]
]);
Specify some attributes not to retrieve
Here, you retrieve all attributes of an item except for its SKU and internal description.
1
2
3
4
5
6
7
$index->setSettings([
'attributesToRetrieve' => [
'*',
'-SKU',
'-internal_desc'
]
]);