O'Reilly logo

Mastering Elasticsearch 5.x - Third Edition by Bharvi Dixit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Built-in functions under the function score query

The following are the built-in functions available to be used with the function_score query:

  • The weight function
  • The field_value_factor function
  • The script_score function
  • Decay functions - linear, exp, gauss

Let's look at them one by one.

The weight function

The weight function allows you to apply a simple boost to each document without the boost being normalized: a weight of 2 results in 2 * _score. For example:

curl -XGET "http://localhost:9200/library/_search" -d' 
{ 
  "query": { 
    "function_score": { 
      "query": { 
        "match": { 
          "tags": "novel" 
        } 
      }, 
      "functions": [ 
        { 
          "filter": { 
            "term": { 
              "tags": "classics" 
            } 
          }, 
          "weight": 2 
        } 
      ], 
      "boost_mode": "replace" 
    } 
  } 
}'

The preceding query will match all the books which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required