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

Structure of the rescore query

Let's now modify our query so that it uses the rescore functionality. Basically, let's assume that we want the score of the document to be equal to the value of the year field. The query that does that would look as follows:

{ 
  "query": { 
    "match_all": {} 
  }, 
  "rescore": { 
    "query": { 
      "rescore_query": { 
        "function_score": { 
          "query": { 
            "match_all": {} 
          }, 
          "script_score": { 
            "script": { 
              "inline": "doc['year'].value", 
              "lang": "painless" 
            } 
          } 
        } 
      } 
    } 
  } 
  "_source": ["title", "available"] 
} 

Let's now look at the preceding query in more detail. The first thing you may have noticed is the rescore object. The mentioned object holds the query that will affect the scoring of the documents returned by the query. In our case, the logic is ...

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