Function_score boost_mode broken in version 5

I am having problems with "function_score" queries involving the combination of a query with a list of functions.

I get the impression that the "boost_mode" is being ignored. This used to work in version 2.4.0

Here is an example.

Start with these four documents:

POST /test/test/1
{
  "description": "banana",
  "date": "2016-01-01"
}

POST /test/test/2
{
  "description": "orange",
  "date": "2016-02-01"
}


POST /test/test/3
{
  "description": "banana",
  "date": "2016-03-01"
}

POST /test/test/4
{
  "description": "orange",
  "date": "2016-04-01"
}

The following query returns the three desired documents, but they all get scores of zero.

If I replace the bool/filter with bool/must, I get scores of 6 and 4 even though the "replace" directive should have resulted in scores of 3 and 2.
If I use "explain=true" it looks like it is still multiplying the query score by the weights.
If I go back to my original bool/filter but remove the second ("gte") range filter, then one of the documents gets a score of 2, but the others get scores of zero.

Note: the query seems to work in version 2.4.0, but not in 5.0.0

GET /test/test/_search
{
  "query": {
    "function_score": {
      "boost_mode": "replace",
      "score_mode": "max",
      "query": {
        "bool": {
          "filter": [
            {
              "range": {
                "date": {
                  "lte": "2016-03-01"
                }
              }
            },
            {
              "range": {
                "date": {
                  "gte": "2015-01-01"
                }
              }
            }
          ]
        }
      },
      "functions": [
        {
          "weight": 3,
          "filter": {
            "match": {
              "description": "banana"
            }
          }
        },
        {
          "weight": 2,
          "filter": {
            "match": {
              "description": "orange"
            }
          }
        }
      ]
    }
  }
}

This has now been fixed in version 5.2. :smile: