Skip to content

Commit 5b6e049

Browse files
jrodewigjkakavas
authored andcommitted
[DOCS] Rewrite prefix query docs (#41955)
1 parent 7b9675b commit 5b6e049

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

docs/reference/query-dsl/prefix-query.asciidoc

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,66 @@
44
<titleabbrev>Prefix</titleabbrev>
55
++++
66

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`.
1114

1215
[source,js]
13-
--------------------------------------------------
16+
----
1417
GET /_search
15-
{ "query": {
16-
"prefix" : { "user" : "ki" }
17-
}
18+
{
19+
"query": {
20+
"prefix": {
21+
"user": {
22+
"value": "ki"
23+
}
24+
}
25+
}
1826
}
19-
--------------------------------------------------
27+
----
2028
// CONSOLE
2129

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:
2352

2453
[source,js]
25-
--------------------------------------------------
54+
----
2655
GET /_search
27-
{ "query": {
28-
"prefix" : { "user" : { "value" : "ki", "boost" : 2.0 } }
29-
}
56+
{
57+
"query": {
58+
"prefix" : { "user" : "ki" }
59+
}
3060
}
31-
--------------------------------------------------
61+
----
3262
// CONSOLE
3363

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

Comments
 (0)