Skip to content

Commit a7e79d0

Browse files
committed
[DOCS] Note limitations of max_gram parm in edge_ngram tokenizer for index analyzers (#49007)
The `edge_ngram` tokenizer limits tokens to the `max_gram` character length. Autocomplete searches for terms longer than this limit return no results. To prevent this, you can use the `truncate` token filter to truncate tokens to the `max_gram` character length. However, this could return irrelevant results. This commit adds some advisory text to make users aware of this limitation and outline the tradeoffs for each approach. Closes #48956.
1 parent 457a568 commit a7e79d0

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

docs/reference/analysis/tokenizers/edgengram-tokenizer.asciidoc

+36-5
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ configure the `edge_ngram` before using it.
7474

7575
The `edge_ngram` tokenizer accepts the following parameters:
7676

77-
[horizontal]
7877
`min_gram`::
7978
Minimum length of characters in a gram. Defaults to `1`.
8079

8180
`max_gram`::
82-
Maximum length of characters in a gram. Defaults to `2`.
81+
+
82+
--
83+
Maximum length of characters in a gram. Defaults to `2`.
84+
85+
See <<max-gram-limits>>.
86+
--
8387

8488
`token_chars`::
8589

@@ -95,6 +99,29 @@ Character classes may be any of the following:
9599
* `punctuation` -- for example `!` or `"`
96100
* `symbol` -- for example `$` or `√`
97101

102+
[[max-gram-limits]]
103+
=== Limitations of the `max_gram` parameter
104+
105+
The `edge_ngram` tokenizer's `max_gram` value limits the character length of
106+
tokens. When the `edge_ngram` tokenizer is used with an index analyzer, this
107+
means search terms longer than the `max_gram` length may not match any indexed
108+
terms.
109+
110+
For example, if the `max_gram` is `3`, searches for `apple` won't match the
111+
indexed term `app`.
112+
113+
To account for this, you can use the <<analysis-truncate-tokenfilter,`truncate`
114+
token filter>> token filter with a search analyzer to shorten search terms to
115+
the `max_gram` character length. However, this could return irrelevant results.
116+
117+
For example, if the `max_gram` is `3` and search terms are truncated to three
118+
characters, the search term `apple` is shortened to `app`. This means searches
119+
for `apple` return any indexed terms matching `app`, such as `apply`, `snapped`,
120+
and `apple`.
121+
122+
We recommend testing both approaches to see which best fits your
123+
use case and desired search experience.
124+
98125
[float]
99126
=== Example configuration
100127

@@ -213,12 +240,16 @@ The above example produces the following terms:
213240
---------------------------
214241

215242
Usually we recommend using the same `analyzer` at index time and at search
216-
time. In the case of the `edge_ngram` tokenizer, the advice is different. It
243+
time. In the case of the `edge_ngram` tokenizer, the advice is different. It
217244
only makes sense to use the `edge_ngram` tokenizer at index time, to ensure
218-
that partial words are available for matching in the index. At search time,
245+
that partial words are available for matching in the index. At search time,
219246
just search for the terms the user has typed in, for instance: `Quick Fo`.
220247

221-
Below is an example of how to set up a field for _search-as-you-type_:
248+
Below is an example of how to set up a field for _search-as-you-type_.
249+
250+
Note that the `max_gram` value for the index analyzer is `10`, which limits
251+
indexed terms to 10 characters. Search terms are not truncated, meaning that
252+
search terms longer than 10 characters may not match any indexed terms.
222253

223254
[source,js]
224255
-----------------------------------

0 commit comments

Comments
 (0)