attributesToRetrieve

Type: list of strings
Engine default: * (all attributes)
Formerly: attributes
Parameter syntax
'attributesToRetrieve' => [
  'attribute1', // list of attributes to retrieve
  'attribute2'
]
'attributesToRetrieve' => [
  '*' // retrieves all attributes
]
'attributesToRetrieve' => [
  '*', // retrieves all attributes
  '-attribute', // except this list of attributes (starting with a '-')
  '-attribute2'
]
Parameter syntax
attributesToRetrieve: [
  'attribute1', // list of attributes to retrieve
  'attribute2'
]
attributesToRetrieve: [
  '*' // retrieves all attributes
]
attributesToRetrieve: [
  '*', // retrieves all attributes
  '-attribute', // except this list of attributes (starting with a '-')
  '-attribute2'
]
Parameter syntax
attributesToRetrieve: [
  'attribute1', // list of attributes to retrieve
  'attribute2'
]
attributesToRetrieve: [
  '*' // retrieves all attributes
]
attributesToRetrieve: [
  '*', // retrieves all attributes
  '-attribute', // except this list of attributes (starting with a '-')
  '-attribute2'
]
Parameter syntax
'attributesToRetrieve': [
  'attribute1', // list of attributes to retrieve
  'attribute2'
]
'attributesToRetrieve': [
  '*' // retrieves all attributes
]
'attributesToRetrieve': [
  '*', // retrieves all attributes
  '-attribute', // except this list of attributes (starting with a '-')
  '-attribute2'
]
Parameter syntax
index.setSettings([
  "attributesToRetrieve": [
    "attribute1", // list of attributes to retrieve
    "attribute2"
  ]
])
index.setSettings([
  "attributesToRetrieve": [
    "*" // retrieves all attributes
  ]
])
index.setSettings([
  "attributesToRetrieve": [
    "*", // retrieves all attributes
    "-attribute", // except this list of attributes (starting with a "-")
    "-attribute2"
  ]
])
Parameter syntax
new JSONObject()
  .put(
    "attributesToRetrieve",
      .put("attribute1") // list of attributes to retrieve
      .put("attribute2")
    new JSONArray()
  )
);
new JSONObject()
  .put(
    "attributesToRetrieve",
    new JSONArray()
      .put("*") // retrieves all attributes
  )
);
new JSONObject()
  .put(
    "attributesToRetrieve",
    new JSONArray()
      .put("*") // retrieves all attributes
      .put("-attribute1") // except this list of attributes (starting with a "-")
      .put("-attribute2")
  )
);
Parameter syntax
dynamic settings = new JObject();
settings.attributesToRetrieve = new JArray(new string[] {
  "attribute1", // list of attributes to retrieve
  "attribute2"
});
settings.attributesToRetrieve = new JArray(new string[] {
  "*" // retrieves all attributes
});
settings.attributesToRetrieve = new JArray(new string[] {
  "*", // retrieves all attributes
  "-attribute", // except this list of attributes (starting with a "-")
  "-attribute2"
});
Parameter syntax
new IndexSettings().setAttributesToRetrieve(Arrays.asList(
  "attribute1", // list of attributes to retrieve
  "attribute2"
))
new IndexSettings().setAttributesToRetrieve(Arrays.asList(
  "*" // retrieves all attributes
))
new IndexSettings().setAttributesToRetrieve(Arrays.asList(
  "*", // retrieves all attributes
  "-attribute", // except this list of attributes (starting with a "-")
  "-attribute2"
))
Parameter syntax
"attributesToRetrieve": []string{
  "attribute1", // list of attributes to retrieve
  "attribute2",
},
"attributesToRetrieve": []string{
  "*", // retrieves all attributes
},
"attributesToRetrieve": []string{
  "*", // retrieves all attributes
  "-attribute", // except this list of attributes (starting with a "-")
  "-attribute2",
},
Parameter syntax
attributesToRetrieve = Some(Seq(
  "attribute1", // list of attributes to retrieve
  "attribute2"
))
attributesToRetrieve = Some(Seq(
  "*" // retrieves all attributes
))
attributesToRetrieve = Some(Seq(
  "*", // retrieves all attributes
  "-attribute", // except this list of attributes (starting with a "-")
  "-attribute2"
))

Can be used in these methods:
search, setSettings, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, set_settings, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, setSettings, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, set_settings, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, setSettings, browse, searchForFacetValues searchAsync, setSettingsAsync, browseAsync, searchForFacetValues Search, SetSettings, Browse, SearchForFacetValues, GenerateSecuredApiKey, AddApiKey, UpdateApiKey Search, setSettings, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey Search, SetSettings, Browse, SearchForFacetValues, GenerateSecuredAPIKey, AddAPIKey, UpdateAPIKey search, changeSettings, 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

