API client / Methods / Advanced
Required API Key: any key with the logs ACL
Method signature
$client->getLogs()

$client->getLogs([
  // All the following parameters are optional
  'offset' => integer offset,
  'length' => integer length,
  'type' => string type
])

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 the logs of the latest search and indexing operations.

Retrieve the logs of your last 1,000 API calls. This helps with real-time debugging of your application.

This method only returns the logs of the targeted cluster.

To ensure regular removal of older entries, you can’t access logs API call logs after the retention period has expired. The number of logs stored is governed by the retention period (seven days) and the API calls limit (1,000 per server).

This API method counts towards your operation quota but isn’t logged.

Examples

Read the Algolia CLI documentation for more information.

1
2
3
4
5
6
7
8
// Get last 10 log entries
$res = $client->getLogs();

// Get last 100 log entries
$res = $client->getLogs([
  'offset' => 0,
  'length' => 100
]);

Parameters

Parameter Description
offset
type: integer
default: 0
Optional

Specify the first entry to retrieve (with 0 being the most recent log entry). The offset can be, at most, the total number of logs stored (which can be lower than the maximum of 1,000).

length
type: integer
default: 10
Optional

Specify the maximum number of entries to retrieve starting at the offset. Maximum allowed value: 1,000.

type
type: string|enum
Optional

Type of logs to retrieve. Can be one of the following:

  • all: Retrieve all the logs.
  • query: Retrieve only the queries.
  • build: Retrieve only the build operations.
  • error: Retrieve only the errors.
requestOptions
type: key/value mapping
default: No request options
Optional

A mapping of requestOptions to send along with the request.

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
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
  "logs":[
      {
        "timestamp":"2017-12-29T18:15:57Z",
        "method":"POST",
        "answer_code":"200",
        "query_body":"\n{\n \"requests\": [\n  {\n   \"indexName\": \"best_buy\",\n   \"params\": \"query=&hitsPerPage=10&page=0&attributesToRetrieve=*&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&getRankingInfo=1&facets=%5B%22brand%22%2C%22categories%22%2C%22free_shipping%22%2C%22type%22%5D&tagFilters=\"\n  }\n ]\n}\n",
        "answer":"\n{\n \"results\": [\n  {\n   \"hits\": [\n    {\n     \"name\": \"Amazon - Fire TV Stick\",\n     \"description\": \"Amazon Fire TV Stick connects to your TV's HDMI port. Just grab and go to enjoy Netflix, Prime Instant Video, Hulu Plus, YouTube.com, music, and much more.\",\n     \"brand\": \"Amazon\",\n     \"categories\": [\n      \"TV & Home Theater\",\n      \"Streaming Media Players\"\n     ],\n     \"hierarchicalCategories\": {\n      \"lvl0\": \"TV & Home Theater\",\n      \"lvl1\": \"TV & Home Theater > Streaming Media Players\"\n     },\n     \"type\": \"Streaming media plyr\",\n     \"price\": 39.99,\n     \"price_range\": \"1 - 50\",\n     \"image\": \"https:\/\/cdn-demo.algolia.com\/bestbuy\/9999119_sb.jpg\",\n     \"url\": \"http:\/\/www.bestbuy.com\/site\/amazon-fire-tv-stick\/9999119.p?id=1219460752591&skuId=9999119&cmp=RMX&ky=1uWSHMdQqBeVJB9cXgEke60s5EjfS6M1W\",\n     \"free_shipping\": false,\n     \"popularity\": 9843,\n     \"rating\": 4,\n     \"objectID\": \"9999119\"\n",
        "url":"\/1\/indexes\/*\/queries?x-algolia-agent=Algolia%20for%20vanilla%20JavaScript%203.24.7%3BAlgolia%20Dashboard%201.0.0%3Breact-instantsearch%204.1.3%3BJS%20Helper%202.23.0&x-algolia-application-id=AJ0P3S7DWQ&x-algolia-api-key=ce11****************************",
        "ip":"84.14.205.82",
        "query_headers":"Host: c1-de-3.algolianet.com\nConnection: keep-alive\nContent-Length: 308\naccept: application\/json\nOrigin: https:\/\/www.algolia.com\nUser-Agent: Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/63.0.3239.84 Safari\/537.36\ncontent-type: application\/x-www-form-urlencoded\nReferer: https:\/\/www.algolia.com\/apps\/AJ0P3S7DWQ\/explorer\/browse\/best_buy\nAccept-Encoding: gzip, deflate, br\nAccept-Language: fr,en;q=0.9\n",
        "sha1":"44c168cea54d2deca9a4724559cf15eccf15cf3e",
        "nb_api_calls":"1",
        "processing_time_ms":"1",
        "query_nb_hits":"10500",
        "index":"demo_index",
        "inner_queries":[
            {
              "indexName":"best_buy",
              "queryID":313453231,
              "offset":0,
              "userToken":"user_1"
            }
        ]
      }
  ]
}

log object

Field Description
timestamp
string

Timestamp in ISO-8601 format.

method
string

Rest type of the method.

answer_code
string

HTTP response code.

query_body
string

Request body. It’s truncated after 1000 characters.

answer
string

Answer body. It’s truncated after 1000 characters.

url
string

Request URL.

ip
string

Client ip of the call.

query_headers
string

Request Headers (API Key is obfuscated).

sha1
string

SHA1 ID of entry.

nb_api_calls
string

Number of API calls.

processing_time_ms
string

Processing time for the query. This does not include network time.

query_nb_hits
string

Number of hits returned for the query.

exhaustive
boolean

Exhaustive flags used during the query.

index
string

Index name of the log.

inner_queries
object[]

Contains an object for each performed query with the indexName, queryID, offset, and userToken.

Did you find this page helpful?