client.execute { get from "index" objectIds Seq("myId2", "myId2")}
struct Contact: Codable { let objectID: ObjectID let firstname: String let lastname: String}index.getObjects(withIDs: ["myId1", "myId2"]) { (result: Result<ObjectsResponse<Contact>, Error>) in if case .success(let response) = result { print("Response: \(response)") }}
Return a list of records with a subset of their attributes
res = index.get_objects(['myId', 'myId2'], { attributesToRetrieve: ['firstname', 'lastname'] })
client.execute { get from "index" objectIds Seq( "myId2", "myId2" ) attributesToRetrieve Seq("firstname")}
struct Contact: Codable { let firstname: String}index.getObjects(withIDs: ["myId1", "myId2"], attributesToRetrieve: ["firstname"]) { (result: Result<ObjectsResponse<Contact>, Error>) in if case .success(let response) = result { print("Response: \(response)") }}
If an object ID isn’t found in your index,
the result is null for that object ID.
Return a single record by its ID
// Retrieves all attributesContact res = index.GetObject<Contact>("myId");// AsynchronousContact res = await index.GetObjectAsync<Contact>("myId");// Retrieves firstname and lastname attributesContact res = index.GetObject<Contact>("myId", attributesToRetrieve: new List<string> { "firstname", "lastname" });// AsynchronousContact res = await index.GetObjectAsync<Contact>("myId", attributesToRetrieve: new List<string> { "firstname", "lastname" });// Retrieves only the firstname attributeContact res = index.GetObject<Contact>("myId", attributesToRetrieve: new List<string> { "firstname" });// AsynchronousContact res = await index.GetObjectAsync<Contact>("myId", attributesToRetrieve: new List<string> { "firstname" });
// Retrieves the object with all its attributeserr := index.GetObject("myId", &object)// Retrieves the object with only its `firstname` attributeerr := index.GetObject("myId", &object, opt.AttributesToRetrieve("firstname"))// Retrieves the object with only its `firstname` and `lastname` attributeserr := index.GetObject("myId", &object, opt.AttributesToRetrieve("firstname", "lastname"))
// Retrieves all attributesindex.getObject('myId').then(object => { console.log(object);});// Retrieves only firstname and lastname attributesindex.getObject('myId', { attributesToRetrieve: ['firstname', 'lastname']}).then(object => { console.log(object);});
index.getObject(ObjectID("myID1"))@Serializabledata class Contact( val firstname: String, val lastname: String, override val objectID: ObjectID) : Indexableval objectID = ObjectID("myID1")index.getObject(objectID)index.getObject(Contact.serializer(), objectID)
// Retrieves all attributes$index->getObject('myId');// Retrieves only firstname and lastname attributes$index->getObject('myId', [ 'attributeToRetrieve' => ['firstname', 'lastname'],]);
# Retrieves all attributesindex.get_object('myId')# Retrieves firstname and lastname attributesindex.get_object('myId', { 'attributesToRetrieve': ['firstname, lastname']})# Retrieves only the firstname attributeindex.get_object('myId', { 'attributesToRetrieve': ['firstname']})
# Retrieves all attributesindex.get_object('myId')# Retrieves firstname and lastname attributesres = index.get_object('myId', { attributesToRetrieve: ['firstname', 'lastname'] })# Retrieves only the firstname attributeres = index.get_object('myId', { attributesToRetrieve: ['firstname'] })
// Retrieves all attributesclient.execute { get from "index" objectId "myId"}// Retrieves firstname and lastname attributesclient.execute { get from "index" objectId "myId" attributesToRetrieve Seq("firstname", "lastname")}// Retrieves only the firstname attributeclient.execute { get from "index" objectId "myId" attributesToRetrieve Seq("firstname")}
struct Contact: Codable { let firstname: String let lastname: String?}// Retrieve all attributes.index.getObject(withID: "myId") { (result: Result<Contact, Error>) in if case .success(let response) = result { print("Response: \(response)") }}// Retrieves `firstname` and `lastname` attributes.index.getObject(withID: "myId", attributesToRetrieve: ["firstname", "lastname"]) { (result: Result<Contact, Error>) in if case .success(let response) = result { print("Response: \(response)") }}// Retrieve only the `firstname` attribute.index.getObject(withID: "myId", attributesToRetrieve: ["firstname"]) { (result: Result<Contact, Error>) in if case .success(let response) = result { print("Response: \(response)") }}
If the object ID doesn’t exist in your index,
this method returns an error.
Return records from multiple indices
var objectsToRetrieve = new List<MultipleGetObject>{ new MultipleGetObject { IndexName = "index1", ObjectID = "myId1" }, new MultipleGetObject { IndexName = "index2", ObjectID = "myId2" }};IEnumerable<Object> objects = client.MultipleGetObjects<Object>(objectsToRetrieve);// AsynchronousIEnumerable<Object> objects = await client.MultipleGetObjectsAsync<Object>(objectsToRetrieve);
let requests: [ObjectRequest] = [ .init(indexName: "index1", objectID: "myId1"), .init(indexName: "index2", objectID: "myId2"),]client.multipleGetObjects(requests: requests) { result in if case .success(let response) = result { print("Response: \(response)") }}
Return a list of records and send extra HTTP headers
res = index.get_objects(['myId1', 'myId2'], { headers: { 'X-Algolia-User-ID': 'user123' }})
client.execute { get from "index" objectIds Seq( "myId1", "myId2" ) options RequestOptions( extraHeaders = Some(Map("X-Algolia-User-ID" => "user123")) )}
var requestOptions = RequestOptions()requestOptions.headers["X-Algolia-User-ID"] = "user123"struct Contact: Codable { let objectID: ObjectID let firstname: String let lastname: String}index.getObjects(withIDs: ["myId1", "myId2"], requestOptions: requestOptions) { (result: Result<ObjectsResponse<Contact>, Error>) in if case .success(let response) = result { print("Response: \(response)") }}
Parameters
object[]
required
A list of key-value pairs that represent specific records in specific indices.
(Required for multipleGetObjects).
Show child attributes
string
required
Index in which to search.
string
required
Object ID of the record to retrieve.
string
required
Object ID for the record you want to get.
(Required for getObject)
string[]
required
List of objectIDs to retrieve.
(Required for getObjects).
string | string[]
Comma-separated list of attributes to include with each record.By default, all retrievable attributes are returned.
This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the getLogs method.
Don’t rely on the order of properties—JSON objects don’t preserve key order.