Nested value on function score

You'd want to do something like this and you may want to consider using field value factor:

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor

{
  "query": {
    "filtered": {
      "query": {
        "nested": {
          "path": "reviews",
          "query": {
            "function_score": {
              "query": {
                "term": {
                  "reviews.userId": {
                    "value": "1"
                  }
                }
              },
              "functions": [
                {
                  "field_value_factor": {
                    "field": "reviews.rating"
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}
1 Like