Link Search Menu Expand Document Documentation Menu

Kuromoji analyzer

The kuromoji analyzer provides morphological analysis for Japanese text using the Kuromoji library backed by the IPAdic dictionary. It segments Japanese sentences into meaningful tokens, removes common stop words and grammatical particles, and returns tokens in their dictionary base form.

To use the kuromoji analyzer or any Kuromoji components, you must first install the analysis-kuromoji plugin.

Installing the plugin

Install the plugin on all nodes and then restart the cluster:

bin/opensearch-plugin install analysis-kuromoji

For more information about installing plugins, see Installing plugins.

Kuromoji plugin components

The analysis-kuromoji plugin provides the following components that you can use independently or combine in custom analyzers.

Analyzers

Analyzer Description
kuromoji Built-in Japanese analyzer. Segments text, removes stop words, and normalizes tokens to their base form.
kuromoji_completion Analyzer designed for autocomplete of Japanese text. Generates the original Japanese tokens along with their romaji reading variants.

Tokenizer

Tokenizer Description
kuromoji_tokenizer Dictionary-based Japanese tokenizer with configurable segmentation modes.

Character filter

Character filter Description
kuromoji_iteration_mark Normalizes Japanese iteration marks (々, ゝ, ゞ, ヽ, and ヾ) by expanding them to the character they repeat.

Token filters

Token filter Description
kuromoji_baseform Replaces inflected tokens with their dictionary base form.
kuromoji_part_of_speech Removes tokens whose part-of-speech tag is in a configured stop-tag list.
kuromoji_readingform Replaces each token with its katakana or romaji reading.
kuromoji_stemmer Removes trailing long vowel marks (ー) from katakana words.
ja_stop Removes Japanese stop words from the token stream.
kuromoji_number Converts Japanese numeral expressions to standard Arabic numerals.
kuromoji_completion Generates romaji reading variants for katakana tokens to support autocomplete.

Analysis pipeline

The kuromoji analyzer applies the following components to input text, in order:

  1. The cjk_width character filter converts full-width ASCII variants to their standard ASCII equivalents and half-width katakana variants to full-width katakana before tokenization.
  2. The kuromoji_tokenizer in search mode segments text using the IPAdic dictionary, splitting long compound words into their sub-tokens.
  3. The kuromoji_baseform token filter replaces inflected verb and adjective forms with their dictionary forms (for example, 食べた becomes 食べる).
  4. The kuromoji_part_of_speech token filter removes grammatical particles (助詞), auxiliary verbs (助動詞), punctuation (記号), and other stop tags.
  5. The ja_stop token filter removes common Japanese stop words.
  6. The kuromoji_stemmer token filter removes trailing long vowel marks (ー) from katakana words of four or more characters (for example, コンピューター becomes コンピュータ).
  7. The lowercase token filter converts any Latin characters to lowercase.

Parameters

The following table lists the parameters for the kuromoji analyzer.

Parameter Data type Description
mode String Tokenization mode. Valid values are normal, search (default), and extended. See Tokenization modes for details.
user_dictionary String Path to a custom user dictionary file (CSV format) placed in the OpenSearch config directory. Optional.
user_dictionary_rules Array of strings Inline custom dictionary rules in CSV format. Each entry is <text>,<subtokens>,<readings>,<part of speech>. Optional. Cannot be used together with user_dictionary.
stopwords String or array of strings Stop words to use. Accepts _japanese_ (the built-in Japanese stop set), an array of explicit stop words, or a path to a stop word file. Default is _japanese_.

For the full list of stop words in the built-in stop set, see stopwords.txt in the Lucene repository.

Tokenization modes

The tokenizer mode controls how compound and unknown words are segmented.

Mode Effect
normal Standard dictionary-based segmentation. Compound words are kept as a single token. Unknown words are kept as a single token.
search (default) Like normal, but compound words (for example, place names) are also split into their sub-components, improving recall for search queries.
extended Like normal, but unknown words are split into unigrams (individual characters), ensuring that every character is indexed.

Example: Basic usage

The following example creates an index that uses the built-in kuromoji analyzer:

PUT /japanese-index
{
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "kuromoji"
      }
    }
  }
}

Test the analyzer with a Japanese sentence meaning “I studied at the Tokyo library”:

POST /_analyze
{
  "analyzer": "kuromoji",
  "text": "東京の図書館で勉強しました"
}

The analyzer returns base-form tokens with particles and auxiliary verbs removed:

{
  "tokens": [
    {
      "token": "東京",
      "start_offset": 0,
      "end_offset": 2,
      "type": "word",
      "position": 0
    },
    {
      "token": "図書館",
      "start_offset": 3,
      "end_offset": 6,
      "type": "word",
      "position": 2
    },
    {
      "token": "勉強",
      "start_offset": 7,
      "end_offset": 9,
      "type": "word",
      "position": 4
    }
  ]
}

Example: Custom Kuromoji analyzer

The following example creates a custom kuromoji analyzer that uses user_dictionary_rules to register inline custom terms:

PUT /japanese-custom-index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_kuromoji": {
          "type": "kuromoji",
          "mode": "search",
          "user_dictionary_rules": [
            "東京スカイツリー,東京 スカイツリー,トウキョウ スカイツリー,カスタム名詞"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "my_kuromoji"
      }
    }
  }
}

