boost.asciidoc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. [[mapping-boost]]
  2. === `boost`
  3. Individual fields can be _boosted_ automatically -- count more towards the relevance score
  4. -- at query time, with the `boost` parameter as follows:
  5. [source,js]
  6. --------------------------------------------------
  7. PUT my_index
  8. {
  9. "mappings": {
  10. "my_type": {
  11. "properties": {
  12. "title": {
  13. "type": "string",
  14. "boost": 2 <1>
  15. },
  16. "content": {
  17. "type": "string"
  18. }
  19. }
  20. }
  21. }
  22. }
  23. --------------------------------------------------
  24. // AUTOSENSE
  25. <1> Matches on the `title` field will have twice the weight as those on the
  26. `content` field, which has the default `boost` of `1.0`.
  27. NOTE: The boost is applied only for term queries (prefix, range and fuzzy queries are not _boosted_).
  28. You can achieve the same effect by using the boost parameter directly in the query, for instance the following query (with field time boost):
  29. [source,js]
  30. --------------------------------------------------
  31. {
  32. "match" : {
  33. "title": {
  34. "query": "quick brown fox"
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. is equivalent to:
  40. [source,js]
  41. --------------------------------------------------
  42. {
  43. "match" : {
  44. "title": {
  45. "query": "quick brown fox",
  46. "boost": 2
  47. }
  48. }
  49. }
  50. --------------------------------------------------
  51. // AUTOSENSE
  52. The boost is also applied when it is copied with the
  53. value in the <<mapping-all-field,`_all`>> field. This means that, when
  54. querying the `_all` field, words that originated from the `title` field will
  55. have a higher score than words that originated in the `content` field.
  56. This functionality comes at a cost: queries on the `_all` field are slower
  57. when field boosting is used.
  58. deprecated[5.0.0, index time boost is deprecated. Instead, the field mapping boost is applied at query time. For indices created before 5.0.0 the boost will still be applied at index time.]
  59. [WARNING]
  60. .Why index time boosting is a bad idea
  61. ==================================================
  62. We advise against using index time boosting for the following reasons:
  63. * You cannot change index-time `boost` values without reindexing all of your
  64. documents.
  65. * Every query supports query-time boosting which achieves the same effect. The
  66. difference is that you can tweak the `boost` value without having to reindex.
  67. * Index-time boosts are stored as part of the <<norms,`norm`>>, which is only one
  68. byte. This reduces the resolution of the field length normalization factor
  69. which can lead to lower quality relevance calculations.
  70. ==================================================