Autocomplete API
The Autocompletion API provides real-time, personalized, typo resistant typeahead for your search bar. You send this API what users are currently typing, and the API returns the complete search query suggestions.
Personalized typeahead
Personalized typeahead is an extreme example of personalized search. The personalization starts immediately when users enter even just one character. The typeahead results are personalized so that the entries most likely to drive conversion for the current user are ranked at the top. Miso will predict what the user is looking for in real-time based on their interests and past behaviors.
Basic usage
The request schema of Autocompletion API is similar to that of Search API: you put the search query users typed so
far, and the user_id or anonymous_id for Miso to identify the current user.
For example, when a user types the first character r, you send Miso the following request:
POST /v1/search/autocomplete
{
"q":"r",
"user_id":"user-123"
}
The response will be like:
{
"message": "success",
"data": {
"took": 50,
"miso_id": "e93a6d02-0a7a-11eb-a896-d28586dc1386",
"completions": {
"title": [
{
"text": "Robin Hood: Prince of Thieves (1991)",
"text_with_markups": "R<mark>obin Hood: Princ…",
"product": {
"product_id": "tmdb-8367"
}
},
{
"text": "Reservoir Dogs (1992)",
"text_with_markups": "R<mark>eservoir Dogs (1…",
"product": {
"product_id": "tmdb-500"
}
},
...
]
}
}
}
- took: the amount of time (in milliseconds) Miso took to answer the query
-
completions: an dictionary of autocompletion candidates from different sources. By default, we only run
autocompletion against the titles of products, but you can choose to get autocompletion candidates from other fields
using the
completion_fieldsparameters. - completions.title[].text: the text of completion candidates
- completions.title[].text_with_markups: the completion candidates with the part of text that users has not typed yet, surrounded by <mark> HTML tags.
-
completions.title[].product: the product record whose title matches the autocompletion candidate. This object can be used to implement direct-to-product links: when they click on the link they will go
directly to the product page instead of the search result page. By default, only the
product_idfield is returned, you useflrequest parameter to get more fields returned in the product object.
Typo resistance
Miso's autocompletion algorithm accepts up to 4 typos in the query string. For example, users can try to find the
movie Robin Hood, but make two typos in the query, which becomes robonhood instead (robin->robon, and a space is missing).
POST /v1/search/autocomplete
{
"q":"robanhood",
"user_id":"user-123"
}
Miso can still find the movie "Robin Hood: Prince of Thieves" as a autocompletion candidate.
{
"message": "success",
"data": {
"took": 50,
"miso_id": "e93a6d02-0a7a-11eb-a896-d28586dc1386",
"completions": {
"title": [
{
"text": "Robin Hood: Prince of Thieves (1991)",
"text_with_markups": "Rob<mark>in Hood: Princ…",
"product": {
"product_id": "tmdb-8367"
}
},
...
]
}
}
}
Completion fields
The auto-completions are made against your product attributes. By default, Miso finds completion candidates from the
title field. The completion_fields parameter
lets you specify the attributes you want to perform auto-completion for.
For example, the following query will return auto-completion candidates from the title and a custom attribute
field:custom_attributes.director.
POST /v1/search/autocomplete
{
"q": "rob",
"user_id": "user-123",
"completion_fields": [
"title",
"custom_attributes.director"
]
}
The response will be like the following:
{
"message": "success",
"data": {
"took": 52,
"miso_id": "16d95080-0bb0-11eb-948d-66359cf29022",
"completions": {
"title": [
{
"text": "Robin Hood: Prince of Thieves (1991)",
"text_with_markups": "Rob<mark>in Hood: Princ…",
"product": {
"product_id": "tmdb-8367"
}
},
{
"text": "RoboCop (1987)",
"text_with_markups": "Rob<mark>oCop (1987)</m…",
"product": {
"product_id": "tmdb-5548"
}
},
...
],
"custom_attributes.director": [
{
"text": "Robert Z. Leonard",
"text_with_markups": "<mark>Rob</mark>ert Z.…",
},
...
]
}
}
}
- Type: string · Qqrequired
The search query users typed so far. Please keep the trailing spaces (if any) intact so that we know whether the user has finished typing the last word or is still typing it. For example, the following query means the user has finished typing the word Fight:
{"q": "Fight "}On the other hand, the following query means the user has not finished typing the last word Clu:
{"q": "Fight Clu"} - Type: array · Additional Interactionsadditional
_interactions A list of additional interaction records. You can use this fields to simulate user interactions without actually writing them to the interaction dataset.
- Type: string · Anonymous Idanonymous
_id The anonymous visitor who made the query and for whom Miso will personalize the results. Either
user_idoranonymous_idneeds to be specified for personalization to work. - Type: string · Boost Fqboost
_fq Defines a query in Elasticsearch query-string syntax (Lucene) that can be used to boost a subset of products to the top of the ranking, or to specific boost positions (See
boost_positionsparameter below.) For example, the query below will promote all the relevant products whose brand isNiketo the top of recommendation list:{ "boost_fq": "brand:\"Nike\"" }For a slightly more complex example, the query below will promote the Nike products which have also been tagged as
ON SALEto the top of the ranking:{ "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"" }It is worth mentioning that, Miso will only boost products that are relevant and have high likelihood to convert, and will not boost a low performance product only because it matches the boosting query.
Depending on your boosting rules, in certain cases, you would like to prevent recommendation results from being too monotone due to boosting. With Miso, you have two tools to do so.
First, you can specify
boost_positionsto place promoted products at specific positions in the ranking. For example, the query below will place boosted products only at the first and fourth places in the ranking (positions are 0-based), and place the remaining products in their original ranking, skipping these two positions.{ "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"", "boost_positions": [0, 3] }The second tool is
diversification.diversificationparameter, on a best-effort basis, will try to maintain a minimum distance between products that have the same attributes. For example, the following query will place products made by the same brand apart from each other.{ "boost_fq": "brand:\"Nike\" AND tags:\"ON SALE\"", "diversification": { "brand": {"minimum_distance": 1} } } - Type: array integer[] · Boost Positionsboost
_positions Defines a list of 0-based positions you want to place the boosted products at.
For example, the query below will promote products whose brand is
Nikeas the top and second recommendations:{ "boost_fq": "brand:\"Nike\"", "boost_positions": [0, 1] }If
boost_positionsis not specified (which is the default behavior), all the boosted products will be ranked higher than the rest of the products. - Type: string · Boost Rule Nameboost
_rule _name Name of the boosting rule. Use this to identify a boosting rule in _boosted_rules in the response
- Type: array object[] · Boost Rulesboost
_rules Define a list of boosting rules that will be applied to the search or recommendation results simultaneously.
boost_rulesparameter is particularly useful when you want to boost more than one sets of products, and promote each of them to different positions. For example, the query below will promote products whose brand isNiketo the top and second results, and products whose brand isAdidasto the third and fourth results:{ "boost_rules": [ { "boost_fq": "brand:\"Nike\"", "boost_positions": [0, 1] }, { "boost_fq": "brand:\"Adidas\"", "boost_positions": [2, 3] } ] } - Type: array string[] · Completion Fieldscompletion
_fields Controls the sources of autocompletion candidates. Miso performs autocompletion by matching what the user has typed so far to either the title of products or to other attributes.
By default, we only autocomplete against the value in the
titlefield. Thecompletion_fieldsparameter lets you specify the attributes you want to perform autocompletion against. For example, the following query will limit the autocompletion candidates to thetitleandtagsof products:{"completion_fields": ["title", "tags"]}Autocompletion also works on custom attributes. For example, if you have a custom attribute for the
designer_nameof the product, the following query limits autocompletion candidates to only the designer names:{"candidates": ["custom_attributes.designer_name"]} - Type: boolean · Dedupe Product Group Iddedupe
_product _group _id Whether to dedupe product based on
product_group_id. Ifdedupe_product_group_id=true, Miso will prevent products with the sameproduct_group_idfrom showing multiple times in the search or recommendation results.This is particular useful when one product has multiple variants (for example, different sizes, colors, or materials), and you only want to show this product only once in the search or recommendation results. Miso will then return the variant that is most likely to be of the user's interest.
- Type: string · Engine Idengine
_id The engine you want to get results from. When you have more than one engine, you can use this parameter to specify the specific engine you want to get results from. If not specified, the default engine will be used.
- Type: array string[] · Flfl
List of fields to retrieve. For example, the following request retrieves only the
titlefield of each product along with theproduct_id, which is always returned.{"fl": ["title"]}You can also match field names by using
*as a wildcard. For example, the query below retrieves thetitleand any custom attributes under theattributesdictionary.{"fl": ["title", "attributes.*"]}The following retrieves all the available fields:
{"fl": ["*"]}For the lowest latency, use an empty array to retrieve just the
product_idfield (which is the default).{"fl": []} - Type: string · Fqfq
Defines a query in Elasticsearch query-string syntax (Lucene) that can be used to restrict the superset of products to return, without influencing the overall ranking.
fqcan enable users to drill down to products with specific features based on different product attributesFor example, the query below limits the search results to only show products whose size is either
MorSand brand isNike:{"fq": "size:(\"M\" OR \"S\") AND brand:\"Nike\""}You can use
fqto apply filters against your custom attributes as well. For example, the query below limits the search results to only products whosedesignerattribute isCalvin Klein{"fq": "attributes.designer:\"Calvin Klein\""}fqcan also limit search results by numerical range. For example, the following query limits the results to products that haverating >= 4.{"fq": "rating:[4 TO *]"}
- application/json
- application/json
curl 'https://api.askmiso.com/v1/search/autocomplete?api_key=YOUR_SECRET_TOKEN' \
--request POST \
--header 'Content-Type: application/json' \
--data '{
"engine_id": "",
"user_id": "",
"anonymous_id": "",
"user_hash": "",
"user_cohort": {
"additionalProperty": true
},
"rows": 5,
"type": "",
"dedupe_product_group_id": true,
"additional_interactions": [],
"fq": "",
"boost_fq": "",
"boost_positions": [
1
],
"boost_rule_name": "",
"boost_rules": [],
"geo": {
"filter": [],
"boost": []
},
"q": "",
"language": "",
"min_query_users": 5,
"completion_fields": [
"title"
],
"fl": []
}'
{
"message": "success",
"data": {
"took": 0,
"miso_id": "123e4567-e89b-12d3-a456-426614174000",
"completions": {
"title": [
{
"text": "Miso Japanese Shiba Inu Dog Eating Miso Soup T-Shirt",
"type": "title",
"product": {
"product_id": "123ABC-S-Black"
}
}
],
"brand": [
{
"text": "Miso",
"type": "brand"
},
{
"text": "Mitsui",
"type": "brand"
}
]
}
}
}