Reading colours and brands in the search box
This guide shows you how to configure search settings to read facet field values from search input as filters. Use this guide when building a search interface that extracts values like red nike shoes into colour and brand filters while searching shoes as text. The engine extracts the values, filters the matching fields, ranks filter matches first, and returns the parsed filters in the response.
The engine reads stored facet values from the answering generation. Enabling value interpretation requires no reindex and is configured in the search settings of the index.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have:
- A configured index with at least one
stringfield that has bothfilterandfacetenabled and nohierarchy. For more information, see Defining an index. - Credentials with the
indexes.readpermission to read settings, thesettings.writepermission to change them, and thesearchpermission to send search queries.
-
Check that the fields hold a dictionary:
Ensure the target fields are
stringfields configured with bothfilterandfacetand withouthierarchy:PUT /v1alpha1/admin/indexes/productsContent-Type: application/json{"fields": {"id": { "type": "string", "role": "id" },"name": { "type": "string", "role": "title" },"colour": { "type": "string", "filter": {}, "facet": {} },"brand": { "type": "string", "filter": {}, "facet": {} },"price": { "type": "double", "filter": {}, "unit": "SEK" }}}A field that lacks
filterorfacetrequires an updated index definition and a reindex before the engine can read its values. For more information, see Rolling out a definition change. -
Opt the fields in through the search settings:
Send a
PUTrequest to update the search settings for the index. Include any existing settings, such asrankingorsynonyms, becausePUTreplaces the entire settings object:PUT /v1alpha1/admin/indexes/products/settingsContent-Type: application/json{"fields": {"colour": { "interpret": {} },"brand": { "interpret": {} }}}The server validates the fields against the active generation. Naming a field that does not exist returns
400 Bad Requestwithsettings:fields:field_unknown. Naming a field that is not astringfield withfilterandfacet, or that hashierarchy, returnssettings:fields:interpret_unsupported.Settings take effect immediately on the answering node and within
EXOFIND_SETTINGS_REFRESH_INTERVAL(default:10s) on other nodes. -
Send a search request with user matching mode:
To interpret search text, use a
textclause with"match": "user":POST /v1alpha1/indexes/products/searchContent-Type: application/json{"query": [{ "type": "text", "text": "red nike shoes under 500", "match": "user" }]}The engine reads
redas the valueRedforcolour,nikeas the valueNikeforbrand, andunder 500as a price bound when the price field declares a currency unit. The query searches the remaining wordshoesas text.Interpretation does not exclude text matches. The query still searches the original words as text, but boosts documents that satisfy the filter so they rank first.
-
Inspect the read filters in the search response:
When the engine extracts values from query text, the response includes an
interpretedobject:{"hits": [ ... ],"interpreted": {"filters": [{"field": "colour","match": { "value": "Red" },"words": ["red"]},{"field": "brand","match": { "value": "Nike" },"words": ["nike"]},{"field": "price","match": { "type": "range", "lt": 500 },"words": ["under", "500"]}],"text": "shoes"}}The
matchproperty returns the value in its stored casing and spelling, soREDin the query matchesRed. Use the returnedfiltersarray to display interactive chips in your search interface. You can pass eachmatchobject directly into afiltersarray if the user keeps the refinement for subsequent queries. -
Disable reading when querying exact text:
To search the entire query input as text without extracting filters, set
"interpret": "off"on thetextclause. This setting disables number interpretation as well:{"query": [{"type": "text","text": "red nike shoes","match": "user","interpret": "off"}]}You can also wrap terms in quotation marks (such as
"red"). Quoted phrases and negative exclusions (-word) are never interpreted as filters. -
Turn a field off later with PATCH:
To update a single field without replacing the entire settings object, send a
PATCHrequest. Setinterpretto{}to enable reading ornullto disable it:PATCH /v1alpha1/admin/indexes/products/settingsContent-Type: application/json{"fields.brand.interpret": null} -
Declare labels for values stored in another language:
The engine matches typed words against stored values, so a term like
röddoes not match the stored valueRed. To interpret words in the user’s language, declare values with labels per locale in the field settings:PATCH /v1alpha1/admin/indexes/products/settingsContent-Type: application/json{"fields.colour.values": [{ "value": "Red", "labels": { "sv": "Röd", "de": "Rot" } },{ "value": "Blue", "labels": { "sv": "Blå", "de": "Blau" } }]}A search with
"locale": "sv"then readsrödas the valueRed, and thematchobject ininterpreted.filtersreturnsRed. Facets oncolouralso return these labels in thelabelproperty, so the filter chip and the facet list display matching text. For information about accepted fields and error responses, see Declared values.
Confirming the result
Section titled “Confirming the result”Inspect the JSON response from the search endpoint to verify query interpretation:
interpreted.filters: Contains each extracted filter, including the targetfield, thematchobject with the stored value, and the originalwords.interpreted.text: Contains the remaining text after removing interpreted terms. If all terms were converted to filters, this value is an empty string.hits: Returns documents that satisfy the extracted filter ranked first, followed by documents that match the terms as text.
If the response omits interpreted, no filters were extracted. Check the following causes:
- The field is not opted in: Retrieve the settings with
GET /v1alpha1/admin/indexes/products/settingsand verify thatfields.<name>.interpretis present. - The word is not a value: A term is extracted only when it matches an indexed value exactly after case and diacritic normalization. Terms are not stemmed; for example,
shoesdoes not matchShoe. Multi-word values match contiguous terms up to three words. - The word is a label of another locale: The engine reads declared labels in the search locale, or in the field’s default locale when the search locale has no label. Send the user’s
localewith the search request, and verify that the label is keyed by a tag that the locale resolves to. - The clause is not in user mode: Only
textclauses with"match": "user"support interpretation. - A newer generation dropped the usage: Search settings outlive generations. If the active generation lacks the field or configures it without
filterorfacet, the engine treats the terms as text instead of returning an error. The node logs skipped fields once per settings version. - Unsupported features on the node: If a node does not support the
interpret_valuescapability, it bypasses the settings and evaluates queries against the index definition alone. Verify whetherunsupportedFeaturesin the settings response includesinterpret_values.
Related
Section titled “Related”- Reading the values of a field - How a span of words is matched and the
interpretedobject. - Field settings - The
fieldsobject of the search settings. - Reading numbers in the search box - Reading a price or a size typed next to a unit.
- Searching from a search box - The punctuation a person can type, the join mode, and showing what was read back to them.
- Searching an index - The search box, filters, facets, and ordering.
Exofind is built by Level Four AB and is available under the Apache License 2.0.