match-phrase-prefix-query.asciidoc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. [[query-dsl-match-query-phrase-prefix]]
  2. === Match Phrase Prefix Query
  3. The `match_phrase_prefix` is the same as `match_phrase`, except that it
  4. allows for prefix matches on the last term in the text. For example:
  5. [source,js]
  6. --------------------------------------------------
  7. {
  8. "match_phrase_prefix" : {
  9. "message" : "quick brown f"
  10. }
  11. }
  12. --------------------------------------------------
  13. It accepts the same parameters as the phrase type. In addition, it also
  14. accepts a `max_expansions` parameter (default `50`) that can control to how
  15. many prefixes the last term will be expanded. It is highly recommended to set
  16. it to an acceptable value to control the execution time of the query. For
  17. example:
  18. [source,js]
  19. --------------------------------------------------
  20. {
  21. "match_phrase_prefix" : {
  22. "message" : {
  23. "query" : "quick brown f",
  24. "max_expansions" : 10
  25. }
  26. }
  27. }
  28. --------------------------------------------------
  29. [IMPORTANT]
  30. ===================================================
  31. The `match_phrase_prefix` query is a poor-man's autocomplete. It is very easy
  32. to use, which let's you get started quickly with _search-as-you-type_ but it's
  33. results, which usually are good enough, can sometimes be confusing.
  34. Consider the query string `quick brown f`. This query works by creating a
  35. phrase query out of `quick` and `brown` (i.e. the term `quick` must exist and
  36. must be followed by the term `brown`). Then it looks at the sorted term
  37. dictionary to find the first 50 terms that begin with `f`, and
  38. adds these terms to the phrase query.
  39. The problem is that the first 50 terms may not include the term `fox` so the
  40. phase `quick brown fox` will not be found. This usually isn't a problem as
  41. the user will continue to type more letters until the word they are looking
  42. for appears.
  43. For better solutions for _search-as-you-type_ see the
  44. <<search-suggesters-completion,completion suggester>> and
  45. {guide}/_index_time_search_as_you_type.html[Index-Time Search-as-You-Type].
  46. ===================================================