<?php
$index->setSettings([
  'attributesToRetrieve' => [
    'author',
    'title',
    'content'
  ]
]);
index.set_settings({
  attributesToRetrieve: [
    'author',
    'title',
    'content'
  ]
})
index.setSettings({
  attributesToRetrieve: [
    'author',
    'title',
    'content'
  ]
});
index.set_settings({
  'attributesToRetrieve': [
    'author',
    'title',
    'content'
  ]
})
index.setSettings([
  "attributesToRetrieve": [
    "author",
    "title",
    "content"
  ]
])
index.setSettings(new JSONObject().put("attributesToRetrieve",
  new JSONArray().put("author").put("title").put("content")));
index.SetSettings(
  JObject.Parse(@"{""attributesToRetrieve"":[""author"",""title"",""content""]}")
);
index.setSettings(
  new IndexSettings().setAttributesToRetrieve(Arrays.asList(
    "author",
    "title",
    "content"
  ))
);
res, err := index.SetSettings(algoliasearch.Map{
  "attributesToRetrieve": []string{
    "author",
    "title",
    "content",
  },
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    attributesToRetrieve = Some(Seq(
      "author",
      "title",
      "content"
    ))
  )
}

Make all attributes as retrievable by default

<?php
$index->setSettings([
  'attributesToRetrieve' => [
    "*"
  ]
]);
index.set_settings({
  attributesToRetrieve: [
    '*'
  ]
})
index.setSettings({
  attributesToRetrieve: [
    '*'
  ]
});
index.set_settings({
  'attributesToRetrieve': [
    '*'
  ]
})
index.setSettings([
  "attributesToRetrieve": [
    "*"
  ]
])
index.setSettings(new JSONObject().put("attributesToRetrieve",
  new JSONArray().put("*")));
index.SetSettings(
  JObject.Parse(@"{""attributesToRetrieve"":["*"]}")
);
index.setSettings(
  new IndexSettings().setAttributesToRetrieve(Arrays.asList(
    "*"
  ))
);
res, err := index.SetSettings(algoliasearch.Map{
  "attributesToRetrieve": []string{
    "*",
  },
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    replaceSynonymsInHighlight = Some(false)
  )
}
<?php
$results = $index->search('query', [
  'attributesToRetrieve' => [
    'title',
    'content'
  ]
]);
results = index.search('query', {
  attributesToRetrieve: [
    'title',
    'content'
  ]
})
index.search({
  query: 'query',
  attributesToRetrieve: [
    "title",
    "content"
  ]
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
  'attributesToRetrieve': [
    'title',
    'content'
  ]
})
let query = Query(query: "query")
query.attributesToRetrieve = [
  "title",
  "content"
]

index.search(query, completionHandler: { (res, error) in
  print(res)
})
index.search(new Query("query").setAttributesToRetrieve("title", "content"));
index.SetSettings(
  JObject.Parse(@"{""attributesToRetrieve"":[""title"",""content""]}")
);
index.search(
  new Query("query").setAttributesToRetrieve(Arrays.asList(
    "title",
    "content"
  ))
);
res, err := index.Search("query", algoliasearch.Map{
  "attributesToRetrieve": []string{
    "title",
    "content",
  },
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    attributesToRetrieve = Some(Seq(
      "title",
      "content"
    ))
  )
}

Specify some attributes not to retrieve

Here, you retrieve all attributes of an item except for its SKU and internal description.

<?php
$index->setSettings([
  'attributesToRetrieve' => [
    '*',
    '-SKU',
    '-internal_desc'
  ]
]);
index.set_settings({
  attributesToRetrieve: [
    '*',
    '-SKU',
    '-internal_desc'
  ]
})
index.setSettings({
  attributesToRetrieve: [
    '*',
    '-SKU',
    '-internal_desc'
  ]
});
index.set_settings({
  'attributesToRetrieve': [
    '*',
    '-SKU',
    '-internal_desc'
  ]
})
index.setSettings([
  "attributesToRetrieve": [
    "*",
    "-SKU",
    "-internal_desc"
  ]
])
index.setSettings(new JSONObject().put("attributesToRetrieve",
  new JSONArray().put("*").put("-SKU").put("-internal_desc")));
index.SetSettings(
  JObject.Parse(@"{""attributesToRetrieve"":[""*"",""-SKU"",""-internal_desc""]}")
);
index.setSettings(
  new IndexSettings().setAttributesToRetrieve(Arrays.asList(
    "*",
    "-SKU",
    "-internal_desc"
  ))
);
res, err := index.SetSettings(algoliasearch.Map{
  "attributesToRetrieve": []string{
    "*",
    "-SKU",
    "-internal_desc",
  },
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    attributesToRetrieve = Some(Seq(
      "*",
      "-SKU",
      "-internal_desc"
    ))
  )
}
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala