Dictionary management
Alibaba Cloud Elasticsearch Serverless (ES Serverless) provides built-in plugins, including the IK analysis plugin, synonym, keyword filter, and stemmer. You can upload custom dictionaries to build more precise and flexible Chinese search capabilities. This topic describes how to add, use, and manage dictionaries.
Background information
The IK analysis plugin segments continuous Chinese sentences into meaningful words.
|
Component |
Description |
Tokenization and types |
|
Tokenizer |
Splits Chinese text into meaningful words (tokens) and determines the tokenization granularity. |
The following tokenization rules are supported:
|
|
Dictionary file |
Provides the vocabulary that the tokenizer uses for tokenization. Note
The dictionary file is a |
The IK analysis plugin includes a default main dictionary ( You can also add custom dictionaries to optimize tokenization for your specific business needs. The following types of dictionaries are supported:
|
ES Serverless includes a built-in, enhanced IK analysis plugin that supports hierarchical dictionary configuration and scope isolation. You can configure separate dictionaries for different indexes or analyzers to achieve fine-grained management.
Higher-priority dictionary configurations completely override lower-priority ones. If multiple dictionaries have conflicting definitions for the same word or tokenization rule, the definition from the highest-priority dictionary takes precedence.
|
Dictionary level |
Key advantage |
Scope |
Priority |
|
Analyzer level |
Provides fine-grained control, allowing different fields within the same index to use different dictionaries. |
Target custom analyzer |
Highest |
|
Index level |
Achieves business isolation by allowing different indexes (such as product catalogs and article libraries) to have their own dictionaries. |
Target index |
Medium |
|
Application level |
Provides a base dictionary for quick use. Note
Built-in dictionaries are at the application level by default. |
Application-wide |
Lowest |
Limitations
-
Dictionary quantity and size limits: You can upload a maximum of
10dictionary files, and the total size of all files cannot exceed20MB.-
If the number of dictionary files exceeds the limit, merge related files or adjust the max_dics_count quota to increase the file count limit.
-
If the total size of dictionary files exceeds the limit, adjust the max_all_dic_size quota to increase the total size limit.
-
-
Dictionary format limit: Only files in
DICformat can be added as dictionaries.
Access dictionary management
Go to the application details page.
Log on to the Elasticsearch Serverless console and switch to the desired region in the top navigation bar.
In the left-side navigation pane, click Application Management. Then, click the name of the application that you created to go to the application details page.
-
In the left-side navigation pane, on the tab, you can add, use, and manage your dictionaries.
Add a dictionary
On the Dictionary Management page, click Add Custom Dictionary. Enter a name and follow the on-screen instructions to add an IK analysis dictionary, IK stopword dictionary, or synonym dictionary. You can upload dictionary files in the following ways.
-
General rules
-
The dictionary name must be unique within the current application and cannot be changed after the dictionary is added.
-
A new dictionary can be used to tokenize only newly created indexes. ES Serverless does not re-tokenize existing indexes with the new dictionary. We recommend that you continue to use the old dictionary for existing indexes and apply the new dictionary to newly created indexes.
-
-
Content requirements for IK analysis and IK stopword dictionaries
-
Enter one word per line, using
\nas the newline character. A word cannot contain spaces in the middle, but leading and trailing spaces are allowed. For example," word "," word", and"word "are valid entries, while"wo rd"is an invalid entry. -
Lines starting with
#are comments.
-
-
Synonym syntax rules
-
The synonym file must be a UTF-8 encoded
.dicfile. Each line in the file defines a set of synonym rules and supports the following two formats:-
Equivalent synonyms (Solr format)
Words separated by commas are equivalent. A search for any one of these words will match documents containing any word in the group.# Example: Searching for "手机" (mobile phone), "智能手机" (smartphone), or "移动电话" (mobile telephone) yields the same results. 手机,智能手机,移动电话 ipod,i-pod,i podAlternatively, you can use
=>to map a set of terms to a standard term. This method is typically used for normalization, which maps non-standard terms to standard ones.# Example: Map both "usa" and "us" to "美国" (United States). usa,us => 美国 -
WordNet format. For more information, see WordNet.
-
-
Stemmer
-
Purpose: A stemmer is a text analysis component that reduces different forms of a word to a common root (or stem). For example, "running", "runs", and "ran" are all stemmed to "run". This process enhances semantic understanding in a search system, allowing a user searching for "run" to match content containing "running" or "runs". A stemmer improves recall by ensuring that different word forms can be retrieved uniformly, and is particularly useful for languages with rich inflection, such as English.
-
Format:
running => run // Indicates stemming. The word on the left is converted to the word on the right. jumping => jump
-
-
Keyword filter
-
Purpose: A keyword filter is an analysis component that treats input text as a single, indivisible keyword, preventing it from being tokenized. Unlike regular tokenizers, it preserves the integrity of the original text, ensuring that "New York" is not split into "New" and "York" but is processed as a whole. This mechanism is crucial in scenarios requiring exact matches, such as indexing and searching fields like product IDs, brand names, and proper nouns. It ensures that certain fields maintain their original semantic integrity, which provides a reliable foundation for precise queries and aggregations.
-
Format:
running // Words configured in the dictionary are not filtered and are always retained. jump
-
-
Stopwords
-
Purpose: A stopword is a common, high-frequency word (such as "the", "a", or "and") that is filtered out during text processing. These words contribute little to distinguishing content. Removing stopwords can significantly reduce index size, improve query efficiency, and make search results more precise by allowing the system to focus on keywords with actual semantic value.
-
Format:
the // Words configured in this dictionary are treated as stopwords and filtered out. of and to a
-
-
Mapping char filter
-
Purpose: A mapping char filter performs character-level replacements before the text is processed by a tokenizer. It uses predefined mapping rules to convert specific character sequences into a target form. This is mainly used to standardize text representations, handle special symbols, and resolve language-specific character issues, thereby improving search quality and query precision.
-
Format:
. => 0 // The character before => is replaced by the character after =>. > => 1 < => 2
-
-
-
Upload from local: Click the
icon or drag and drop a local file to upload it. -
Upload from OSS: Select and upload a file from a specified OSS bucket.
-
The OSS bucket and the ES Serverless application must be in the same region.
-
The directory name in the bucket must contain
es-serverless, or you must add thees-serverless: es-serverlesstag to the bucket. Otherwise, the upload will fail.NoteES Serverless requires the
es-serverlesskeyword to authorize access to the OSS bucket data. -
The ES Serverless application does not automatically sync updates to dictionary files in OSS. If the content of a source dictionary file in OSS changes, you must perform an IK dictionary update to apply the changes.
-
Configure and use dictionaries
After you upload the dictionary file, it takes approximately 2 min to take effect. You can then go to Kibana to configure and use the dictionary for word segmentation.
Validate a dictionary
You can use the POST /_analyze API to test whether the added dictionary is working. The following code provides an example.
POST /_analyze
{
"analyzer": "ik_smart",
"text": "租户专用词汇测试"
}
Index-level configuration
The following example creates an index named products that uses the business-terms and product-names analysis dictionaries, and the stop-words stopword dictionary for tokenization.
Before you begin, you must add the relevant dictionaries to your application.
PUT /products
{
"settings": {
"index": {
"ik": {
"extra_dict_ids": ["business-terms", "product-names"],
"extra_stop_dict_ids": ["stop-words"]
}
}
},
"mappings": {
"properties": {
"title": { "type": "text", "analyzer": "ik_max_word" },
"content": { "type": "text", "analyzer": "ik_smart" }
}
}
}
-
extra_dict_ids: Specifies the custom IK analysis dictionaries to add.
-
extra_stop_dict_ids: Specifies the custom IK stopword dictionaries to add.
Analyzer-level configuration
-
Method 1: Use a
custom analyzer + custom tokenizer. Configure the custom dictionary in the tokenizer. This method is highly extensible and suitable for complex business scenarios.The following example creates an index named
custom_analyzer_indexand configures themy_ik_analyzeranalyzer to use theanalyzer-specific-dictandspecial-termsanalysis dictionaries, along with theanalyzer-stop-wordsstopword dictionary. This configuration applies a separate dictionary to tokenize thecontentfield.NoteBefore you begin, you must add the relevant dictionaries to your application.
PUT /custom_analyzer_index { "settings": { "analysis": { "analyzer": { "my_ik_analyzer": { "type": "custom", "tokenizer": "ik_tokenizer", "filter": ["lowercase"] } }, "tokenizer": { "ik_tokenizer": { "type": "ik_max_word", "use_smart": false, "enable_lowercase": true, "extra_dict_ids": ["analyzer-specific-dict", "special-terms"], "extra_stop_dict_ids": ["analyzer-stop-words"] } } } }, "mappings": { "properties": { "content": { "type": "text", "analyzer": "my_ik_analyzer" } } } }-
extra_dict_ids: Specifies the custom IK analysis dictionaries to add.
-
extra_stop_dict_ids: Specifies the custom IK stopword dictionaries to add.
-
-
Method 2: Directly configure the custom dictionary in the analyzer definition. This method is simple, efficient, and suitable for standard scenarios.
The following example creates an index named
analyzer_level_indexand defines two analyzers, allowing different fields within the same index to use separate dictionaries for tokenization.NoteBefore you begin, you must add the relevant dictionaries to your application.
-
product_analyzeranalyzer: Uses theproduct-dictandbrand-namesanalysis dictionaries, and theproduct-stop-wordsstopword dictionary to tokenize theproduct_namefield. -
content_analyzeranalyzer: Uses thecontent-dictandtechnical-termsanalysis dictionaries, and thecontent-stop-wordsstopword dictionary to tokenize thedescriptionfield.
PUT /analyzer_level_index { "settings": { "analysis": { "analyzer": { "product_analyzer": { "type": "ik_smart", "extra_dict_ids": ["product-dict", "brand-names"], "extra_stop_dict_ids": ["product-stop-words"] }, "content_analyzer": { "type": "ik_max_word", "extra_dict_ids": ["content-dict", "technical-terms"], "extra_stop_dict_ids": ["content-stop-words"] } } } }, "mappings": { "properties": { "product_name": { "type": "text", "analyzer": "product_analyzer" }, "description": { "type": "text", "analyzer": "content_analyzer" } } } }-
extra_dict_ids: Specifies the custom IK analysis dictionaries to add.
-
extra_stop_dict_ids: Specifies the custom IK stopword dictionaries to add.
-
Use the ik_max_word tokenizer
-
Run the following index creation request in Kibana to enable the
ik_max_wordmode and the single-character word formation feature.PUT /product_index { "settings": { "index": { "number_of_shards": 1, "number_of_replicas": 0, "analysis": { "analyzer": { "my_index_analyzer": { "type": "ik_max_word", "filter": ["lowercase"], "enable_single_word": "true" }, "my_search_analyzer": { "type": "ik_max_word", "filter": ["lowercase"], "enable_single_word": "true" } } } } }, "mappings": { "properties": { "content": { "type": "text", "analyzer": "my_index_analyzer", "search_analyzer": "my_search_analyzer", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "title": { "type": "text", "analyzer": "my_index_analyzer", "search_analyzer": "my_search_analyzer" }, "description": { "type": "text", "analyzer": "my_index_analyzer", "search_analyzer": "my_search_analyzer" }, "created_at": { "type": "date" } } } } -
After creating the index, run the following command in Kibana to verify the single-character word formation feature.
POST /product_index/_analyze { "analyzer": "my_index_analyzer", "text": "华为手机旗舰店" }The expected tokenization result includes single characters such as "华", "为", "手", "机", "旗", "舰", and "店", while also retaining the original words "华为", "手机", and "旗舰店".
ImportantIf you are using an older version of the IK analysis plugin, you may need to replace the
enable_single_wordparameter with one officially supported by that version. In newer versions of the IK analysis plugin, single-character word formation is included by default, but this configuration explicitly enables the feature.
Use synonyms
The following example configures synonyms by using a filter. It uses a test file named aliyun-synonyms.dic, which contains begin, start. Before you begin, add the dictionary.
-
After connecting to your cluster, create an index and configure it to use the uploaded synonym file.
PUT /aliyun-index-test01 { "settings": { "analysis": { "filter": { "my_inline_synonym_filter": { "type": "synonym_graph", "synonyms_path": "aliyun-synonyms", "updateable": true } }, "analyzer": { "my_ik_search_analyzer": { "type": "custom", "tokenizer": "ik_smart", "filter": ["lowercase", "my_inline_synonym_filter"] }, "my_ik_index_analyzer": { "type": "custom", "tokenizer": "ik_max_word", "filter": ["lowercase"] } } } }, "mappings": { "properties": { "title": { "type": "text", "analyzer": "my_ik_index_analyzer", "search_analyzer": "my_ik_search_analyzer", "term_vector": "with_positions_offsets" } } } } -
Verify the synonym effect.
Use the
_analyzeAPI to verify that the analyzer has correctly loaded the synonyms. Assume the synonym file containsbegin,start.GET /aliyun-index-test01/_analyze { "analyzer": "my_ik_search_analyzer", "text": "start" }A successful response should include both
beginandstartas tokens.{ "tokens": [ { "token": "begin", "start_offset": 0, "end_offset": 5, "type": "SYNONYM", "position": 0 }, { "token": "start", "start_offset": 0, "end_offset": 5, "type": "ENGLISH", "position": 0 } ] }
Use stemmers and keyword filters
The following example configures a stemmer and a keyword filter by using filters. It uses the test files my-stemmer.dic and my-keyword.dic with the content shown below. Before you begin, add the dictionaries.
my-stemmer.dic
running =>run
runs =>run
ran =>run
my-keyword.dic
asd_123
-
After connecting to your cluster, create an index and configure it to use the uploaded stemmer and keyword filter dictionaries.
Stemming
PUT /analysis-demo { "settings": { "analysis": { "analyzer": { "my_stemmer_analyzer": { "tokenizer": "standard", "filter": [ "lowercase", "stemmer_filter" ] } }, "filter": { "stemmer_filter": { "type": "stemmer_override", "rules_path": "my-stemmer", // Configure the stemmer path here. The name must match the dictionary name from the console. "language": "english" } } } }, "mappings": { "properties": { "content": { "type": "text", "analyzer": "my_stemmer_analyzer" } } } }Verify the stemming effect in the index.
POST /analysis-demo/_analyze { "analyzer": "my_stemmer_analyzer", "text": "I am running. He runs every day. They ran yesterday." }In a successful response,
running,runs, andranare all replaced withrun:{ "tokens": [ { "token": "i", "start_offset": 0, "end_offset": 1, "type": "<ALPHANUM>", "position": 0 }, { "token": "am", "start_offset": 2, "end_offset": 4, "type": "<ALPHANUM>", "position": 1 }, { "token": "run", "start_offset": 5, "end_offset": 12, "type": "<ALPHANUM>", "position": 2 }, { "token": "he", "start_offset": 14, "end_offset": 16, "type": "<ALPHANUM>", "position": 3 }, { "token": "run", "start_offset": 17, "end_offset": 21, "type": "<ALPHANUM>", "position": 4 }, { "token": "every", "start_offset": 22, "end_offset": 27, "type": "<ALPHANUM>", "position": 5 }, { "token": "day", "start_offset": 28, "end_offset": 31, "type": "<ALPHANUM>", "position": 6 }, { "token": "they", "start_offset": 33, "end_offset": 37, "type": "<ALPHANUM>", "position": 7 }, { "token": "run", "start_offset": 38, "end_offset": 41, "type": "<ALPHANUM>", "position": 8 }, { "token": "yesterday", "start_offset": 42, "end_offset": 51, "type": "<ALPHANUM>", "position": 9 } ] }Keyword filtering
PUT /stemmer01 { "settings": { "analysis": { "analyzer": { "stemmer_keyword_analyzer": { "tokenizer": "standard", "filter": [ "lowercase", "keyword_filter" ] } }, "filter": { "keyword_filter": { "type": "keyword_marker", "keywords_path": "my-keyword", "ignore_case": true } } } }, "mappings": { "properties": { "content": { "type": "text", "analyzer": "stemmer_keyword_analyzer" } } } }Verify the keyword filtering effect in the index.
POST /stemmer01/_analyze { "text": "asd_123-and another product", "analyzer": "stemmer_keyword_analyzer" }In a successful response,
asd_123is output as a single keyword:{ "tokens": [ { "token": "asd_123", "start_offset": 0, "end_offset": 7, "type": "<ALPHANUM>", "position": 0 }, { "token": "and", "start_offset": 8, "end_offset": 11, "type": "<ALPHANUM>", "position": 1 }, { "token": "another", "start_offset": 12, "end_offset": 19, "type": "<ALPHANUM>", "position": 2 }, { "token": "product", "start_offset": 20, "end_offset": 27, "type": "<ALPHANUM>", "position": 3 } ] }
Use stopwords
The following example configures stopwords by using a filter. It uses a test file named my-stop-words.dic with the content shown below. Before you begin, add the dictionary.
the
of
and
to
a
-
After connecting to your cluster, create an index and configure it to use the uploaded stopword dictionary.
PUT /my-stop-words { "settings": { "analysis": { "analyzer": { "standard_stop_word_analyzer": { "tokenizer": "standard", "filter": [ "stop_word_file" ] } }, "filter": { "stop_word_file": { "type": "stop", "stopwords_path": "my-stop-words" // The name must match the dictionary name entered in the console. } } } }, "mappings": { "properties": { "content": { "type": "text", "analyzer": "standard_stop_word_analyzer" } } } } -
Verify the stopword effect in the index.
POST /my-stop-words/_analyze { "analyzer": "standard_stop_word_analyzer", "text": "text to analyze" }A successful response does not contain "to" because it is defined as a stopword and is filtered out:
{ "tokens": [ { "token": "text", "start_offset": 0, "end_offset": 4, "type": "<ALPHANUM>", "position": 0 }, { "token": "analyze", "start_offset": 8, "end_offset": 15, "type": "<ALPHANUM>", "position": 2 } ] }
Use mapping char filters
The following example configures a mapping char filter by using a char_filter. It uses a test file named my-mapping-char-filter.dic with the content shown below. Before you begin, add the dictionary.
. => 0 // The character before => is replaced by the character after =>. For example, . is replaced by 0.
> => 1
< => 2
-
After connecting to your cluster, create an index and configure it to use the uploaded dictionary.
PUT /my-mapping-char-filter { "settings": { "analysis": { "analyzer": { "mapping_char_word_analyzer": { "tokenizer": "standard", "char_filter": [ "mapping_char_word_filter" ] } }, "char_filter": { "mapping_char_word_filter": { "type": "mapping", "mappings_path": "my-mapping-char-filter" } } } } } -
Verify the mapping char filter effect in the index.
POST /my-mapping-char-filter/_analyze { "analyzer": "mapping_char_word_analyzer", "text": "text to analyze.><" }In a successful response, the characters
.><are replaced with012:{ "tokens": [ { "token": "text", "start_offset": 0, "end_offset": 4, "type": "<ALPHANUM>", "position": 0 }, { "token": "to", "start_offset": 5, "end_offset": 7, "type": "<ALPHANUM>", "position": 1 }, { "token": "analyze012", "start_offset": 8, "end_offset": 18, "type": "<ALPHANUM>", "position": 2 } ] }
Manage dictionaries
After adding a dictionary, you can view its basic information on the Dictionary Management page, or perform actions such as downloading, updating, or deleting it as needed.
-
View dictionary: View information such as dictionary type, source, file size, and the number of entries.
-
Download dictionary: Download the dictionary file to your local machine.
-
Update dictionary: Update the current dictionary with the latest version of your dictionary file.
Important-
Updating a dictionary does not interrupt your service. After an update, the new dictionary only affects the tokenization of newly written data. This inconsistency in tokenization may make historical data unsearchable.
-
To apply the latest dictionary to an existing index, run a
POST /your_index/_update_by_queryoperation to re-tokenize all documents in the target index according to the latest rules. To avoid affecting your services, perform this operation during off-peak hours.
-
-
Delete dictionary: If a dictionary is no longer needed, you can delete it. This action cannot be undone, so proceed with caution.
Important-
We recommend that you avoid deleting dictionaries unless absolutely necessary. Instead, adjust your tokenization strategy by updating the dictionary content.
-
If you must delete a dictionary and need to fix historical data, first update the dictionary content to an empty state, and then run a
POST /your_index/_update_by_queryoperation to update the index documents, ensuring consistent tokenization.
-
Impact of dictionary changes
Updating or deleting a dictionary can affect search effectiveness and tokenization behavior in the following ways:
-
Changes in tokenization granularity
-
New data: After a dictionary is updated or deleted, documents in new indexes will no longer be tokenized using the old dictionary's rules.
-
Historical data: The tokenization of already indexed documents is not affected. However, if new tokenization rules are used at search time, it may decrease recall.
-
-
Degraded search effectiveness
-
Decreased recall: Search keywords may fail to match compound words defined in the original thesaurus. For example, after
"machine learning"is removed from the thesaurus, a search for"machine learning"may fail to retrieve documents that contain this term (the search term will be split into"machine", "learning"). -
Precision fluctuation: After the stopword dictionary is deleted, meaningless words (such as
"the" and "a") will be included in searches again, which adds noise to the results.
-
-
Changes in relevance scores: Metrics like term frequency (TF) and inverse document frequency (IDF) are calculated based on tokenization results. Updating or deleting a dictionary can alter the scoring logic, affecting the relevance of search results.