prefix-query.asciidoc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. [[query-dsl-prefix-query]]
  2. === Prefix query
  3. ++++
  4. <titleabbrev>Prefix</titleabbrev>
  5. ++++
  6. Returns documents that contain a specific prefix in a provided field.
  7. [[prefix-query-ex-request]]
  8. ==== Example request
  9. The following search returns documents where the `user` field contains a term
  10. that begins with `ki`.
  11. [source,console]
  12. ----
  13. GET /_search
  14. {
  15. "query": {
  16. "prefix": {
  17. "user": {
  18. "value": "ki"
  19. }
  20. }
  21. }
  22. }
  23. ----
  24. [[prefix-query-top-level-params]]
  25. ==== Top-level parameters for `prefix`
  26. `<field>`::
  27. (Required, object) Field you wish to search.
  28. [[prefix-query-field-params]]
  29. ==== Parameters for `<field>`
  30. `value`::
  31. (Required, string) Beginning characters of terms you wish to find in the
  32. provided `<field>`.
  33. `rewrite`::
  34. (Optional, string) Method used to rewrite the query. For valid values and more
  35. information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.
  36. [[prefix-query-notes]]
  37. ==== Notes
  38. [[prefix-query-short-ex]]
  39. ===== Short request example
  40. You can simplify the `prefix` query syntax by combining the `<field>` and
  41. `value` parameters. For example:
  42. [source,console]
  43. ----
  44. GET /_search
  45. {
  46. "query": {
  47. "prefix" : { "user" : "ki" }
  48. }
  49. }
  50. ----
  51. [[prefix-query-index-prefixes]]
  52. ===== Speed up prefix queries
  53. You can speed up prefix queries using the <<index-prefixes,`index_prefixes`>>
  54. mapping parameter. If enabled, {es} indexes prefixes between 2 and 5
  55. characters in a separate field. This lets {es} run prefix queries more
  56. efficiently at the cost of a larger index.