AI Hints
Home›Elasticsearch Tutorial›Text Analysis
Elasticsearch · Lesson 53 of 120

The _analyze API

See the terms.

⏱ 2 min read▶ Video at 49:48🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

When a search doesn't match, the first question is, what terms were actually indexed? The analyze API shows you exactly what an analyzer does to some text.

  • Search won't match?
  • What was indexed?
  • _analyze

The standard analyzer

We send some text to_analyze, with the standard analyzer, the default for text fields. Run it. It split the text into words, removed the punctuation, and lower cased everything.

Dev Tools Consoletext
GET _analyze?filter_path=tokens.token
{
  "analyzer": "standard",
  "text": "Storm RAIN-Jacket, 2 colors!"
}
Output
{
  "tokens": [
    {"token": "storm"},
    {"token": "rain"},
    {"token": "jacket"},
    {"token": "2"},
    {"token": "colors"}
  ]
}

Build your own on the fly

You can also test a tokenizer and filters directly. Here, the HTML strip character filter, the whitespace tokenizer, and the lowercase filter. Run it. The tags are gone, and the words are only split on spaces.

Dev Tools Consoletext
GET _analyze?filter_path=tokens.token
{
  "char_filter": ["html_strip"],
  "tokenizer": "whitespace",
  "filter": ["lowercase"],
  "text": "<b>Storm</b> RAIN-Jacket"
}
Output
{"tokens": [{"token": "storm"}, {"token": "rain-jacket"}]}

Summary

Underscore analyze shows the terms an analyzer produces. It's your best tool for debugging search. Next, the built-in analyzers.

Key takeaways
  • _analyze
  • Test analyzers
  • Debug search
Next up: Built-in Analyzers — standard, simple, keyword