API Reference / API Methods / Manage indices / Browse index
Required API Key: any key with the browse ACL
Method signature
$index->browseObjects()

$index->browseObjects([
  // All the following parameters are optional
  'query' => string,
  // + any browseParameters
  // + any requestOptions
])

About this method # A

Get all index content without any record limit. Can be used for backups.

The browse method is an alternative to the Search index method. If you need to retrieve the full content of your index (for backup, SEO purposes or for running a script on it), you should use this method instead.

Results are ranked by attributes and custom ranking.

But for performance reasons, there is no ranking based on:

  • distinct
  • typo-tolerance
  • number of matched words
  • proximity
  • geo distance

The analytics API doesn’t collect data when using browse.

You shouldn’t use this method for building a search UI. Instead, use search along with the paginationLimitedTo setting to retrieve more than 1,000 results.

If you want to reduce the payload size of the browse response and don’t need all attributes in your records, you can use attributesToRetrieve to declare which attributes to retrieve.

Examples # A

Browse an index (recommended way)#

This example shows how to iterate over the whole index:

1
2
3
4
5
6
// Empty query will match all records
$iterator = $index->browseObjects(['query' => '', 'filters' => 'i<42']);

foreach ($iterator as $hit) {
  var_dump($hit);
}

Retrieve only certain attributes when browsing#

This example shows how to iterate over the whole index and only retrieve certain attributes:

1
2
3
4
5
6
// Empty query will match all records
$iterator = $index->browseObjects(['query' => '', 'attributesToRetrieve' => [ 'title', 'content' ]]);

foreach ($iterator as $hit) {
  var_dump($hit);
}

Browse an index and send extra HTTP headers#

1
2
3
4
5
6
7
8
9
10
11
$searchParameters = [];

$iterator = $index->browseObjects([
  'query' => '', // Empty query will match all records
  'filters' => 'i<42',
  'X-Forwarded-For' => '94.228.178.246'
]);

foreach ($iterator as $hit) {
  var_dump($hit);
}

Parameters # A

query #
type: string
Required

Query to search. Accepts every character and every character entered will be used in the search.

Empty query can be used to fetch all records.

browseParameters #
type: key/value mapping
default: No browse parameters
Optional

Browse compatible search parameters.

Can contain any of the search parameters. Some useful ones for browse include:

There are certain search parameters the engine overrides:

requestOptions #
type: key/value mapping
default: No request options
Optional

A mapping of requestOptions to send along with the query.

Response # A

This section shows the JSON response returned by the API. Since each language encapsulates this response inside objects specific to that language and/or implementation, the actual type in your language might differ from what’s written here. You can view the response in the logs (using the getLogs method).

JSON format#

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "hits": [
    {
      "firstname": "Jimmie",
      "lastname": "Barninger",
      "objectID": "433"
    }
  ],
  "processingTimeMS": 7,
  "query": "",
  "params": "filters=level%3D20",
  "cursor": "ARJmaWx0ZXJzPWxldmVsJTNEMjABARoGODA4OTIzvwgAgICAgICAgICAAQ=="
}
hits #
list

Retrieved records.

cursor #
string

A cursor to retrieve the next chunk of data. Used with browseFrom. If absent, it means that the end of the index has been reached.

params #
string

URL-encoded search parameters used to filter the results.

query #
string

Query text used to filter the results.

processingTimeMS #
integer

Time that the server took to process the request, in milliseconds. This does not include network time.

nbHits #
integer

Number of objects in the index. Present only when the query is empty and the browse is not filtered.

page #
integer

Index of the current page (zero-based). Present only when the query is empty and the browse is not filtered.

hitsPerPage #
integer

The maximum number of hits returned per page. Present only when the query is empty and the browse is not filtered.

nbPages #
integer

The number of returned pages. Calculation is based on total number of hits (nbHits) divided by the number of hits per page (hitsPerPage), rounded to the nearest highest integer.

Present only when the query is empty and the browse is not filtered.

Did you find this page helpful?
PHP v3