Customizing text analysis
This guide shows you how to configure custom text analysis for string fields. Use this guide when a field requires analysis behavior that differs from the default engine analysis.
Prerequisites
Section titled “Prerequisites”Before customizing text analysis, ensure you have:
- A schema with string fields configured for
matchingorautocomplete.
-
Configure an analyzer on your field’s
matchingorautocompletesetting:- Preset analyzer: To use a predefined analyzer chain, specify a preset:
preserve_terms: Tokenizes and normalizes, but keeps every word whole. Use this for names, codes, and SKUs, where stemmingrunningtorunis undesirable.full_text: Drops stopwords, splits compounds, and stems words. Use this for prose.
"sku": {"type": "string","matching": {"analyzer": { "preset": "preserve_terms" }}} - Custom analyzer pipeline: When neither preset fits, define a custom pipeline with
charFilters, atokenizer, andfilters:If you omit the tokenizer, the engine selects the tokenizer for the locale of each value. The pipeline describes indexing, and the engine derives query analysis from it. For component details, see the analysis reference."matching": {"analyzer": {"custom": {"charFilters": [ { "mapping": { "mappings": { "-": "" } } } ],"tokenizer": { "whitespace": {} },"filters": [ { "normalize": {} } ]}}} - Shared analyzer: To share an analyzer across multiple fields, define the chain under
resources.analyzersand reference it by name:"resources": {"analyzers": {"prose": { "preset": "full_text" }}},"fields": {"description": { "type": "string", "matching": { "analyzer": { "named": "prose" } } },"review": { "type": "string", "matching": { "analyzer": { "named": "prose" } } }}
- Preset analyzer: To use a predefined analyzer chain, specify a preset:
-
Add custom stopword or synonym filters (optional):
- Stopwords: To share a stopword list across fields, define it under
resources.stopwordsand reference it in a filter:"resources": {"stopwords": { "brands": ["acme"] }}To inline a stopword list for a single field, use"filters": [ { "stopwords": { "named": "brands" } } ]words. To use the stopword list for the locale of the value being analyzed, supply an empty{ "stopwords": {} }. - Synonyms: Define synonym rules under
resources.synonyms:A field uses the set only when a"resources": {"synonyms": {"cars": {"rules": [{ "equivalent": ["car", "automobile"] },{ "mapping": { "from": ["ny"], "to": ["new york"] } }]}}}synonymsfilter appears in a custom chain on itsmatchingorautocompleteusage, because a preset accepts no extra filters:An"description": {"type": "string","matching": {"analyzer": {"custom": {"filters": [{ "normalize": {} },{ "synonyms": { "named": "cars" } },{ "stemming": {} }]}}}}equivalentrule makes each listed word match the others. Amappingrule is one-way, so a value containingnymatches searches fornew yorkbut not the reverse. Write the rule terms in the form the tokens have where the filter sits, which is lowercase afternormalizeand whole words beforestemming. For the full placement rules, see applying a synonym set to a field. Synonym sets inresourcesapply when values are indexed. For synonyms on search text, see change synonyms without reindexing.
- Stopwords: To share a stopword list across fields, define it under
-
Reindex existing documents: Analysis configurations and synonym rules in
resourcesapply when values are indexed rather than when queried. Reindex existing documents so that they use the updated analysis settings. To apply synonyms to search text without reindexing, see change synonyms without reindexing.
Confirming the configuration
Section titled “Confirming the configuration”Read back the schema definition from the engine to verify the configuration.
Note: The engine expands preset definitions into their full chains before storing them. Reading back the definition shows the expanded chain that was stored.
Related
Section titled “Related”- Analysis - Every preset, tokenizer, char filter, and token filter.
- Defining an index - Attaching a chain to a field and picking what the field is for.
- Localizing fields - The rules a locale applies on top of a chain.
- Changing synonyms without reindexing - Synonyms that apply to search text instead.
- Rolling out a definition change - Reindexing after the chain changes.
- Locales - The languages with rules, and what each one gets.
Exofind is built by Level Four AB and is available under the Apache License 2.0.