Test the custom analyzer with a sentence containing the registered term (“I went to Tokyo Skytree”):

POST /japanese-custom-index/_analyze
{
  "analyzer": "my_kuromoji",
  "text": "東京スカイツリーに行きました"
}

The analyzer uses the custom dictionary rule to segment 東京スカイツリー into 東京 and スカイツリー. The default katakana stemmer (kuromoji_stemmer) removes the trailing long vowel mark from スカイツリー to produce スカイツリ. The kuromoji_part_of_speech filter removes the particle and the auxiliary verbs まし and , and kuromoji_baseform normalizes 行き to its base form 行く:

{
  "tokens": [
    {
      "token": "東京",
      "start_offset": 0,
      "end_offset": 2,
      "type": "word",
      "position": 0
    },
    {
      "token": "スカイツリ",
      "start_offset": 2,
      "end_offset": 8,
      "type": "word",
      "position": 1
    },
    {
      "token": "行く",
      "start_offset": 9,
      "end_offset": 11,
      "type": "word",
      "position": 3
    }
  ]
}

Kuromoji completion analyzer

The kuromoji_completion analyzer is designed for autocomplete use cases. It generates both the original Japanese tokens and their romaji (Latin script) reading variants, allowing users to search for Japanese content by typing in either Japanese characters or their romanized equivalents. In query mode, the analyzer also assembles partial input from an input method editor (IME) into a single token before romanizing it.

The following table lists the parameters for the kuromoji_completion analyzer.

Parameter Data type Description
mode String Controls how tokens are generated. Valid values are index (default) and query. Both modes expand katakana tokens into their original form plus all romaji variants. The query mode applies two additional rules for handling partial IME input: it concatenates consecutive kana tokens into a single token before romanizing, and it merges a kana token with a trailing lowercase alphabet token that represents a partially typed IME keystroke (for example, サッ followed by k becomes サッk).
user_dictionary String Path to a custom user dictionary file. Optional.
user_dictionary_rules Array of strings Inline custom dictionary rules. Optional.

Use query mode in the search analyzer so that partial IME input typed by a user is correctly assembled before romanization.

Example: Autocomplete using the Kuromoji completion analyzer

The following example configures an index with different completion analyzers used at index time and search time:

PUT /autocomplete-index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "kuromoji_index_analyzer": {
          "type": "kuromoji_completion",
          "mode": "index"
        },
        "kuromoji_search_analyzer": {
          "type": "kuromoji_completion",
          "mode": "query"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "suggest": {
        "type": "text",
        "analyzer": "kuromoji_index_analyzer",
        "search_analyzer": "kuromoji_search_analyzer"
      }
    }
  }
}

For more details about the completion token filter, see Kuromoji completion token filter.

Using the Kuromoji and ICU plugins together

For the most thorough Japanese text analysis, combine the analysis-kuromoji and analysis-icu plugins. ICU contributes Unicode normalization of full-width and half-width characters and comprehensive character folding that the Kuromoji components alone do not provide.

Both analysis-kuromoji and analysis-icu must be installed before creating an index that uses components from both plugins.

The following example creates a custom analyzer combining both plugins. The icu_normalizer character filter converts full-width characters to their ASCII equivalents before tokenization (for example, 300 becomes 300), keeping numeric sequences as single tokens. The kuromoji_iteration_mark character filter expands Japanese iteration marks (for example, 時々 becomes 時時) so the tokenizer can look them up in the dictionary correctly:

PUT /japanese-icu-index
{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "japanese_icu_analyzer": {
            "char_filter": [
              "icu_normalizer",
              "kuromoji_iteration_mark"
            ],
            "tokenizer": "kuromoji_tokenizer",
            "filter": [
              "kuromoji_baseform",
              "kuromoji_part_of_speech",
              "ja_stop",
              "kuromoji_stemmer",
              "lowercase"
            ]
          }
        }
      }
    }
  }
}

Test the combined analyzer with a sentence containing full-width digits and a long vowel mark (“The computer processes 300 documents”):

POST /japanese-icu-index/_analyze
{
  "analyzer": "japanese_icu_analyzer",
  "text": "コンピューターは300件の文書を処理します"
}

The analyzer applies the following transformations:

  • icu_normalizer converts the full-width digits 300 to 300 before tokenization.
  • kuromoji_stemmer removes the trailing long vowel mark, converting コンピューター to コンピュータ.
  • kuromoji_part_of_speech removes the particles , , and , along with the auxiliary verb ます.
  • ja_stop removes because it appears in the _japanese_ stop set.
  • 300 is kept as a single token, and 文書 and 処理 are returned in base form.

The response appears as follows:

{
  "tokens": [
    {
      "token": "コンピュータ",
      "start_offset": 0,
      "end_offset": 7,
      "type": "word",
      "position": 0
    },
    {
      "token": "300",
      "start_offset": 8,
      "end_offset": 11,
      "type": "word",
      "position": 2
    },
    {
      "token": "件",
      "start_offset": 11,
      "end_offset": 12,
      "type": "word",
      "position": 3
    },
    {
      "token": "文書",
      "start_offset": 13,
      "end_offset": 15,
      "type": "word",
      "position": 5
    },
    {
      "token": "処理",
      "start_offset": 16,
      "end_offset": 18,
      "type": "word",
      "position": 7
    }
  ]
}