match-bool-prefix-query.asciidoc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. [[query-dsl-match-bool-prefix-query]]
  2. === Match Bool Prefix Query
  3. A `match_bool_prefix` query analyzes its input and constructs a
  4. <<query-dsl-bool-query,`bool` query>> from the terms. Each term except the last
  5. is used in a `term` query. The last term is used in a `prefix` query. A
  6. `match_bool_prefix` query such as
  7. [source,js]
  8. --------------------------------------------------
  9. GET /_search
  10. {
  11. "query": {
  12. "match_bool_prefix" : {
  13. "message" : "quick brown f"
  14. }
  15. }
  16. }
  17. --------------------------------------------------
  18. // CONSOLE
  19. where analysis produces the terms `quick`, `brown`, and `f` is similar to the
  20. following `bool` query
  21. [source,js]
  22. --------------------------------------------------
  23. GET /_search
  24. {
  25. "query": {
  26. "bool" : {
  27. "should": [
  28. { "term": { "message": "quick" }},
  29. { "term": { "message": "brown" }},
  30. { "prefix": { "message": "f"}}
  31. ]
  32. }
  33. }
  34. }
  35. --------------------------------------------------
  36. // CONSOLE
  37. An important difference between the `match_bool_prefix` query and
  38. <<query-dsl-match-query-phrase-prefix,`match_phrase_prefix`>> is that the
  39. `match_phrase_prefix` query matches its terms as a phrase, but the
  40. `match_bool_prefix` query can match its terms in any position. The example
  41. `match_bool_prefix` query above could match a field containing containing
  42. `quick brown fox`, but it could also match `brown fox quick`. It could also
  43. match a field containing the term `quick`, the term `brown` and a term
  44. starting with `f`, appearing in any position.
  45. ==== Parameters
  46. By default, `match_bool_prefix` queries' input text will be analyzed using the
  47. analyzer from the queried field's mapping. A different search analyzer can be
  48. configured with the `analyzer` parameter
  49. [source,js]
  50. --------------------------------------------------
  51. GET /_search
  52. {
  53. "query": {
  54. "match_bool_prefix" : {
  55. "message": {
  56. "query": "quick brown f",
  57. "analyzer": "keyword"
  58. }
  59. }
  60. }
  61. }
  62. --------------------------------------------------
  63. // CONSOLE
  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.