Query suggestion APIedit

Want 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 /api/as/v1/engines/{ENGINE_NAME}/query_suggestion
POST /api/as/v1/engines/{ENGINE_NAME}/query_suggestion

Example - A GET request to national-parks-demo to receive suggestions for the "car" query from the title and state text fields.

curl -X POST 'https://[instance id].ent-search.[region].[provider].cloud.es.io/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"
  }
}