|
4 | 4 | <titleabbrev>Fuzzy</titleabbrev>
|
5 | 5 | ++++
|
6 | 6 |
|
7 |
| -The fuzzy query uses similarity based on Levenshtein edit distance. |
| 7 | +Returns documents that contain terms similar to the search term, as measured by |
| 8 | +a http://en.wikipedia.org/wiki/Levenshtein_distance[Levenshtein edit distance]. |
8 | 9 |
|
9 |
| -==== String fields |
| 10 | +An edit distance is the number of one-character changes needed to turn one term |
| 11 | +into another. These changes can include: |
10 | 12 |
|
11 |
| -The `fuzzy` query generates matching terms that are within the |
12 |
| -maximum edit distance specified in `fuzziness` and then checks the term |
13 |
| -dictionary to find out which of those generated terms actually exist in the |
14 |
| -index. The final query uses up to `max_expansions` matching terms. |
| 13 | +* Changing a character (**b**ox → **f**ox) |
| 14 | +* Removing a character (**b**lack → lack) |
| 15 | +* Inserting a character (sic → sic**k**) |
| 16 | +* Transposing two adjacent characters (**ac**t → **ca**t) |
15 | 17 |
|
16 |
| -Here is a simple example: |
| 18 | +To find similar terms, the `fuzzy` query creates a set of all possible |
| 19 | +variations, or expansions, of the search term within a specified edit distance. |
| 20 | +The query then returns exact matches for each expansion. |
| 21 | + |
| 22 | +[[fuzzy-query-ex-request]] |
| 23 | +==== Example requests |
| 24 | + |
| 25 | +[[fuzzy-query-ex-simple]] |
| 26 | +===== Simple example |
17 | 27 |
|
18 | 28 | [source,js]
|
19 |
| --------------------------------------------------- |
| 29 | +---- |
20 | 30 | GET /_search
|
21 | 31 | {
|
22 | 32 | "query": {
|
23 |
| - "fuzzy" : { "user" : "ki" } |
| 33 | + "fuzzy": { |
| 34 | + "user": { |
| 35 | + "value": "ki" |
| 36 | + } |
| 37 | + } |
24 | 38 | }
|
25 | 39 | }
|
26 |
| --------------------------------------------------- |
| 40 | +---- |
27 | 41 | // CONSOLE
|
28 | 42 |
|
29 |
| -Or with more advanced settings: |
| 43 | +[[fuzzy-query-ex-advanced]] |
| 44 | +===== Example using advanced parameters |
30 | 45 |
|
31 | 46 | [source,js]
|
32 |
| --------------------------------------------------- |
| 47 | +---- |
33 | 48 | GET /_search
|
34 | 49 | {
|
35 | 50 | "query": {
|
36 |
| - "fuzzy" : { |
37 |
| - "user" : { |
| 51 | + "fuzzy": { |
| 52 | + "user": { |
38 | 53 | "value": "ki",
|
39 |
| - "boost": 1.0, |
40 |
| - "fuzziness": 2, |
| 54 | + "fuzziness": "AUTO", |
| 55 | + "max_expansions": 50, |
41 | 56 | "prefix_length": 0,
|
42 |
| - "max_expansions": 100 |
| 57 | + "transpositions": true, |
| 58 | + "rewrite": "constant_score" |
43 | 59 | }
|
44 | 60 | }
|
45 | 61 | }
|
46 | 62 | }
|
47 |
| --------------------------------------------------- |
| 63 | +---- |
48 | 64 | // CONSOLE
|
49 | 65 |
|
50 |
| -[float] |
51 |
| -===== Parameters |
| 66 | +[[fuzzy-query-top-level-params]] |
| 67 | +==== Top-level parameters for `fuzzy` |
| 68 | +`<field>`:: |
| 69 | +(Required, object) Field you wish to search. |
52 | 70 |
|
53 |
| -[horizontal] |
54 |
| -`fuzziness`:: |
55 |
| - |
56 |
| - The maximum edit distance. Defaults to `AUTO`. See <<fuzziness>>. |
| 71 | +[[fuzzy-query-field-params]] |
| 72 | +==== Parameters for `<field>` |
| 73 | +`value`:: |
| 74 | +(Required, string) Term you wish to find in the provided `<field>`. |
57 | 75 |
|
58 |
| -`prefix_length`:: |
| 76 | +`fuzziness`:: |
| 77 | +(Optional, string) Maximum edit distance allowed for matching. See <<fuzziness>> |
| 78 | +for valid values and more information. |
59 | 79 |
|
60 |
| - The number of initial characters which will not be ``fuzzified''. This |
61 |
| - helps to reduce the number of terms which must be examined. Defaults |
62 |
| - to `0`. |
63 | 80 |
|
64 | 81 | `max_expansions`::
|
| 82 | ++ |
| 83 | +-- |
| 84 | +(Optional, integer) Maximum number of variations created. Defaults to `50`. |
65 | 85 |
|
66 |
| - The maximum number of terms that the `fuzzy` query will expand to. |
67 |
| - Defaults to `50`. |
68 |
| - |
69 |
| -`transpositions`:: |
70 |
| - |
71 |
| - Whether fuzzy transpositions (`ab` -> `ba`) are supported. |
72 |
| - Default is `true`. |
| 86 | +WARNING: Avoid using a high value in the `max_expansions` parameter, especially |
| 87 | +if the `prefix_length` parameter value is `0`. High values in the |
| 88 | +`max_expansions` parameter can cause poor performance due to the high number of |
| 89 | +variations examined. |
| 90 | +-- |
73 | 91 |
|
74 |
| -WARNING: This query can be very heavy if `prefix_length` is set to `0` and if |
75 |
| -`max_expansions` is set to a high number. It could result in every term in the |
76 |
| -index being examined! |
| 92 | +`prefix_length`:: |
| 93 | +(Optional, integer) Number of beginning characters left unchanged when creating |
| 94 | +expansions. Defaults to `0`. |
77 | 95 |
|
| 96 | +`transpositions`:: |
| 97 | +(Optional, boolean) Indicates whether edits include transpositions of two |
| 98 | +adjacent characters (ab → ba). Defaults to `true`. |
78 | 99 |
|
| 100 | +`rewrite`:: |
| 101 | +(Optional, string) Method used to rewrite the query. For valid values and more |
| 102 | +information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>. |
0 commit comments