liveBook · Manning

Standard tokenizer

As explained in Elasticsearch in Action, Second Edition

A standard tokenizer is a built-in Lucene text-analysis component that divides text into tokens according to predefined standard rules.

A standard tokenizer is a built-in Elasticsearch analysis component that turns text into separate tokens using predefined word-boundary rules. It splits on whitespace and punctuation such as commas, hyphens, colons, and semicolons, making text searchable as individual terms rather than one unbroken string. section 7.7.1 section 3.1.2

Tokenization supports matching a query against words stored from a text field. For example, a synopsis containing “Peter Piper picked a peck of Pickled-peppers!” can be represented as tokens including peter, piper, picked, pickled, and peppers, so searches containing Peter and Peppers can match it. section 3.1.2

Test the tokenizer directly

Use the _analyze API with tokenizer set to standard. For “Hello,cruel world!”, the comma and whitespace are delimiters, producing Hello, cruel, and world. This direct call isolates tokenization from the other components an analyzer may apply. section 7.7.1

POST _analyze
{
  "text": "Hello,cruel world!",
  "tokenizer": "standard"
}

Run this request to inspect how standard tokenization separates punctuation-delimited and whitespace-delimited words. section 7.7.1

The standard tokenizer is one component, not the whole standard analyzer. The default standard analyzer also applies a lowercase token filter: “Weird Combo” becomes lowercase tokens, while the tokenizer removes the smiley and exclamation marks. Emoji in the example remain indexed as tokens. Stop words are not removed by default. section 7.3.1

Use the distinction when configuring analysis:

  • Choose the standard tokenizer when word-boundary splitting on whitespace and punctuation fits the field. section 7.7.1
  • Use the standard analyzer when its built-in tokenization and lowercasing behavior are appropriate; it is Elasticsearch’s default analyzer. section 7.3.1
  • Add a stop-word configuration when common words should be omitted; stop filtering is disabled by default. section 7.3.1
  • Create a custom tokenizer when tokens must be split at a chosen maximum length. section 7.7.1

Limit token length

The standard tokenizer exposes max_token_length, whose default is 255. Define a custom tokenizer of type standard with max_token_length set to 2, place it in a custom analyzer, and analyze “Bond”; the result is the two tokens “Bo” and “nd”. section 7.7.1

Listing 7.43 Index with a custom tokenizer
PUT index_with_custom_standard_tokenizer
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_token_length_analyzer": {                #1
          "tokenizer": "custom_token_length_tokenizer"
        }
      },
      "tokenizer": {
        "custom_token_length_tokenizer": {
          "type": "standard", 
          "max_token_length": 2                          #2
        }
      }
    }
  }
}

This index settings example names a standard tokenizer and sets max_token_length to 2 for a custom analyzer. section 7.7.1

Check analysis output before indexing whenever token boundaries affect search behavior. The _analyze API can test the implicit default analyzer or an explicitly named analyzer, helping verify punctuation handling, lowercasing, retained emoji, and configured stop words or token length. section 7.3.1 section 7.7.1

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines delimiter behavior and demonstrates _analyze testing plus max_token_length customization, without detailing tokenizer internals.
Examples
Uses “Hello,cruel world!”, “Bond”, a coffee-and-popcorn phrase, and a Peter Piper synopsis.
What it assumes
Introduces tokenization from raw text and assumes no prior Elasticsearch analysis knowledge.
What you can do after
Operate/configure it by testing token output and defining a custom maximum token length.
How it connects
Connects tokenization with text analysis, normalization, standard analyzer, lowercase token filter, stop words, and custom analyzers.

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.