Get query suggestions
Get query suggestions
You can request basic query expression (q) completions from a Coveo Machine Learning (Coveo ML) query suggestions model by sending a GET or POST HTTP request to https://platform.cloud.coveo.com/rest/search/v2/querySuggest.
The Search API query suggestion route supports several parameters which you can include either in the query string of a GET request, or in the JSON body of a POST request (see QS parameters).
|
|
Note
When using an OAuth2 token to authenticate a GET or POST HTTP request to the Search API query suggestion route, you must specify the unique identifier of the target organization by including the |
Query suggestion examples
-
Requesting query suggestions using the GET method:
GET https://platform.cloud.coveo.com/rest/search/v2/querySuggest?locale=en&q=twa&searchHub=BookstoreSearch HTTP/1.1 Accept: application/json Authorization: Bearer **********-****-****-****-************ -
Requesting query suggestions using the POST method:
POST https://platform.cloud.coveo.com/rest/search/v2/querySuggest HTTP/1.1 Content-Type: application/json Accept: application/json Authorization: Bearer **********-****-****-****-************Payload
{ "locale": "en", "q": "twa", "searchHub": "BookstoreSearch" }200 OK response body (excerpt)
{ "completions": [ { "executableConfidence": 1, "expression": "mark twain", "highlighted": "[mark] {twa}[in]", "score": 14.525258530973204 }, { "executableConfidence": 0.6666666666666666, "expression": "[wes]{twa}[rd] [ho]", "highlighted": "", "score": 8.50548085208594 }, { "executableConfidence": 0.5, "expression": "hot water music", "highlighted": "[hot] (wat)[er] [music]", "score": 7.107770631785241 }, ... ] }
|
|
Notes
|
Troubleshooting
If your QS model isn’t behaving as expected, this may be due to a mismatch between the searchHub value used in your Search API requests and the originLevel1 value used when logging events for the target search interface through the Usage Analytics Write API.
It’s important that these values match in any given search interface, since the Coveo ML service uses them as filter fields.
|
|
Note
The same relationship exists between the |
Troubleshooting example
You have one search interface for books and another for movies.
On the Coveo Analytics side, when logging events in these search interfaces, the originlevel1 values specified in your requests are, respectively, BookstoreSearch and MovieStoreSearch.
On the Search API side, this translates into distinctive behavior from one searchHub to another.
-
You make the following request:
POST https://platform.cloud.coveo.com/rest/search/v2/querySuggest HTTP/1.1 Content-Type: application/json Accept: application/json Authorization: Bearer **********-****-****-****-************Payload
{ "q": "Dost", "searchHub": "BookstoreSearch" }The Search API returns the following completions, where the
Dostoevskysuggestion is executable and highly recommended:{ "completions": [ { "executableConfidence": 1, "expression": "Dostoevsky", "highlighted": "{Dost}[oevsky]", "score": 56.135864235791246 }, ... ] } -
You make the following request to the Search API:
POST https://platform.cloud.coveo.com/rest/search/v2/querySuggest HTTP/1.1 Content-Type: application/json Accept: application/json Authorization: Bearer **********-****-****-****-************Payload
{ "q": "Dost", "searchHub": "MovieStoreSearch" }The Search API returns the following completions, where
Dosti(a successful Hindi film) is executable and highly recommended, and whereDostoevskydoesn’t figure at all:{ "completions": [ ... { "executableConfidence": 1, "expression": "Dosti", "highlighted": "{Dost}[i]", "score": 35.183255413846215 }, ... ] }Hence, when in the
BookstoreSearchsearch interface, it’s important to pass"searchHub": "BookstoreSearch"for the relevant query suggestionDostoveskyto be returned, instead of the Hindi film.
Query suggestion parameters
See the reference documentation for requesting query suggestions.