Skip to content

Commit b0ffc60

Browse files
authored
[DOCS] Reformat reverse token filter docs (#50672)
* Updates the description and adds a Lucene link * Adds analyze and custom analyzer snippets
1 parent 2bc37ea commit b0ffc60

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

docs/reference/analysis/tokenfilters/reverse-tokenfilter.asciidoc

+87-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,90 @@
44
<titleabbrev>Reverse</titleabbrev>
55
++++
66

7-
A token filter of type `reverse` that simply reverses each token.
7+
Reverses each token in a stream. For example, you can use the `reverse` filter
8+
to change `cat` to `tac`.
9+
10+
Reversed tokens are useful for suffix-based searches,
11+
such as finding words that end in `-ion` or searching file names by their
12+
extension.
13+
14+
This filter uses Lucene's
15+
https://lucene.apache.org/core/{lucene_version_path}/analyzers-common/org/apache/lucene/analysis/reverse/ReverseStringFilter.html[ReverseStringFilter].
16+
17+
[[analysis-reverse-tokenfilter-analyze-ex]]
18+
==== Example
19+
20+
The following <<indices-analyze,analyze API>> request uses the `reverse`
21+
filter to reverse each token in `quick fox jumps`:
22+
23+
[source,console]
24+
--------------------------------------------------
25+
GET _analyze
26+
{
27+
"tokenizer" : "standard",
28+
"filter" : ["reverse"],
29+
"text" : "quick fox jumps"
30+
}
31+
--------------------------------------------------
32+
33+
The filter produces the following tokens:
34+
35+
[source,text]
36+
--------------------------------------------------
37+
[ kciuq, xof, spmuj ]
38+
--------------------------------------------------
39+
40+
/////////////////////
41+
[source,console-result]
42+
--------------------------------------------------
43+
{
44+
"tokens" : [
45+
{
46+
"token" : "kciuq",
47+
"start_offset" : 0,
48+
"end_offset" : 5,
49+
"type" : "<ALPHANUM>",
50+
"position" : 0
51+
},
52+
{
53+
"token" : "xof",
54+
"start_offset" : 6,
55+
"end_offset" : 9,
56+
"type" : "<ALPHANUM>",
57+
"position" : 1
58+
},
59+
{
60+
"token" : "spmuj",
61+
"start_offset" : 10,
62+
"end_offset" : 15,
63+
"type" : "<ALPHANUM>",
64+
"position" : 2
65+
}
66+
]
67+
}
68+
--------------------------------------------------
69+
/////////////////////
70+
71+
[[analysis-reverse-tokenfilter-analyzer-ex]]
72+
==== Add to an analyzer
73+
74+
The following <<indices-create-index,create index API>> request uses the
75+
`reverse` filter to configure a new
76+
<<analysis-custom-analyzer,custom analyzer>>.
77+
78+
[source,console]
79+
--------------------------------------------------
80+
PUT reverse_example
81+
{
82+
"settings" : {
83+
"analysis" : {
84+
"analyzer" : {
85+
"whitespace_reverse" : {
86+
"tokenizer" : "whitespace",
87+
"filter" : ["reverse"]
88+
}
89+
}
90+
}
91+
}
92+
}
93+
--------------------------------------------------

0 commit comments

Comments
 (0)