match-phrase-prefix-query.asciidoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. [[query-dsl-match-query-phrase-prefix]]
  2. === Match phrase prefix query
  3. ++++
  4. <titleabbrev>Match phrase prefix</titleabbrev>
  5. ++++
  6. Returns documents that contain the words of a provided text, in the **same
  7. order** as provided. The last term of the provided text is treated as a
  8. <<query-dsl-prefix-query,prefix>>, matching any words that begin with that term.
  9. [[match-phrase-prefix-query-ex-request]]
  10. ==== Example request
  11. The following search returns documents that contain phrases beginning with
  12. `quick brown f` in the `message` field.
  13. This search would match a `message` value of `quick brown fox` or `two quick
  14. brown ferrets` but not `the fox is quick and brown`.
  15. [source,console]
  16. --------------------------------------------------
  17. GET /_search
  18. {
  19. "query": {
  20. "match_phrase_prefix" : {
  21. "message" : {
  22. "query" : "quick brown f"
  23. }
  24. }
  25. }
  26. }
  27. --------------------------------------------------
  28. [[match-phrase-prefix-top-level-params]]
  29. ==== Top-level parameters for `match_phrase_prefix`
  30. `<field>`::
  31. (Required, object) Field you wish to search.
  32. [[match-phrase-prefix-field-params]]
  33. ==== Parameters for `<field>`
  34. `query`::
  35. +
  36. --
  37. (Required, string) Text you wish to find in the provided `<field>`.
  38. The `match_phrase_prefix` query <<analysis,analyzes>> any provided text into
  39. tokens before performing a search. The last term of this text is treated as a
  40. <<query-dsl-prefix-query,prefix>>, matching any words that begin with that term.
  41. --
  42. `analyzer`::
  43. (Optional, string) <<analysis,Analyzer>> used to convert text in the `query`
  44. value into tokens. Defaults to the <<specify-index-time-analyzer,index-time
  45. analyzer>> mapped for the `<field>`. If no analyzer is mapped, the index's
  46. default analyzer is used.
  47. `max_expansions`::
  48. (Optional, integer) Maximum number of terms to which the last provided term of
  49. the `query` value will expand. Defaults to `50`.
  50. `slop`::
  51. (Optional, integer) Maximum number of positions allowed between matching tokens.
  52. Defaults to `0`. Transposed terms have a slop of `2`.
  53. `zero_terms_query`::
  54. +
  55. --
  56. (Optional, string) Indicates whether no documents are returned if the `analyzer`
  57. removes all tokens, such as when using a `stop` filter. Valid values are:
  58. `none` (Default)::
  59. No documents are returned if the `analyzer` removes all tokens.
  60. `all`::
  61. Returns all documents, similar to a <<query-dsl-match-all-query,`match_all`>>
  62. query.
  63. --
  64. [[match-phrase-prefix-query-notes]]
  65. ==== Notes
  66. [[match-phrase-prefix-autocomplete]]
  67. ===== Using the match phrase prefix query for search autocompletion
  68. While easy to set up, using the `match_phrase_prefix` query for search
  69. autocompletion can sometimes produce confusing results.
  70. For example, consider the query string `quick brown f`. This query works by
  71. creating a phrase query out of `quick` and `brown` (i.e. the term `quick` must
  72. exist and must be followed by the term `brown`). Then it looks at the sorted
  73. term dictionary to find the first 50 terms that begin with `f`, and adds these
  74. terms to the phrase query.
  75. The problem is that the first 50 terms may not include the term `fox` so the
  76. phrase `quick brown fox` will not be found. This usually isn't a problem as
  77. the user will continue to type more letters until the word they are looking
  78. for appears.
  79. For better solutions for _search-as-you-type_ see the
  80. <<completion-suggester,completion suggester>> and
  81. the <<search-as-you-type,`search_as_you_type` field type>>.