liveBook · Manning

Tokenization

As explained in Elasticsearch in Action, Second Edition

Tokenization is the process of splitting a character stream into discrete tokens according to rules such as whitespace, delimiters, or character patterns.

When a user searches a synopsis for “Peter” or “pickled peppers,” Elasticsearch must first turn the text into searchable pieces. Tokenization splits a text field into individual tokens according to rules such as whitespace, punctuation, letters, delimiters, or patterns. section 3.1.2 section 7.2.1

A tokenizer performs this chopping step. A whitespace tokenizer separates words at whitespace, while other tokenizers can split on nonletters, colons, digits, or custom separators. Tokenization creates tokens but does not perform later enhancements such as synonym handling, stemming, or other normalization. section 7.2.1 section 3.1.2

From synopsis text to tokens

The input “Peter Piper picked a peck of Pickled-peppers!” becomes [peter, piper, picked, a, peck, of, pickled, peppers]. The displayed result includes lowercasing and punctuation removal, so it illustrates tokenization together with analysis steps beyond merely splitting the character stream. section 3.1.2

Choose tokenization rules according to the searchable text:

  • Use whitespace-style splitting when word boundaries are primarily whitespace. section 3.1.2 section 7.2.1
  • Use separators or patterns when terms contain hyphens, punctuation, colons, digits, or other meaningful boundaries; for example, “pickled-peppers” can become “pickled” and “peppers,” while “K8s” can become “K” and “s.” section 7.2.1
  • Remember that tokenization alone cannot answer synonym, plural, or related-word queries; normalization continues the analysis. section 7.2.1

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines rule-based splitting and variants, but defers synonym handling, stemming, and other transformations to normalization.
Examples
Uses synopsis text, whitespace-separated words, movie-review punctuation, hyphenated terms, and alphanumeric strings as examples.
What you can do after
Evaluate tokenizer choices for searchable text and distinguish splitting from subsequent normalization.
How it connects
Connects text analysis with analyzers, normalization, character filters, token filters, and inverted indexes.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.