boost.asciidoc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. [[index-boost]]
  2. === `boost`
  3. Individual fields can be _boosted_ -- count more towards the relevance score
  4. -- at index 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 that a `title` field will usually be shorter than a `content` field. The
  28. default relevance calculation takes field length into account, so a short
  29. `title` field will have a higher natural boost than a long `content` field.
  30. [WARNING]
  31. .Why index time boosting is a bad idea
  32. ==================================================
  33. We advise against using index time boosting for the following reasons:
  34. * You cannot change index-time `boost` values without reindexing all of your
  35. documents.
  36. * Every query supports query-time boosting which achieves the same effect. The
  37. difference is that you can tweak the `boost` value without having to reindex.
  38. * Index-time boosts are stored as part of the <<norms,`norm`>>, which is only one
  39. byte. This reduces the resolution of the field length normalization factor
  40. which can lead to lower quality relevance calculations.
  41. ==================================================
  42. The only advantage that index time boosting has is that it is copied with the
  43. value into the <<mapping-all-field,`_all`>> field. This means that, when
  44. querying the `_all` field, words that originated from the `title` field will
  45. have a higher score than words that originated in the `content` field.
  46. This functionality comes at a cost: queries on the `_all` field are slower
  47. when index-time boosting is used.