Perform accent-insensitive search using OpenSearch
Accent-insensitive search in OpenSearch is not just an analyzer tweak; it is an index-design decision. The moment you introduce ASCII folding for user-facing text, you are defining how tokens will be stored, matched, and ranked. That makes the choice between a text analyzer and a keyword normalizer important: the former improves recall at query time, while the latter determines whether aggregations, faceting, and exact-value rollups behave consistently.
The architectural implication is that search and analytics often need different representations of the same field. A multi-field mapping lets the same content serve both use cases, but only if the pipeline is planned up front. If you add diacritic handling later, expect reindexing, refreshed dashboards, and possible application changes where exact-match logic previously depended on raw Unicode values. This is a common source of technical debt in search platforms.
There is also a relevance and observability trade-off. Preserving the original token alongside the folded form can improve matching breadth, but it also changes how candidates are scored and can surface mixed results that need validation with real user queries. Teams should test for language-specific behavior, because diacritic folding is broadly useful but not a substitute for locale-aware search rules in every domain.
For platform teams, the practical takeaway is to treat accent handling as part of the contract between ingestion, search, and reporting layers. Define which fields are searchable, aggregatable, or both; standardize the mapping early; and verify that downstream consumers interpret normalized buckets and query results correctly. That keeps search flexible without creating hidden inconsistencies across the stack.
Solution overview
Lucene Analyzers are Java libraries that are used to analyze text while indexing and searching documents. These analyzers consist of tokenizers and filters. The tokenizers split the incoming text into one or more tokens, and the filters are used to transform the tokens by modifying or removing the unnecessary characters. OpenSearch supports custom analyzers, which enable you to configure different combinations of tokenizers and filters. It can consist of character filters, tokenizers, and token filters. In order to enable our diacritic-insensitive search, we configure custom analyzers that use the ASCII folding token filter. ASCIIFolding is a method used to covert alphabetic, numeric, and symbolic Unicode characters that arenโt in the first 127 ASCII characters (the Basic Latin Unicode block) into their ASCII equivalents, if one exists. For example, the filter changes โร โ to โaโ. This allows search engines to return results agnostic of the accent. In this post, we configure accent-insensitive search using the ASCIIFolding filter supported in OpenSearch Service. We ingest a set of European movie names with diacritics and verify search results with and without the diacritics.Create an index with a custom analyzer
We first create the indexasciifold_movies with custom analyzer custom_asciifolding:
PUT /asciifold_movies
{
"settings": {
"analysis": {
"analyzer": {
"custom_asciifolding": {
"tokenizer": "standard",
"filter": [
"my_ascii_folding"
]
}
},
"filter": {
"my_ascii_folding": {
"type": "asciifolding",
"preserve_original": true
}
}
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"analyzer": "custom_asciifolding",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
Ingest sample data
Next, we ingest sample data with Latin characters into the indexasciifold_movies:
POST _bulk
{ "index" : { "_index" : "asciifold_movies", "_id":"1"} }
{ "title" : "Jour de fรชte"}
{ "index" : { "_index" : "asciifold_movies", "_id":"2"} }
{ "title" : "La gloire de mon pรจre" }
{ "index" : { "_index" : "asciifold_movies", "_id":"3"} }
{ "title" : "Le roi et lโoiseau" }
{ "index" : { "_index" : "asciifold_movies", "_id":"4"} }
{ "title" : "รtre et avoir" }
{ "index" : { "_index" : "asciifold_movies", "_id":"5"} }
{ "title" : "Kirikou et la sorciรจre"}
{ "index" : { "_index" : "asciifold_movies", "_id":"6"} }
{ "title" : "Seรฑora Acero"}
{ "index" : { "_index" : "asciifold_movies", "_id":"7"} }
{ "title" : "Seรฑora garรงon"}
{ "index" : { "_index" : "asciifold_movies", "_id":"8"} }
{ "title" : "Jour de fete"}
Query the index
Now we query theasciifold_movies index for words with and without Latin characters.
Our first query uses an accented character:
GET asciifold_movies/_search
{
ย ย "query": {
ย ย ย "match": {
ย ย ย ย "title": "fรชte"
ย ย ย }
ย ย }
}
GET asciifold_movies/_search
{
ย ย "query": {
ย ย ย "match": {
ย ย ย ย "title": "fete"
ย ย ย }
ย ย }
}
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 0.7361701,
"hits": [
{
"_index": "asciifold_movies",
"_id": "8",
"_score": 0.7361701,
"_source": {
"title": "Jour de fete"
}
},
{
"_index": "asciifold_movies",
"_id": "1",
"_score": 0.42547938,
"_source": {
"title": "Jour de fรชte"
}
}
]
}
}
Enable aggregations for fields with accents
Now that we have enabled accent-insensitive search, letโs look at how we can make aggregations work with accents. Try the following query on the index:GET asciifold_movies/_search
{
ย ย "size": 0,
ย ย "aggs": {
ย ย ย "test": {
ย ย ย ย "terms": {
ย ย ย ย ย "field": "title.keyword"
ย ย ย ย }
ย ย ย }
ย ย }
}
"aggregations" : {
"test" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Jour de fete",
"doc_count" : 1
},
{
"key" : "Jour de fรชte",
"doc_count" : 1
},
{
"key" : "Kirikou et la sorciรจre",
"doc_count" : 1
},
{
"key" : "La gloire de mon pรจre",
"doc_count" : 1
},
{
"key" : "Le roi et lโoiseau",
"doc_count" : 1
},
{
"key" : "Seรฑora Acero",
"doc_count" : 1
},
{
"key" : "Seรฑora garรงon",
"doc_count" : 1
},
{
"key" : "รtre et avoir",
"doc_count" : 1
}
]
}
}
Create accent-insensitive aggregations using a normalizer
In the previous example, the aggregation returns two different buckets, one for โJour de fรชteโ and one for โJour de fete.โ We can enable aggregations to create one bucket for the field, regardless of the diacritics. This is achieved using the normalizer filter. The normalizer supports a subset of character and token filters. Using just the defaults, the normalizer filter is a simple way to standardize Unicode text in a language-independent way for search, thereby standardizing different forms of the same character in Unicode and allowing diacritic-agnostic aggregations. Letโs modify the index mapping to include the normalizer. Delete the previous index, then create a new index with the following mapping and ingest the same dataset:PUT /asciifold_movies
{
ย ย "settings": {
ย ย ย "analysis": {
ย ย ย ย "analyzer": {
ย ย ย ย ย "custom_asciifolding": {
ย ย ย ย ย ย "tokenizer": "standard",
ย ย ย ย ย ย "filter": [
ย ย ย ย ย ย ย "my_ascii_folding"
ย ย ย ย ย ย ]
ย ย ย ย ย }
ย ย ย ย },
ย ย ย ย "filter": {
ย ย ย ย ย "my_ascii_folding": {
ย ย ย ย ย ย "type": "asciifolding",
ย ย ย ย ย ย "preserve_original": true
ย ย ย ย ย }
ย ย ย ย },
ย ย ย ย "normalizer": {
ย ย ย ย ย "custom_normalizer": {
ย ย ย ย ย ย "type": "custom",
ย ย ย ย ย ย "filter": "asciifolding"
ย ย ย ย ย }
ย ย ย ย }
ย ย ย }
ย ย },
ย ย "mappings": {
ย ย ย "properties": {
ย ย ย ย "title": {
ย ย ย ย ย "type": "text",
ย ย ย ย ย "analyzer": "custom_asciifolding",
ย ย ย ย ย "fields": {
ย ย ย ย ย ย "keyword": {
ย ย ย ย ย ย ย "type": "keyword",
ย ย ย ย ย ย ย "ignore_above": 256,
ย ย ย ย ย ย ย "normalizer": "custom_normalizer"
ย ย ย ย ย ย }
ย ย ย ย ย }
ย ย ย ย }
ย ย ย }
ย ย }
}
GET asciifold_movies/_search
{
ย ย "size": 0,
ย ย "aggs": {
ย ย ย "test": {
ย ย ย ย "terms": {
ย ย ย ย ย "field": "title.keyword"
ย ย ย ย }
ย ย ย }
ย ย }
}
"aggregations" : {
ย ย ย "test" : {
ย ย ย ย "doc_count_error_upper_bound" : 0,
ย ย ย ย "sum_other_doc_count" : 0,
ย ย ย ย "buckets" : [
ย ย ย ย ย {
ย ย ย ย ย ย "key" : "Jour de fete",
ย ย ย ย ย ย "doc_count" : 2
ย ย ย ย ย },
ย ย ย ย ย {
ย ย ย ย ย ย "key" : "Etre et avoir",
ย ย ย ย ย ย "doc_count" : 1
ย ย ย ย ย },
ย ย ย ย ย {
ย ย ย ย ย ย "key" : "Kirikou et la sorciere",
ย ย ย ย ย ย "doc_count" : 1
ย ย ย ย ย },
ย ย ย ย ย {
ย ย ย ย ย ย "key" : "La gloire de mon pere",
ย ย ย ย ย ย "doc_count" : 1
ย ย ย ย ย },
ย ย ย ย ย {
ย ย ย ย ย ย "key" : "Le roi et l'oiseau",
ย ย ย ย ย ย "doc_count" : 1
ย ย ย ย ย },
ย ย ย ย ย {
ย ย ย ย ย ย "key" : "Senora Acero",
ย ย ย ย ย ย "doc_count" : 1
ย ย ย ย ย },
ย ย ย ย ย {
ย ย ย ย ย ย "key" : "Senora garcon",
ย ย ย ย ย ย "doc_count" : 1
ย ย ย ย ย }
ย ย ย ย ]
ย ย ย }
ย ย }
Summary
In this post, we showed how to enable accent-insensitive search and aggregations by designing the index mapping to do ASCII folding for search tokens and normalize the keyword field for aggregations. You can use the OpenSearch query DSL to implement a range of search features, providing a flexible foundation for structured and unstructured search applications. The Open Source OpenSearch community has also extended the product to enable support for natural language processing, machine learning algorithms, custom dictionaries, and a wide variety of other plugins. If you have feedback about this post, submit it in the comments section. If you have questions about this post, start a new thread on the Amazon OpenSearch Service forum or contact AWS Support.About the Author
Aruna Govindaraju is an Amazon OpenSearch Specialist Solutions Architect and has worked with many commercial and open-source search engines. She is passionate about search, relevancy, and user experience. Her expertise with correlating end-user signals with search engine behavior has helped many customers improve their search experience. Her favorite pastime is hiking the New England trails and mountains.Build a search application with Amazon OpenSearch Serverless
Enjoyed this article? Sign up for our newsletter to receive regular insights and stay connected.
