Guides / Building Search UI / UI & UX patterns / Query Suggestions

Troubleshooting Query Suggestions with Logs

Sometimes, you may find that a suggestion you expect to be in your Query Suggestions index is missing. If this occurs, the logs endpoint in the Query Suggestions REST API can help you understand why.

You can retrieve the log file for the last build of any Query Suggestions index using the logs endpoint. When the request is successful, the HTTP response is a 200 OK and returns the most recent log file in JSON Lines format. Depending on the amount of source data considered for suggestions, the logs can be quite large. It may be easiest to dump the response into a file for further inspection.

1
2
3
4
5
6
curl -X GET \
     -o "path/to/logs.jsonl" \
     -H "X-Algolia-API-Key: ${YourAdminAPIKey}" \
     -H "X-Algolia-Application-Id: ${YourApplicationID}" \
     --compressed \
    "https://query-suggestions.us.algolia.com/1/logs/${query_suggestions_index_name}"

You must use the admin API key to access Query Suggestions build logs.

Log schema

Each line in the log file is a single log and has the following attributes:

  • timestamp - date and time of logged action.
  • level - type of log, can be one of three values: INFO, SKIP, or ERROR.
  • message - detailed description of what happened.
  • contextLevel - the hierarchy of the logs. For example, a log with contextLevel=1 belongs to a preceding log with contextLevel=0.

Sample log file

Logs include information about the generation process as a whole, including:

  • what source index(es) the Query Suggestions builder used, including external analytics sources
  • number of top searches found in the source index’s analytics
  • number of suggestion candidates from facet data
  • how many read and write operations the Query Suggestions builder made to generate the suggestions

See below for examples of these types of logs:

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
[
  {
    "timestamp": "2020-11-03T04:10:59.200274859Z",
    "level": "INFO",
    "message": "done loading analytics data in 2.995576317s",
    "contextLevel": 0
  },
  {
    "timestamp": "2020-11-03T04:11:00.525440213Z",
    "level": "INFO",
    "message": "about to process source index \"instant_search\"",
    "contextLevel": 0
  },
  {
    "timestamp": "2020-11-03T04:11:02.801832802Z",
    "level": "INFO",
    "message": "found 515 popular searches",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:20.95248061Z",
    "level": "INFO",
    "message": "0 potential candidates for generation from facets",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:20.952486251Z",
    "level": "INFO",
    "message": "about to import external indices",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:20.952491864Z",
    "level": "INFO",
    "message": "done to processing source index \"instant_search\"",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:29.967979293Z",
    "level": "INFO",
    "message": "done generating suggestion index \"query_suggestions\" in 29.44254095s",
    "contextLevel": 0
  },
  {
    "timestamp": "2020-11-03T04:11:29.968089323Z",
    "level": "INFO",
    "message": "1,023.00 reads and 313.00 writes made to the searchAPI",
    "contextLevel": 0
  }
]

Skipped suggestions

In addition to general information about the generation process, logs include why particular candidate suggestions were “skipped,” and not included in the suggestions index. This often has to do with configuration options, such as the minimum number of results a suggestion must retrieve or the minimum number of letters a suggestion must have. If you find that a desired suggestion was skipped for one of these reasons, you can change your configuration accordingly.

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
28
29
30
31
32
[
  {
    "timestamp": "2020-11-03T04:11:02.801865892Z",
    "level": "SKIP",
    "message": "skipping query \"\": the query is empty",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:02.852462339Z",
    "level": "INFO",
    "message": "skipping query \"a\": not enough letters",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:03.488965905Z",
    "level": "SKIP",
    "message": "query \"apple airport\" does not meet the min hits criteria of 5, got 4 hits",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:03.488965905Z",
    "level": "SKIP",
    "message": "skipping query \"query\": not enough search results with prefixNone index, got 0, expected 5",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:03.488965905Z",
    "level": "SKIP",
    "message": "skipping query \"3-year\": excluded because containing a special char",
    "contextLevel": 1
  }
]

Normalization

To avoid redundant suggestions, the Query Suggestions builder normalizes and completes suggestions based on the configured language. In the example below, you can see the builder doesn’t always use the singular or plural; instead, it only keeps the most popular declined form.

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
28
29
30
31
32
[
  {
    "timestamp": "2020-11-03T04:11:02.852462339Z",
    "level": "INFO",
    "message": "normalized \"clou\" to \"cloud\"",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:20.952497284Z",
    "level": "INFO",
    "message": "about to normalize plurals",
    "contextLevel": 0
  },
  {
    "timestamp": "2020-11-03T04:11:23.37891251Z",
    "level": "INFO",
    "message": "merged \"batteries\" into \"battery\"",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:25.860366236Z",
    "level": "INFO",
    "message": "merged \"cell phone\" into \"cell phones\"",
    "contextLevel": 1
  },
  {
    "timestamp": "2020-11-03T04:11:26.614469772Z",
    "level": "INFO",
    "message": "done normalizing plurals",
    "contextLevel": 1
  }
]

Errors

When the request isn’t successful, the HTTP response could be a 404 if no Query Suggestions index exists with the given name or if the index hasn’t finished its initial build. If you use incorrect credentials or use a non-admin API key, the API returns a 403 HTTP response.

If the request is successful, you may see some logs with level=ERROR for the reasons listed below.

During index generation

  • one of the source indices doesn’t exist
  • can’t process source index
  • can’t normalize plurals
  • can’t select display forms
  • can’t create new suggestions index
  • unable to add external searches to suggestions index
  • search or indexing operations quotas exceeded
  • can’t finish generating index
  • can’t get popular searches
  • can’t add popular searches to suggestions index

When using external analytics:

  • can’t browse external index, it doesn’t exist
  • can’t get popular searches from records in external index; this is often due to incorrectly formatted data

When generating searches from facet data:

  • can’t generate searches
  • unable to add generated searches to suggestions index

If you receive one of these errors and don’t understand the reason behind it, please reach out to your success team or the support team.

Did you find this page helpful?