match-bool-prefix-query.asciidoc 2.8 KB

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