search mobile facets autocomplete spellcheck crawler rankings weights synonyms analytics engage api customize documentation install setup technology content domains user history info home business cart chart contact email activate analyticsalt analytics autocomplete cart contact content crawling custom documentation domains email engage faceted history info install mobile person querybuilder search setup spellcheck synonyms weights engage_search_term engage_related_content engage_next_results engage_personalized_results engage_recent_results success add arrow-down arrow-left arrow-right arrow-up caret-down caret-left caret-right caret-up check close content conversions-small conversions details edit grid help small-info error live magento minus move photo pin plus preview refresh search settings small-home stat subtract text trash unpin wordpress x alert case_deflection advanced-permissions keyword-detection predictive-ai sso

Search Fields

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.

query
required
Number of results to be included in the _group key of the returned document. Can be between 1 and 10. Defaults to 10.
search_field
required
Send in a search_field object with your query.
fields
optional
Fields must exist within your Engine schema and be of type text.
weights
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.
import com.swiftype.appsearch.Client;
import com.swiftype.appsearch.ClientException;
import java.util.*;

Client client = new Client("host-2376rb", "search-soaewu2ye6uc45dr8mcd54v8");

String engineName = "national-parks-demo"; String query = "everglade";

Map<String, Object> searchFields = new HashMap<>(); searchFields.put("title", Collections.emptyMap()); searchFields.put("description", Collections.emptyMap()); searchFields.put("states", Collections.emptyMap());

Map<String, Object> options = new HashMap<>(); options.put("search_fields", searchFields);

try { Map<String, Object> response = client.search(engineName, query, options); System.out.println(response); } catch (ClientException e) { System.out.println(e); }

Example - Specifying search_fields for a given query.
const SwiftypeAppSearchClient = require('swiftype-app-search-node')

const client = new SwiftypeAppSearchClient('host-2376rb', 'search-soaewu2ye6uc45dr8mcd54v8')

const engineName = 'national-parks-demo' const query = 'everglade'

const options = { search_fields: { title: {}, description: {}, states: {} } }

client .search(engineName, query, options) .then(response => console.log(response)) .catch(error => console.log(error))

Example - Specifying search_fields for a given query.
require 'swiftype-app-search'

host_identifier = 'host-2376rb' api_key = 'search-soaewu2ye6uc45dr8mcd54v8' client = SwiftypeAppSearch::Client.new(host_identifier: host_identifier, api_key: api_key)

engine_name = 'national-parks-demo' query = 'everglade'

options = { search_fields: { title: {}, description: {}, states: {} } }

begin puts client.search(engine_name, query, options) rescue SwiftypeAppSearch::ClientException => e puts e end

Example - Specifying search_fields for a given query.
from swiftype_app_search import Client
from swiftype_app_search.exceptions import SwiftypeAppSearchError

host_identifier = 'host-2376rb' api_key = 'search-soaewu2ye6uc45dr8mcd54v8' client = Client(host_identifier, api_key)

engine_name = 'national-parks-demo' query = 'everglade'

options = { 'search_fields': { 'title': {}, 'description': {}, 'states': {} } }

try: print(client.search(engine_name, query, options)) except SwiftypeAppSearchError as e: print(e)

Example - Specifying search_fields for a given query.
const client = SwiftypeAppSearch.createClient({
  hostIdentifier: 'host-2376rb',
  searchKey: 'search-soaewu2ye6uc45dr8mcd54v8',
  engineName: 'national-parks-demo'
})

const query = 'everglade'

const options = { search_fields: { title: {}, description: {}, states: {} } }

client .search(query, options) .then(function(response){ console.log(response) }) .catch(function(error){ console.log(error) })

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.
import com.swiftype.appsearch.Client;
import com.swiftype.appsearch.ClientException;
import java.util.*;

Client client = new Client("host-2376rb", "search-soaewu2ye6uc45dr8mcd54v8");

String engineName = "national-parks-demo"; String query = "everglade";

Map<String, Integer> make = new HashMap<>(); title.put("weight", 10);

Map<String, Integer> model = new HashMap<>(); description.put("weight", 5);

Map<String, Integer> make = new HashMap<>(); states.put("weight", 3);

Map<String, Object> searchFields = new HashMap<>(); searchFields.put("title", title); searchFields.put("description", description); searchFields.put("states", states);

Map<String, Object> options = new HashMap<>(); options.put("search_fields", searchFields);

try { Map<String, Object> response = client.search(engineName, query, options); System.out.println(response); } catch (ClientException e) { System.out.println(e); }

Example - Specifying weights to favor the park title, followed by its description, and then their states.
const SwiftypeAppSearchClient = require('swiftype-app-search-node')

const client = new SwiftypeAppSearchClient('host-2376rb', 'search-soaewu2ye6uc45dr8mcd54v8')

const engineName = 'national-parks-demo' const query = 'everglade'

const options = { search_fields: { title: { weight: 10 }, description: { weight: 5 }, states: { weight: 3 } } }

client .search(engineName, query, options) .then(response => console.log(response)) .catch(error => console.log(error))

Example - Specifying weights to favor the park title, followed by its description, and then their states.
require 'swiftype-app-search'

host_identifier = 'host-2376rb' api_key = 'search-soaewu2ye6uc45dr8mcd54v8' client = SwiftypeAppSearch::Client.new(host_identifier: host_identifier, api_key: api_key)

engine_name = 'national-parks-demo' query = 'everglade'

options = { search_fields: { title: { weight: 10 }, description: { weight: 5 }, states: { weight: 3 } } }

begin puts client.search(engine_name, query, options) rescue SwiftypeAppSearch::ClientException => e puts e end

Example - Specifying weights to favor the park title, followed by its description, and then their states.
from swiftype_app_search import Client
from swiftype_app_search.exceptions import SwiftypeAppSearchError

host_identifier = 'host-2376rb' api_key = 'search-soaewu2ye6uc45dr8mcd54v8' client = Client(host_identifier, api_key)

engine_name = 'national-parks-demo' query = 'everglade'

options = { 'search_fields': { 'title': { 'weight': 5 }, 'description': { 'weight': 10 }, 'states': { 'weight': 10 } } }

try: print(client.search(engine_name, query, options)) except SwiftypeAppSearchError as e: print(e)

Example - Specifying weights to favor the park title, followed by its description, and then their states.
const client = SwiftypeAppSearch.createClient({
  hostIdentifier: 'host-2376rb',
  searchKey: 'search-soaewu2ye6uc45dr8mcd54v8',
  engineName: 'national-parks-demo'
})

const query = 'everglade'

const options = { search_fields: { title: { weight: 10 }, description: { weight: 5 }, states: { weight: 3 } }

client .search(query, options) .then(function(response){ console.log(response) }) .catch(function(error){ console.log(error) })

Errors

search_fieldsIf 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!