The IK analyzer plugin (analysis-ik) provides Chinese text tokenization for Alibaba Cloud Elasticsearch with multiple built-in dictionary types. You can customize or extend dictionaries to improve tokenization accuracy and dynamically load dictionary files from Object Storage Service (OSS) for remote management.
Background information
The IK analyzer plugin consists of three components: tokenizers, dictionary files, and update mechanisms.
The IK analyzer plugin version must match the Elasticsearch cluster version. For example, if your cluster runs version 8.17, the IK analyzer plugin is also version 8.17.
-
Tokenizers: Split Chinese text into meaningful tokens and control tokenization granularity.
-
Dictionary files: Provide the vocabulary that tokenizers rely on for segmentation. Dictionaries support customization and extension.
-
Dictionary update methods: Support both cold and hot updates, letting you adjust dictionaries flexibly to meet business requirements.
Tokenization rules
The IK analyzer supports two tokenization modes:
-
ik_max_word: Splits text at the finest granularity. Ideal for term-based queries.
-
ik_smart: Splits text at a coarser granularity. Ideal for phrase-based queries.
Dictionary types
The IK analyzer supports the following dictionary types.
|
Dictionary type |
Description |
File requirements |
Supported update methods |
|
Main dictionary |
The default main dictionary is When you configure a main dictionary for an ES index, the cluster matches incoming data against this dictionary during indexing. Matched terms become searchable via corresponding keywords. |
One word per line, saved as a |
|
|
Stop word dictionary |
The default stop word dictionary is When you configure a stop word dictionary for an ES index, the cluster filters out matched terms during indexing. Filtered terms are excluded from the inverted index. |
||
|
Preposition dictionary |
The default preposition dictionary is |
Not applicable |
|
|
Quantifier dictionary |
The default quantifier dictionary is |
||
|
suffix.dic |
Stores suffix terms to help the tokenizer split words with suffixes. |
Not applicable |
Update not supported |
|
surname.dic |
Stores common Chinese surnames to help the tokenizer recognize names. |
Dictionary update methods
Update dictionaries when the defaults do not meet your needs. The IK analyzer supports the following methods.
|
Update method |
Description |
Scenarios |
|
Restarts the ES cluster to apply dictionary changes to all nodes. Uploaded files are delivered to all ES nodes, and the nodes restart. Changes take effect after the restart completes. |
|
|
Note
Only supports updating main or stop word dictionaries. Important
When you configure hot update for the first time or change the dictionary file list (add, delete, or rename dictionary files), the cluster restarts. Only subsequent content-only changes to existing dictionary files with unchanged file names take effect dynamically without a restart. Schedule these operations during off-peak hours to avoid impacting your business. |
|
Prerequisites
-
The instance is in Normal state. View the instance status on the details page.
NoteThis topic uses an Alibaba Cloud ES instance running version
7.10.0. Console interfaces and features may differ across versions. -
(Optional) If you plan to update dictionaries, complete the following steps first.
-
To update using Upload OSS File: First create an OSS bucket and upload the required dictionary files.
-
To update using Upload On-premises File: Save the required dictionary files to your local machine first.
-
Update IK dictionaries
Update IK dictionaries when the defaults do not meet your needs. Review the update method before proceeding. For indexes already configured with IK tokenization, dictionary updates apply only to new data. To apply changes to existing data, recreate the index.
Cold update
To perform a cold update:
Cold updates restart the cluster. Perform this during off-peak hours.
-
Go to the instance details page.
-
Log on to the Alibaba Cloud Elasticsearch console.
-
In the navigation pane on the left, click Elasticsearch Clusters.
-
In the top menu bar, select a resource group and region.
-
In the Elasticsearch instance list, click the target instance ID to go to its details page.
-
-
Go to the cold update page for the
analysis-ikplugin.-
In the navigation pane on the left, choose .
-
On the Built-in Plug-ins tab, find the
analysis-ikplugin and click Standard Update in the Actions column.
-
-
Perform the cold update.
-
In the Configure IK Dictionaries - Standard Update dialog box, click Edit next to the target dictionary, upload the required dictionary file as instructed, then click Save.
You can upload dictionary files using one of the following methods:
-
Upload On-premises File: Click the
icon or drag and drop your local file as instructed. -
Upload OSS File: Enter the bucket name and dictionary file name, then click Add.
-
The bucket and Alibaba Cloud ES instance must be in the same region.
-
OSS dictionary files are not automatically synchronized. If the source file changes, perform a dictionary update to apply changes.
-
Note-
Each dictionary type supports only one
DIC-format file. The uploaded file replaces the original dictionary. -
Dictionary file names must end with
.dic. File names can contain letters, digits, and underscores, and must not exceed 30 characters. -
To restore a dictionary to its default file, download the default file and re-upload it. Obtain the default dictionary files from the following links:
-
-
Select the risk acknowledgment and click OK to restart the instance.
After the instance restarts, the dictionary update is complete.
-
-
(Optional) Test whether the dictionary update took effect.
-
Click the
icon in the upper-left corner and choose to open the code editor.Run the following code to perform coarse-grained tokenization on the input text
Chinese character input method for computers.NoteIn practice, replace the
textvalue with a word from your dictionary.GET _analyze { "analyzer": "ik_smart", "text": "Chinese character input method for computers" }The expected response is as follows.
{ "tokens" : [ { "token" : "computer", "start_offset" : 0, "end_offset" : 3, "type" : "CN_WORD", "position" : 0 }, { "token" : "Chinese character input", "start_offset" : 3, "end_offset" : 7, "type" : "CN_WORD", "position" : 1 }, { "token" : "method", "start_offset" : 7, "end_offset" : 9, "type" : "CN_WORD", "position" : 2 } ] }
Hot update
To perform a hot update:
Content-only changes to existing dictionary files with unchanged file names do not restart the cluster. If dictionary file names or the file count changes, or if you are configuring hot update for the first time, the cluster restarts. Perform this operation during off-peak hours to minimize business impact. After the restart, the dictionary takes effect automatically.
-
Go to the instance details page.
-
Log on to the Alibaba Cloud Elasticsearch console.
-
In the navigation pane on the left, click Elasticsearch Clusters.
-
In the top menu bar, select a resource group and region.
-
In the Elasticsearch instance list, click the target instance ID to go to its details page.
-
-
Go to the hot update page for the
analysis-ikplugin.-
In the navigation pane on the left, choose .
-
On the Built-in Plug-ins tab, find the
analysis-ikplugin and click Rolling Update in the Actions column.
-
-
Perform the hot update.
-
In the Configure IK Dictionaries - Rolling Update dialog box, click Edit next to the target dictionary, upload the required dictionary file as instructed, then click Save.
You can upload dictionary files using one of the following methods:
-
Upload On-premises File: Click the
icon or drag and drop your local file as instructed. -
Upload OSS File: Enter the bucket name and dictionary file name, then click Add.
-
The bucket and Alibaba Cloud ES instance must be in the same region.
-
OSS dictionary files are not automatically synchronized. If the source file changes, perform a dictionary update to apply changes.
-
Note-
You can upload multiple dictionary files. File names must end with
.dic. File names can contain letters, digits, and underscores, and must not exceed 30 characters. -
To modify an uploaded dictionary file, click the
icon next to it to download and edit the file. Then delete the original file and re-upload the updated one. After deleting the original file, click Save; otherwise, the system reports that a file with the same name already exists.
-
-
Click OK and wait for ES nodes to finish loading the dictionary.
ES nodes load dictionary files automatically. Loading times vary across nodes — wait until all nodes finish.
-
-
(Optional) Test whether the dictionary update took effect.
-
Click the
icon in the upper-left corner and choose to open the code editor.Run the following code to perform coarse-grained tokenization on the input text
Chinese character input method for computers.NoteIn practice, replace the
textvalue with a word from your dictionary.GET _analyze { "analyzer": "ik_smart", "text": "Chinese character input method for computers" }The expected response is as follows.
{ "tokens" : [ { "token" : "computer", "start_offset" : 0, "end_offset" : 3, "type" : "CN_WORD", "position" : 0 }, { "token" : "Chinese character input", "start_offset" : 3, "end_offset" : 7, "type" : "CN_WORD", "position" : 1 }, { "token" : "method", "start_offset" : 7, "end_offset" : 9, "type" : "CN_WORD", "position" : 2 } ] }
Use the IK analyzer plugin
Tokenize text using the IK tokenizer with a Pinyin filter.
-
Go to the Kibana Developer Tools page for your ES instance.
-
Click the
icon in the upper-left corner and choose to open the code editor.
-
Create an index and configure the IK tokenizer and Pinyin filter.
Run the following command to create the
ik_pinyinindex with a customik_pinyin_analyzer. This analyzer usesik_max_wordtokenization and a Pinyin filter to convert Chinese terms into Pinyin.NoteThe Pinyin filter converts tokens to Pinyin after Chinese tokenization completes.
PUT ik_pinyin { "settings":{ "analysis": { "filter": { "my_pinyin" : { "type" : "pinyin", "keep_separate_first_letter" : false, "keep_full_pinyin" : true, "keep_original" : true, "limit_first_letter_length" : 16, "lowercase" : true, "remove_duplicated_term" : true } }, "analyzer": { "ik_pinyin_analyzer": { "type": "custom", "tokenizer": "ik_max_word", "filter": ["my_pinyin"] } } } }, "mappings":{ "properties":{ "text":{ "type" : "text", "analyzer" : "ik_pinyin_analyzer" } } } }Key parameters are described below.
-
Pinyin filter (the
filter)NoteAll available parameters are documented in Pinyin Analysis for Elasticsearch.
Parameter
Description
my_pinyin
The name of the custom Pinyin filter.
type
Set to
pinyinto use a Pinyin filter.keep_separate_first_letter
Set to
falseto exclude individual first-letter tokens for each character.keep_full_pinyin
Set to
trueto include full Pinyin forms.keep_original
Set to
trueto retain the original input text.limit_first_letter_length
Set to
16to limit first-letter sequences to 16 characters.lowercase
Set to
trueto output Pinyin in lowercase.remove_duplicated_term
Set to
trueto remove duplicate terms, such as avoiding"zh, zh". -
Analyzer (the
analyzer):Parameter
Description
ik_pinyin_analyzer
The name of the custom analyzer.
type
Set to
customto define a custom analyzer.tokenizer
Set to
ik_max_wordto split text at the finest granularity.filter
Set to
my_pinyinto apply themy_pinyinPinyin filter.A successful result is as follows.
{ "acknowledged": true, "shards_acknowledged": true, "index": "ik_pinyin" }
-
-
Verify tokenization results.
Run the following code to tokenize the input text
This is a test.GET ik_pinyin/_analyze { "text": "This is a test", "analyzer": "ik_pinyin_analyzer" }The expected response is as follows.
{ "tokens" : [ { "token" : "zhe", "start_offset" : 0, "end_offset" : 2, "type" : "CN_WORD", "position" : 0 }, { "token" : "this is", "start_offset" : 0, "end_offset" : 2, "type" : "CN_WORD", "position" : 0 }, { "token" : "zs", "start_offset" : 0, "end_offset" : 2, "type" : "CN_WORD", "position" : 0 }, { "token" : "shi", "start_offset" : 0, "end_offset" : 2, "type" : "CN_WORD", "position" : 1 }, { "token" : "ge", "start_offset" : 2, "end_offset" : 3, "type" : "CN_CHAR", "position" : 2 }, { "token" : "one", "start_offset" : 2, "end_offset" : 3, "type" : "CN_CHAR", "position" : 2 }, { "token" : "g", "start_offset" : 2, "end_offset" : 3, "type" : "CN_CHAR", "position" : 2 }, { "token" : "ce", "start_offset" : 3, "end_offset" : 5, "type" : "CN_WORD", "position" : 3 }, { "token" : "shi", "start_offset" : 3, "end_offset" : 5, "type" : "CN_WORD", "position" : 4 }, { "token" : "test", "start_offset" : 3, "end_offset" : 5, "type" : "CN_WORD", "position" : 4 }, { "token" : "cs", "start_offset" : 3, "end_offset" : 5, "type" : "CN_WORD", "position" : 4 } ] }
Optimize tokenization for alphanumeric mixed words
When you use the ik_max_word tokenizer, alphanumeric mixed strings such as fawjh6bcm may not be tokenized effectively for search. To improve recall, set enable_single_word to true. This splits mixed words into single-character tokens, enabling character-level matching.
The following example creates a custom analyzer with enable_single_word enabled:
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"ik_single_char_analyzer": {
"type": "custom",
"tokenizer": "my_ik_tokenizer"
}
},
"tokenizer": {
"my_ik_tokenizer": {
"type": "ik_max_word",
"enable_single_word": true
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "ik_single_char_analyzer"
}
}
}
}
|
Parameter |
Description |
|
enable_single_word |
Set to |
This parameter is also supported in Alibaba Cloud Elasticsearch Serverless environments.
Use the ngram tokenizer for mixed Chinese-English search
When searching for concatenated English model numbers (such as jh6bcm) mixed with Chinese text, the IK analyzer alone may not produce effective tokens for partial matching. In this case, use the ngram tokenizer to complement or replace the IK analyzer.
The ngram tokenizer breaks text into contiguous character sequences of configurable length, enabling substring matching.
The following example creates an index that uses the ngram tokenizer:
PUT my_ngram_index
{
"settings": {
"analysis": {
"tokenizer": {
"my_ngram_tokenizer": {
"type": "ngram",
"min_gram": 2,
"max_gram": 3,
"token_chars": ["letter", "digit"]
}
},
"analyzer": {
"ngram_analyzer": {
"type": "custom",
"tokenizer": "my_ngram_tokenizer"
}
}
}
},
"mappings": {
"properties": {
"model_number": {
"type": "text",
"analyzer": "ngram_analyzer"
}
}
}
}
|
Parameter |
Description |
|
min_gram |
The minimum character length of a gram. Default: |
|
max_gram |
The maximum character length of a gram. Default: |
|
token_chars |
The character classes to include in tokens. Valid values: |
For more information about the ngram tokenizer configuration, see Ngram tokenizer.
FAQ
Uppercase words in synonym files cause errors. What do I do?
The IK analyzer is case-sensitive when processing synonym files. If a synonym file contains uppercase words (such as IT), parsing errors may occur during indexing.
You can resolve this issue using either of the following methods.
-
Convert all synonyms to lowercase: Edit your synonym file and convert all entries to lowercase before uploading.
-
Add a lowercase filter to the analyzer: Add a
lowercasefilter before the synonym filter in your analyzer configuration to normalize text before synonym matching. Example:PUT my_index { "settings": { "analysis": { "filter": { "my_synonym_filter": { "type": "synonym", "synonyms_path": "your_synonyms.txt" } }, "analyzer": { "ik_synonym_analyzer": { "type": "custom", "tokenizer": "ik_max_word", "filter": ["lowercase", "my_synonym_filter"] } } } } }ImportantThe
lowercasefilter must appear before the synonym filter in the filter chain to ensure text is converted to lowercase before synonym matching occurs.
References
-
API for hot-updating IK dictionaries: UpdateHotIkDicts
-
API for cold-updating IK dictionaries: UpdateDict