🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API client / Methods / Indexing
Required API Key: any key with the search ACL
Method signature
$index->getObjects(array objectIds)
$index->getObjects(array objectIds, [
  // All the following parameters are optional
  'attributesToRetrieve' => array
  // Any other requestOptions
])

// get a single object
$index->getObject(string objectId)
$index->getObject(string objectId, [
  // All the following parameters are optional
  'attributesToRetrieve' => array
  // Any other requestOptions
])

// get multiple objects
$client->getMultipleObject(array multipleObjects)

We released a new version of the PHP API client in public beta. Read the beta documentation for more information.

We released a new version of the JavaScript API client in public beta. Read the beta documentation for more information.

We released a new version of the Java API client in public beta. Read the beta documentation for more information.

You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.

You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.

About this method

Get one or more objects using their object IDs.

There are three methods you can use to get records (objects) from your indices:

getObject
Get a single record from an index.
getObjects
Get multiple records from an index.
multipleGetObjects
Get multiple records from multiple indices within the same Algolia application.

To get all records from an index, use the browse method.

Records are returned in the order in which they were requested.

Examples

Read the Algolia CLI documentation for more information.

Return a list of objects by their IDs

1
$index->getObjects(['myId1', 'myId2']);

Return a list of objects with a subset of their attributes

1
2
3
$index->getObjects(['myId1', 'myId2'], [
  'attributesToRetrieve' => ['firstname', 'lastname']
]);

If an object ID isn’t found in your index, the result is null for that object ID.

Return a single object by its ID

1
2
3
4
5
6
7
// Retrieves all attributes
$index->getObject('myId');

// Retrieves only firstname and lastname attributes
$index->getObject('myId', [
  'attributeToRetrieve' => ['firstname', 'lastname'],
]);

If the object ID doesn’t exist in your index, this method returns an error.

Return objects from multiple indices

1
2
3
4
5
6
7
8
9
10
$client->multipleGetObjects(array(
  [
    "indexName" => "index1",
    "objectID" => "myId1"
  ], 
  [
    "indexName" => "index2",
    "objectID" => "myId2"
  ]
));

Return a list of objects and send extra HTTP headers

1
2
3
4
5
$objectIDs = [/* objectIDs */];

$index->getObjects($objectIDs, [
  'X-Forwarded-For' => '94.228.178.246'
];

Parameters

Parameter Description
objectIDs
type: list
Required

List of objectIDs to retrieve.

attributesToRetrieve
type: string | array
Optional

Comma-separated list of attributes to include with each record.

By default, all retrievable attributes are returned.

requestOptions
type: key-value pairs
default: ""
Optional

requestOptions to add to the request.

You can’t use search parameters with getObjects.

objectID
type: integer|string
Required

Object ID for the record you want to get.

multipleObjects
type: list of multipleObject
true (for multipleGetObjects)

A list of key-value pairs that represent specific objects in specific indices.

multipleObjects ➔ multipleObject

Each multipleObject parameter must have two attributes:

  • indexName. The index in which to search (as a string).
  • objectId. The object ID of the record to retrieve (as a string).

Check the example Return objects from multiple indices for reference.

Parameter Description

Response

This section shows the JSON response returned by the API. Each API client encapsulates this response inside objects specific to the programming language, so that the actual response might be different. You can view the response by using the getLogs method. Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.

JSON format

1
2
3
4
5
6
7
8
{
  "results": [
    {
      "objectID": "1182729442",
      "name": "product 1"
    }
  ]
}

The following example tries to get two objects. The first object ID doesn’t exist: null is returned. The seocnd object ID exists and the object is returned.

1
2
3
4
5
6
7
8
9
10
{
  "results": [
    null,
    {
      "objectID": "1182729442",
      "name": "product 1"
    }
  ],
  "message": "ObjectID 1182729441 does not exist."
}
Field Description
results
list

List of the retrieved objects.

Did you find this page helpful?