Remove Punctuation in Elasticsearch

Practical ways to remove or ignore punctuation during Elasticsearch indexing and search, with steps, verification checks, and common troubleshooting fixes.

Before you start

Elasticsearch does not store punctuation as a separate feature that you can simply switch off. The standard analyzer removes most punctuation while tokenizing text, but punctuation is generally removed as part of a broader character filter or token filter pipeline. Whether you need a change depends on where you are working: a custom index mapping lets you control analysis, while an index that already contains data may require reindexing after the mapping changes. Check your Elasticsearch version and review the current mapping before editing it.

Step-by-step instructions

Use these steps when you want punctuation removed or normalized during indexing and search. The standard analyzer is usually sufficient because it drops characters such as periods, commas, quotes, and brackets when they are not part of a token.

Check the current analyzer

Review the index mapping to see which analyzer is applied to the field. If no analyzer is specified, Elasticsearch applies the standard analyzer by default to text fields. If a custom analyzer is present, inspect it to identify the character filters and token filters that affect punctuation.

Test the analyzer output

Use the Analyze API before changing an index. Send sample text such as a filename, question, or camera model name and look at the returned tokens. If punctuation tokens still appear, a custom analyzer or unusual mapping is likely overriding the default behavior.

Use a character filter to remove punctuation

A mapping character filter can replace or remove matching characters. Use a pattern such as a Unicode punctuation class to strip punctuation early in the analysis chain. Because punctuation classes can differ across Elasticsearch versions, test the pattern against real sample text before applying it.

Apply the analyzer in a mapping

Define a custom analyzer with the chosen character filter and tokenizer, then set it on the relevant field. For existing indices, update the mapping is only possible for compatible changes. Changing an analyzer on a field that already contains documents normally requires creating a new index and reindexing the data.

Keep search and index analysis aligned

Use the same custom analyzer for both indexing and query-time analysis unless you have a specific reason to separate them. Without search_analyzer, the index analyzer is also used for search. Keeping them aligned prevents punctuation in a query from being treated differently from punctuation in stored text.

Check the output

Test the same sample through the Analyze API with the final analyzer. Confirm that tokens contain only the expected alphanumeric parts and that punctuation is absent. Then index or reindex a small set of representative documents and run a term query for a known token. If the analyzer is working, the query should match without requiring punctuation.

Common problems and next steps

Punctuation still appears in tokens

If punctuation remains, the field is probably not using the analyzer you edited. Check the mapping name, whether the field uses a multi-field with its own analyzer, and whether a keyword sub-field is returning the raw value. Keyword fields are not analyzed, so punctuation remains intact by design.

Hyphens and apostrophes behave differently

Removing all punctuation can merge words that should stay separate or change how a word is understood. For example, the standard analyzer has specific handling for some apostrophe and hyphen cases. Before using a broad punctuation-removal pattern, test forms that appear in your content and decide whether alternative tokens such as separate words are acceptable.

Searches no longer match

A missing match after changing the analyzer often means the index and query analyzers are different. Specify the same search_analyzer or remove it to inherit the index analyzer. For an existing index, changing the analyzer without reindexing can leave old tokens in the inverted index, so reindex and verify before relying on the result.