multi-term-rewrite.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. [[query-dsl-multi-term-rewrite]]
  2. == `rewrite` parameter
  3. WARNING: This parameter is for expert users only. Changing the value of
  4. this parameter can impact search performance and relevance.
  5. {es} uses https://lucene.apache.org/core/[Apache Lucene] internally to power
  6. indexing and searching. In their original form, Lucene cannot execute the
  7. following queries:
  8. * <<query-dsl-fuzzy-query, `fuzzy`>>
  9. * <<query-dsl-prefix-query, `prefix`>>
  10. * <<query-dsl-query-string-query, `query_string`>>
  11. * <<query-dsl-regexp-query, `regexp`>>
  12. * <<query-dsl-wildcard-query, `wildcard`>>
  13. To execute them, Lucene changes these queries to a simpler form, such as a
  14. <<query-dsl-bool-query, `bool` query>> or a
  15. {wikipedia}/Bit_array[bit set].
  16. The `rewrite` parameter determines:
  17. * How Lucene calculates the relevance scores for each matching document
  18. * Whether Lucene changes the original query to a `bool`
  19. query or bit set
  20. * If changed to a `bool` query, which `term` query clauses are included
  21. [discrete]
  22. [[rewrite-param-valid-values]]
  23. === Valid values
  24. `constant_score` (Default)::
  25. Uses the `constant_score_boolean` method for fewer matching terms. Otherwise,
  26. this method finds all matching terms in sequence and returns matching documents
  27. using a bit set.
  28. `constant_score_boolean`::
  29. Assigns each document a relevance score equal to the `boost`
  30. parameter.
  31. +
  32. This method changes the original query to a <<query-dsl-bool-query, `bool`
  33. query>>. This `bool` query contains a `should` clause and
  34. <<query-dsl-term-query, `term` query>> for each matching term.
  35. +
  36. This method can cause the final `bool` query to exceed the clause limit in the
  37. <<indices-query-bool-max-clause-count, `indices.query.bool.max_clause_count`>>
  38. setting. If the query exceeds this limit, {es} returns an error.
  39. `scoring_boolean`::
  40. Calculates a relevance score for each matching document.
  41. +
  42. This method changes the original query to a <<query-dsl-bool-query, `bool`
  43. query>>. This `bool` query contains a `should` clause and
  44. <<query-dsl-term-query, `term` query>> for each matching term.
  45. +
  46. This method can cause the final `bool` query to exceed the clause limit in the
  47. <<indices-query-bool-max-clause-count, `indices.query.bool.max_clause_count`>>
  48. setting. If the query exceeds this limit, {es} returns an error.
  49. `top_terms_blended_freqs_N`::
  50. Calculates a relevance score for each matching document as if all terms had the
  51. same frequency. This frequency is the maximum frequency of all matching terms.
  52. +
  53. This method changes the original query to a <<query-dsl-bool-query, `bool`
  54. query>>. This `bool` query contains a `should` clause and
  55. <<query-dsl-term-query, `term` query>> for each matching term.
  56. +
  57. The final `bool` query only includes `term` queries for the top `N` scoring
  58. terms.
  59. +
  60. You can use this method to avoid exceeding the clause limit in the
  61. <<indices-query-bool-max-clause-count, `indices.query.bool.max_clause_count`>>
  62. setting.
  63. `top_terms_boost_N`::
  64. Assigns each matching document a relevance score equal to the `boost` parameter.
  65. +
  66. This method changes the original query to a <<query-dsl-bool-query, `bool`
  67. query>>. This `bool` query contains a `should` clause and
  68. <<query-dsl-term-query, `term` query>> for each matching term.
  69. +
  70. The final `bool` query only includes `term` queries for the top `N` terms.
  71. +
  72. You can use this method to avoid exceeding the clause limit in the
  73. <<indices-query-bool-max-clause-count, `indices.query.bool.max_clause_count`>>
  74. setting.
  75. `top_terms_N`::
  76. Calculates a relevance score for each matching document.
  77. +
  78. This method changes the original query to a <<query-dsl-bool-query, `bool`
  79. query>>. This `bool` query contains a `should` clause and
  80. <<query-dsl-term-query, `term` query>> for each matching term.
  81. +
  82. The final `bool` query
  83. only includes `term` queries for the top `N` scoring terms.
  84. +
  85. You can use this method to avoid exceeding the clause limit in the
  86. <<indices-query-bool-max-clause-count, `indices.query.bool.max_clause_count`>>
  87. setting.
  88. [discrete]
  89. [[rewrite-param-perf-considerations]]
  90. === Performance considerations for the `rewrite` parameter
  91. For most uses, we recommend using the `constant_score`,
  92. `constant_score_boolean`, or `top_terms_boost_N` rewrite methods.
  93. Other methods calculate relevance scores. These score calculations are often
  94. expensive and do not improve query results.