match-bool-prefix-query.asciidoc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. [[query-dsl-match-bool-prefix-query]]
  2. === Match boolean prefix query
  3. ++++
  4. <titleabbrev>Match boolean prefix</titleabbrev>
  5. ++++
  6. A `match_bool_prefix` query analyzes its input and constructs a
  7. <<query-dsl-bool-query,`bool` query>> from the terms. Each term except the last
  8. is used in a `term` query. The last term is used in a `prefix` query. A
  9. `match_bool_prefix` query such as
  10. [source,console]
  11. --------------------------------------------------
  12. GET /_search
  13. {
  14. "query": {
  15. "match_bool_prefix" : {
  16. "message" : "quick brown f"
  17. }
  18. }
  19. }
  20. --------------------------------------------------
  21. where analysis produces the terms `quick`, `brown`, and `f` is similar to the
  22. following `bool` query
  23. [source,console]
  24. --------------------------------------------------
  25. GET /_search
  26. {
  27. "query": {
  28. "bool" : {
  29. "should": [
  30. { "term": { "message": "quick" }},
  31. { "term": { "message": "brown" }},
  32. { "prefix": { "message": "f"}}
  33. ]
  34. }
  35. }
  36. }
  37. --------------------------------------------------
  38. An important difference between the `match_bool_prefix` query and
  39. <<query-dsl-match-query-phrase-prefix,`match_phrase_prefix`>> is that the
  40. `match_phrase_prefix` query matches its terms as a phrase, but the
  41. `match_bool_prefix` query can match its terms in any position. The example
  42. `match_bool_prefix` query above could match a field containing
  43. `quick brown fox`, but it could also match `brown fox quick`. It could also
  44. match a field containing the term `quick`, the term `brown` and a term
  45. starting with `f`, appearing in any position.
  46. ==== Parameters
  47. By default, `match_bool_prefix` queries' input text will be analyzed using the
  48. analyzer from the queried field's mapping. A different search analyzer can be
  49. configured with the `analyzer` parameter
  50. [source,console]
  51. --------------------------------------------------
  52. GET /_search
  53. {
  54. "query": {
  55. "match_bool_prefix": {
  56. "message": {
  57. "query": "quick brown f",
  58. "analyzer": "keyword"
  59. }
  60. }
  61. }
  62. }
  63. --------------------------------------------------
  64. `match_bool_prefix` queries support the
  65. <<query-dsl-minimum-should-match,`minimum_should_match`>> and `operator`
  66. parameters as described for the
  67. <<query-dsl-match-query-boolean,`match` query>>, applying the setting to the
  68. constructed `bool` query. The number of clauses in the constructed `bool`
  69. query will in most cases be the number of terms produced by analysis of the
  70. query text.
  71. The <<query-dsl-match-query-fuzziness,`fuzziness`>>, `prefix_length`,
  72. `max_expansions`, `fuzzy_transpositions`, and `fuzzy_rewrite` parameters can
  73. be applied to the `term` subqueries constructed for all terms but the final
  74. term. They do not have any effect on the prefix query constructed for the
  75. final term.