prefix-query.asciidoc 2.1 KB

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