boost.asciidoc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. "properties": {
  11. "title": {
  12. "type": "text",
  13. "boost": 2 <1>
  14. },
  15. "content": {
  16. "type": "text"
  17. }
  18. }
  19. }
  20. }
  21. --------------------------------------------------
  22. // CONSOLE
  23. <1> Matches on the `title` field will have twice the weight as those on the
  24. `content` field, which has the default `boost` of `1.0`.
  25. NOTE: The boost is applied only for term queries (prefix, range and fuzzy queries are not _boosted_).
  26. You can achieve the same effect by using the boost parameter directly in the query, for instance the following query (with field time boost):
  27. [source,js]
  28. --------------------------------------------------
  29. POST _search
  30. {
  31. "query": {
  32. "match" : {
  33. "title": {
  34. "query": "quick brown fox"
  35. }
  36. }
  37. }
  38. }
  39. --------------------------------------------------
  40. // CONSOLE
  41. is equivalent to:
  42. [source,js]
  43. --------------------------------------------------
  44. POST _search
  45. {
  46. "query": {
  47. "match" : {
  48. "title": {
  49. "query": "quick brown fox",
  50. "boost": 2
  51. }
  52. }
  53. }
  54. }
  55. --------------------------------------------------
  56. // CONSOLE
  57. 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.]
  58. [WARNING]
  59. .Why index time boosting is a bad idea
  60. ==================================================
  61. We advise against using index time boosting for the following reasons:
  62. * You cannot change index-time `boost` values without reindexing all of your
  63. documents.
  64. * Every query supports query-time boosting which achieves the same effect. The
  65. difference is that you can tweak the `boost` value without having to reindex.
  66. * Index-time boosts are stored as part of the <<norms,`norm`>>, which is only one
  67. byte. This reduces the resolution of the field length normalization factor
  68. which can lead to lower quality relevance calculations.
  69. ==================================================