Get query suggestions
Get query suggestions
This is for:
DeveloperYou 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 |
-
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)
|
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 Coveo Usage Analytics (Coveo UA) Write API. It’s important that those values match in any given search interface, since the Coveo ML service uses them as filter fields.
You have a search interface for books, and another one for movies.
On the usage analytics side, when logging events in those search interfaces, the originlevel1
value specified in your requests is, respectively, BookstoreSearch
and MovieStoreSearch
.
On the Search API side, this translates into very 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 Dostoevsky
suggestion is executable and highly recommended:
200 OK response body (excerpt)
|
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 highly successful Hindi film) is executable and highly recommended, and where Dostoevsky
doesn’t figure at all:
200 OK response body (excerpt)
|
Hence, when in the BookstoreSearch
search interface, it’s very important to pass the "searchHub": "BookstoreSearch"
for the relevant query suggestion Dostovesky
to be returned, instead of Hindi films.
Note
Analogous remarks hold for the |