Enterprise Search in Japanese: Why We Switched from Kuromoji to N-gram
The Problem: “Search Results Are Wrong”
On a project, a client came to us with a complaint:
“The search results don’t make sense.”
Results were showing up that didn’t match the search terms.
Context
- Not a DB search — ElasticSearch
- Data volume too large for an RDBMS
- Japanese-language search
At this point, I already knew this would be tricky.
Root Cause: Kuromoji
After investigation, the cause was straightforward.
👉 They were using Kuromoji.
Kuromoji is a morphological analyzer, which means:
- It breaks text into word units
- It analyzes based on context
In other words:
👉 It’s built for “text comprehension,” not “search”
What Was Happening
For example, even when the search term was an exact match:
- Tokenization differed
- Tokens changed
- Unintended matches occurred
The result:
👉 “Why is this showing up?” 👉 “Why isn’t this showing up?”
Conclusion: Not Suited for General Search
Kuromoji is powerful, but:
👉 It’s not suited for general search (partial match, fuzzy search)
Especially in enterprise systems, users expect:
- Near-exact match behavior
- Partial matching
- Intuitive search results
Kuromoji doesn’t deliver that.
Solution: Switch to N-gram
The fix was simple:
👉 Switch to n-gram
This gave us:
- Working partial matches
- Search results that matched user expectations
The Real Challenge
Since this was ElasticSearch:
👉 Changing the analyzer = full reindex required
That means:
- Reloading all data
- Risk of downtime
Zero-Downtime Release with Aliases
The technique we used:
👉 Index aliases
Here’s the process:
- Create a new index (with n-gram analyzer)
- Reindex the data
- Verify behavior in advance
- Switch the alias
👉 The actual release takes a split second
Why This Matters
With this approach:
- You can test beforehand
- Zero production impact
- Easy rollback
Summary
- Kuromoji is for “text analysis”
- N-gram is for “search”
- Japanese search requires choosing the right tool for the job
One Takeaway
👉 Japanese enterprise search is 90% decided by your technology choice
Side Note (From Experience)
Kuromoji is powerful when you understand it properly.
But if you just default to “it’s Japanese, so use Kuromoji” — things will break.