title: Elasticsearch gives [function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]
body: <p>I have a query as follows to use function_score but it gives an error that the query is malformed  and [END_OBJECT] is expected but found [FIELD_NAME]. I have checked the documentation and couldn't find what is incorrect or inconsistent with this. I haven't added any script in script_score here but even when I tried with adding script it gave the same problem. </p>
  
  <pre><code>{
    "from": 0,
    "query": {
      "function_score": {
        "query": {
          "bool": {
            "filter": [
              {
                "bool": {
                  "should": [
                    {
                      "bool": {
                        "must": [
                          {
                            "match": {
                              "address.area.area.raw": "Durbarmarg"
                            }
                          },
                          {
                            "match": {
                              "address.area.city.raw": "Kathmandu"
                            }
                          },
                          {
                            "match": {
                              "address.area.district.raw": "Kathmandu"
                            }
                          },
                          {
                            "match": {
                              "address.area.state.raw": "State-3"
                            }
                          },
                          {
                            "match": {
                              "address.area.country.raw": "Nepal"
                            }
                          }
                        ]
                      }
                    },
                    {
                      "nested": {
                        "inner_hits": {},
                        "path": "branchAddress",
                        "query": {
                          "bool": {
                            "must": [
                              {
                                "match": {
                                  "branchAddress.area.area.raw": "Durbarmarg"
                                }
                              },
                              {
                                "match": {
                                  "branchAddress.area.city.raw": "Kathmandu"
                                }
                              },
                              {
                                "match": {
                                  "branchAddress.area.district.raw": "Kathmandu"
                                }
                              },
                              {
                                "match": {
                                  "branchAddress.area.state.raw": "State-3"
                                }
                              },
                              {
                                "match": {
                                  "branchAddress.area.country.raw": "Nepal"
                                }
                              }
                            ]
                          }
                        }
                      }
                    }
                  ]
                }
              }
            ],
            "must": [
              {
                "term": {
                  "sub_categories.raw": "Restaurant"
                }
              }
            ],
            "must_not": [],
            "should": []
          }
        }
      },
      "script_score": {}
    },
    "size": 10
  }
  </code></pre>
  
  <p>The error is as bellow:</p>
  
  <pre><code>raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
  elasticsearch.exceptions.RequestError: TransportError(400, 'parsing_exception', '[function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]')
  </code></pre>