Classic tokenizer

The classic tokenizer is a grammar based tokenizer that is good for English language documents. This tokenizer has heuristics for special treatment of acronyms, company names, email addresses, and internet host names. However, these rules don’t always work, and the tokenizer doesn’t work well for most languages other than English:

  • It splits words at most punctuation characters, removing punctuation. However, a dot that’s not followed by whitespace is considered part of a token.
  • It splits words at hyphens, unless there’s a number in the token, in which case the whole token is interpreted as a product number and is not split.
  • It recognizes email addresses and internet hostnames as one token.

Example output

  1. POST _analyze
  2. {
  3. "tokenizer": "classic",
  4. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  5. }

The above sentence would produce the following terms:

  1. [ The, 2, QUICK, Brown, Foxes, jumped, over, the, lazy, dog's, bone ]

Configuration

The classic tokenizer accepts the following parameters:

max_token_length

The maximum token length. If a token is seen that exceeds this length then it is split at max_token_length intervals. Defaults to 255.

Example configuration

In this example, we configure the classic tokenizer to have a max_token_length of 5 (for demonstration purposes):

  1. PUT my-index-000001
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "my_analyzer": {
  7. "tokenizer": "my_tokenizer"
  8. }
  9. },
  10. "tokenizer": {
  11. "my_tokenizer": {
  12. "type": "classic",
  13. "max_token_length": 5
  14. }
  15. }
  16. }
  17. }
  18. }
  19. POST my-index-000001/_analyze
  20. {
  21. "analyzer": "my_analyzer",
  22. "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  23. }

The above example produces the following terms:

  1. [ The, 2, QUICK, Brown, Foxes, jumpe, d, over, the, lazy, dog's, bone ]