liveBook · Manning

Edge n-gram indexing

As explained in Elasticsearch in Action, Second Edition

An edge n-gram is an n-gram anchored at the beginning of a token.

Edge n-gram indexing breaks each token into prefixes anchored at its beginning. For “action,” it produces “a,” “ac,” “act,” “acti,” “actio,” and “action,” making partial input useful for typeahead-style search. section 4.6.6 section 7.7.2

Generating prefixes with an edge_ngram tokenizer

A custom analyzer can attach an edge_ngram tokenizer with minimum and maximum prefix lengths. For “bond,” a configuration using sizes 2 through 6 produces “bo,” “bon,” and “bond” (with longer tokens continuing up to the configured maximum). The _analyze API lets you inspect the generated terms before using the analyzer in an index. section 7.7.2

..
"tokenizer": {
  "my_edge_ngram_tokenizer":{
    "type":"edge_ngram",
     "min_gram":2,
     "max_gram":6,
     "token_chars":["letter","digit"]
   }
}

Inspect the tokenizer fragment that sets edge_ngram, min_gram, max_gram, and accepted token characters. section 7.7.2

For typeahead search, Elasticsearch can also provide the search_as_you_type field, which creates analyzed subfields automatically. A bool_prefix multi_match query searches the main field and its shingle-based subfields together. section 4.6.6

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines prefix generation and shows tokenizer configuration and _analyze testing, while deferring detailed treatment to a later discussion.
Examples
Uses action, coffee, and bond prefixes, plus book-title mappings, indexed documents, analyzer tests, and a bool_prefix search.
What you can do after
Apply it via Elasticsearch analyzers, edge_ngram tokenizer settings, and the _analyze API to produce and inspect token prefixes.
How it connects
Connects edge n-grams with n-grams, shingles, analyzers, tokenizers, search_as_you_type, and multi_match queries.

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.