prefix-query.asciidoc 1.5 KB

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