ℹ️ For new users, we recommend using our native Elasticsearch tools, rather than the standalone App Search product. We are actively developing new features and capabilities in the Elastic Stack to help you build powerful search applications.
Refer to this blog for more information.
Query suggestion API
editQuery suggestion API
editWant to learn more? Explore the Query Suggestions guide.
Provide relevant query suggestions for incomplete queries.
Also known as Autocomplete
Requires a Public Search Key.
Only available on text fields.
-
query
(required) - A partial query for which to receive suggestions.
-
types
(optional) - Specify the documents key within the types parameter to look for suggestions within certain text fields. Defaults to all text fields.
-
size
(optional) - Number of query suggestions to return. Must be between 1 and 20. Defaults to 10.
GET <ENTERPRISE_SEARCH_BASE_URL>/api/as/v1/engines/{ENGINE_NAME}/query_suggestion
POST <ENTERPRISE_SEARCH_BASE_URL>/api/as/v1/engines/{ENGINE_NAME}/query_suggestion
Example - A POST
request to national-parks-demo
to receive suggestions for the "car" query from the title
and state
text fields.
curl -X POST '<ENTERPRISE_SEARCH_BASE_URL>/api/as/v1/engines/national-parks-demo/query_suggestion' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer search-7eud55t7ecdmqzcanjsc9cqu' \ -d '{ "query": "car", "types": { "documents": { "fields": [ "title", "states" ] } }, "size": 4 }'
Example Response
{ "results": { "documents": [ { "suggestion": "carlsbad" }, { "suggestion": "carlsbad caverns" }, { "suggestion": "carolina" } ] }, "meta": { "request_id": "914f909793379ed5af9379b4401f19be" } }