title: How is Elasticsearch calculating the scores in this Function Score Query? Strange behaviour
body: <p>I am using a <code>script_score</code> to calculate the score based on the value of a field, let's call it <code>likeability</code> it is of type <code>float</code>. </p>
  
  <p>The script is:</p>
  
  <pre><code>_score * (1 + _doc['likeability'].value)
  </code></pre>
  
  <p>I have some identical documents except for the <code>likeability</code> and the id of course.</p>
  
  <p>When I run the function score query as below, I get the following results:</p>
  
  <pre><code>id | likeability | score
  A  | 3.5         | 56.961056
  B  | 2.0         | 37.974037
  C  | 1.5         | 31.645031
  D  | 0.5         | 18.987019
  E  | 1.0         | 16.044298
  F  | 0.0         |  8.022149 
  </code></pre>
  
  <p>Strangely with a likeability of <code>0.5</code> document D gets a higher score than E with a likeability of <code>1.0</code>.</p>
  
  <p>Has anyone an idea of why this is the case?</p>
  
  <p>I had this problem on my machine and it disappeared. But now is happening on another machine.</p>
  
  <p>Can this have something to do with the number of shards?</p>
  
  <p>Here is my query: </p>
  
  <pre><code>{
    "from": 0,
    "size": 50,
    "query": {
      "function_score": {
        "query": { ... }
        },
        "functions": [
          {
            "filter": {
              "match_all": {
                "boost": 1.0
              }
            },
            "script_score": {
              "script": {
                "inline": "_score * (1 + doc['likeability'].value)",
                "lang": "painless"
              }
            }
          }
        ],
        "score_mode": "multiply",
        "boost_mode" : "replace",
        "max_boost": 3.4028235E+38,
        "boost": 1.0
      }
    }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I double checked again, and as it seems it might have to do something with shards, because if I calculate the <code>_score</code> out of the script it turns out there are two values for it:</p>
  
  <pre><code>id | likeability | score
  
  _score of 12,65777
  A  | 3.5         | 56.961056
  B  | 2.0         | 37.974037 
  C  | 1.5         | 31.645031 
  D  | 0.5         | 18.987019 
  
  _score of 8.022149
  E  | 1.0         | 16.044298 
  F  | 0.0         |  8.022149
  
  </code></pre>