DocumentTypes
Engine Type | Supported? |
---|---|
Crawler-based Engine | YES |
API-based Engine | YES |
Search within a single DocumentType or through specific, multiple DocumentTypes.
For Crawler based Engines the default DocumentType is page
.
Single DocumentType
Searching for a single DocumentType.
- q
- required
- The query used within your search.
- engine_key
- required
- The Engine Key associated with your Engine. Found within your dashboard.
- document_types
- optional
- The DocumentType within which to search. See the API Overview for more information on DocumentTypes.
Example - An example when searching
document_types
. Only search through the videos
DocumentType. Crawler based Engines use page
as the default DocumentType.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "YOUR_ENGINE_KEY",
"q": "brothers",
"document_types": ["videos"]
}'
Multiple DocumentTypes
Searching against one of more DocumentTypes.
- q
- required
- The query used for a prefix match. Queries shorter than a few characters may not return results.
- engine_key
- required
- The Engine Key associated with your Engine. Found within your dashboard.
- document_types
- optional
- The DocumentTypes within which to search. See the API Overview for more information on DocumentTypes.
Example - Return results matching "brothers" in the
magazines
and comics
DocumentTypes using a Public search query. Crawler based Engines use page
as the default DocumentType.
curl -XGET 'https://search-api.swiftype.com/api/v1/public/engines/search.json' \
-H 'Content-Type: application/json' \
-d '{
"engine_key": "YOUR_ENGINE_KEY",
"q": "brothers",
"document_types": ["magazines", "comics"]
}'
Errors
Example - Errors for limiting DocumentTypes searched to a DocumentType that doesn't exist
{
"engine_key": "YOUR_ENGINE_KEY",
"q": "brothers",
"document_types": ["books", "folios"]
}
Example Response
{
"records": {
"books": [...]
},
"info": {...},
"errors": {
"document_types": ["DocumentType 'folios' does not exist in this Engine."]
}
}
Example - Errors for fetching a field that doesn't exist in a DocumentType.
{
"engine_key": "YOUR_ENGINE_KEY",
"q": "brothers",
"fetch_fields": {"books": ["title", "publisher"]}
}
Example Response
{
"records": {
"books": [...]
},
"info": {...},
"errors": {
"fetch_fields": {
"books": ["DocumentType 'books' does not have a field 'publisher'."]
}
}
}
Example - Errors for specifying search fields for a DocumentType that doesn't exist in the Engine
{
"engine_key": "YOUR_ENGINE_KEY",
"q": "brothers",
"search_fields": {"folios": ["title"]}
}
Example Response
{
"records": {
"books": [...]
},
"info": {...},
"errors": {
"search_fields": {
"folios": ["DocumentType 'folios' does not exist in this Engine."]
}
}
}
Example - Errors for specifying search fields for a DocumentType that exists in the Engine but is excluded
{
"engine_key": "YOUR_ENGINE_KEY",
"q": "brothers",
"search_fields": {"magazines": ["title"]},
"document_types": ["books"]
}
Example Response
{
"records": {
"books": [...]
},
"info": {...},
"errors": {
"search_fields": {
"magazines": ["DocumentType 'magazines' exists in this Engine but is not included in the list of DocumentTypes to search."]
}
}
}
Stuck? Looking for help? Contact support or check out the Site Search community forum!