prefix-query.asciidoc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.id` field contains a term
  10. that begins with `ki`.
  11. [source,console]
  12. ----
  13. GET /_search
  14. {
  15. "query": {
  16. "prefix": {
  17. "user.id": {
  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. `case_insensitive`::
  37. (Optional, boolean) allows ASCII case insensitive matching of the
  38. value with the indexed field values when set to true. Setting to false is disallowed.
  39. [[prefix-query-notes]]
  40. ==== Notes
  41. [[prefix-query-short-ex]]
  42. ===== Short request example
  43. You can simplify the `prefix` query syntax by combining the `<field>` and
  44. `value` parameters. For example:
  45. [source,console]
  46. ----
  47. GET /_search
  48. {
  49. "query": {
  50. "prefix" : { "user" : "ki" }
  51. }
  52. }
  53. ----
  54. [[prefix-query-index-prefixes]]
  55. ===== Speed up prefix queries
  56. You can speed up prefix queries using the <<index-prefixes,`index_prefixes`>>
  57. mapping parameter. If enabled, {es} indexes prefixes between 2 and 5
  58. characters in a separate field. This lets {es} run prefix queries more
  59. efficiently at the cost of a larger index.
  60. [[prefix-query-allow-expensive-queries]]
  61. ===== Allow expensive queries
  62. Prefix queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>
  63. is set to false. However, if <<index-prefixes, `index_prefixes`>> are enabled, an optimised query is built which
  64. is not considered slow, and will be executed in spite of this setting.