boost-field.asciidoc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. [[mapping-boost-field]]
  2. === `_boost`
  3. deprecated[1.0.0.RC1,See <<function-score-instead-of-boost>>]
  4. Boosting is the process of enhancing the relevancy of a document or
  5. field. Field level mapping allows to define an explicit boost level on a
  6. specific field. The boost field mapping (applied on the
  7. <<mapping-root-object-type,root object>>) allows
  8. to define a boost field mapping where *its content will control the
  9. boost level of the document*. For example, consider the following
  10. mapping:
  11. [source,js]
  12. --------------------------------------------------
  13. {
  14. "tweet" : {
  15. "_boost" : {"name" : "my_boost", "null_value" : 1.0}
  16. }
  17. }
  18. --------------------------------------------------
  19. The above mapping defines a mapping for a field named `my_boost`. If the
  20. `my_boost` field exists within the JSON document indexed, its value will
  21. control the boost level of the document indexed. For example, the
  22. following JSON document will be indexed with a boost value of `2.2`:
  23. [source,js]
  24. --------------------------------------------------
  25. {
  26. "my_boost" : 2.2,
  27. "message" : "This is a tweet!"
  28. }
  29. --------------------------------------------------
  30. [[function-score-instead-of-boost]]
  31. ==== Function score instead of boost
  32. Support for document boosting via the `_boost` field has been removed
  33. from Lucene and is deprecated in Elasticsearch as of v1.0.0.RC1. The
  34. implementation in Lucene resulted in unpredictable result when
  35. used with multiple fields or multi-value fields.
  36. Instead, the <<query-dsl-function-score-query>> can be used to achieve
  37. the desired functionality by boosting each document by the value in
  38. any field the document:
  39. [source,js]
  40. --------------------------------------------------
  41. {
  42. "query": {
  43. "function_score": {
  44. "query": { <1>
  45. "match": {
  46. "title": "your main query"
  47. }
  48. },
  49. "functions": [{
  50. "script_score": { <2>
  51. "script": "doc['my_boost_field'].value"
  52. }
  53. }],
  54. "score_mode": "multiply"
  55. }
  56. }
  57. }
  58. --------------------------------------------------
  59. <1> The original query, now wrapped in a `function_score` query.
  60. <2> This script returns the value in `my_boost_field`, which is then
  61. multiplied by the query `_score` for each document.