|
4 | 4 | <titleabbrev>Prefix</titleabbrev>
|
5 | 5 | ++++
|
6 | 6 |
|
7 |
| -Matches documents that have fields containing terms with a specified |
8 |
| -prefix (*not analyzed*). The prefix query maps to Lucene `PrefixQuery`. |
9 |
| -The following matches documents where the user field contains a term |
10 |
| -that starts with `ki`: |
| 7 | +Returns documents that contain a specific prefix in a provided field. |
| 8 | + |
| 9 | +[[prefix-query-ex-request]] |
| 10 | +==== Example request |
| 11 | + |
| 12 | +The following search returns documents where the `user` field contains a term |
| 13 | +that begins with `ki`. |
11 | 14 |
|
12 | 15 | [source,js]
|
13 |
| --------------------------------------------------- |
| 16 | +---- |
14 | 17 | GET /_search
|
15 |
| -{ "query": { |
16 |
| - "prefix" : { "user" : "ki" } |
17 |
| - } |
| 18 | +{ |
| 19 | + "query": { |
| 20 | + "prefix": { |
| 21 | + "user": { |
| 22 | + "value": "ki" |
| 23 | + } |
| 24 | + } |
| 25 | + } |
18 | 26 | }
|
19 |
| --------------------------------------------------- |
| 27 | +---- |
20 | 28 | // CONSOLE
|
21 | 29 |
|
22 |
| -A boost can also be associated with the query: |
| 30 | +[[prefix-query-top-level-params]] |
| 31 | +==== Top-level parameters for `prefix` |
| 32 | +`<field>`:: |
| 33 | +(Required, object) Field you wish to search. |
| 34 | + |
| 35 | +[[prefix-query-field-params]] |
| 36 | +==== Parameters for `<field>` |
| 37 | +`value`:: |
| 38 | +(Required, string) Beginning characters of terms you wish to find in the |
| 39 | +provided `<field>`. |
| 40 | + |
| 41 | +`rewrite`:: |
| 42 | +(Optional, string) Method used to rewrite the query. For valid values and more |
| 43 | +information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>. |
| 44 | + |
| 45 | +[[prefix-query-notes]] |
| 46 | +==== Notes |
| 47 | + |
| 48 | +[[prefix-query-short-ex]] |
| 49 | +===== Short request example |
| 50 | +You can simplify the `prefix` query syntax by combining the `<field>` and |
| 51 | +`value` parameters. For example: |
23 | 52 |
|
24 | 53 | [source,js]
|
25 |
| --------------------------------------------------- |
| 54 | +---- |
26 | 55 | GET /_search
|
27 |
| -{ "query": { |
28 |
| - "prefix" : { "user" : { "value" : "ki", "boost" : 2.0 } } |
29 |
| - } |
| 56 | +{ |
| 57 | + "query": { |
| 58 | + "prefix" : { "user" : "ki" } |
| 59 | + } |
30 | 60 | }
|
31 |
| --------------------------------------------------- |
| 61 | +---- |
32 | 62 | // CONSOLE
|
33 | 63 |
|
34 |
| -This multi term query allows you to control how it gets rewritten using the |
35 |
| -<<query-dsl-multi-term-rewrite,rewrite>> |
36 |
| -parameter. |
| 64 | +[[prefix-query-index-prefixes]] |
| 65 | +===== Speed up prefix queries |
| 66 | +You can speed up prefix queries using the <<index-prefixes,`index_prefixes`>> |
| 67 | +mapping parameter. If enabled, {es} indexes prefixes between 2 and 5 |
| 68 | +characters in a separate field. This lets {es} run prefix queries more |
| 69 | +efficiently at the cost of a larger index. |
0 commit comments