Search Fields (Weights)
Learn more about Weights within the Relevance Tuning guide.
The search_fields
parameter restricts a query to search only specific fields.
Restricting fields will result in faster queries, especially for schemas with many text fields.
Only available within text fields.
- search_fields
- required
- Send in a
search_fields
object with your query. - fields
- optional
- Fields must exist within your Engine schema and be of type text.
- weight
- optional
- Weight is given between 10 (most relevant) to 1 (least relevant).
Example - Specifying
search_fields
for a given query.
curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {},
"description": {},
"states": {}
},
"query": "everglade"
}'
Example - Specifying
search_fields
for a given query.
No Java example available, showing cURL
curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {},
"description": {},
"states": {}
},
"query": "everglade"
}'
Example - Specifying
search_fields
for a given query.
No Node example available, showing cURL
curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {},
"description": {},
"states": {}
},
"query": "everglade"
}'
Example - Specifying
search_fields
for a given query.
No Ruby example available, showing cURL
curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {},
"description": {},
"states": {}
},
"query": "everglade"
}'
Example - Specifying
search_fields
for a given query.
No Python example available, showing cURL
curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {},
"description": {},
"states": {}
},
"query": "everglade"
}'
Example - Specifying
search_fields
for a given query.
No Javascript example available, showing cURL
curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {},
"description": {},
"states": {}
},
"query": "everglade"
}'
Search Fields with Weight
Apply Weights to each search field.
Engine level Weight settings will be applied is none are provided.
Query time Weights take precedence over Engine level values.
Example - Specifying weights to favor the park
title
, followed by its description
, and then their states
.
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {
"weight": 10
},
"description": {
"weight": 5
},
"states": {
"weight": 3
}
},
"query": "everglade"
}'
Example - Specifying weights to favor the park
title
, followed by its description
, and then their states
.
No Java example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {
"weight": 10
},
"description": {
"weight": 5
},
"states": {
"weight": 3
}
},
"query": "everglade"
}'
Example - Specifying weights to favor the park
title
, followed by its description
, and then their states
.
No Node example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {
"weight": 10
},
"description": {
"weight": 5
},
"states": {
"weight": 3
}
},
"query": "everglade"
}'
Example - Specifying weights to favor the park
title
, followed by its description
, and then their states
.
No Ruby example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {
"weight": 10
},
"description": {
"weight": 5
},
"states": {
"weight": 3
}
},
"query": "everglade"
}'
Example - Specifying weights to favor the park
title
, followed by its description
, and then their states
.
No Python example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {
"weight": 10
},
"description": {
"weight": 5
},
"states": {
"weight": 3
}
},
"query": "everglade"
}'
Example - Specifying weights to favor the park
title
, followed by its description
, and then their states
.
No Javascript example available, showing cURL
curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer search-soaewu2ye6uc45dr8mcd54v8' \
-d '{
"search_fields": {
"title": {
"weight": 10
},
"description": {
"weight": 5
},
"states": {
"weight": 3
}
},
"query": "everglade"
}'
Errors
search_fields | If a requested search field does not exist in the current schema. If a search field JSON object is malformed. It must be an empty JSON object or a JSON object with a weight key. If all search fields are non text fields. |
Stuck? Looking for help? Contact support or check out the App Search community forum!