Can we use a field in script score which is excluded in _source

Index mapping:

{
    "index":
    {
        "mappings":
        {
            "dynamic": "strict",
            "_source":
            {
                "excludes":
                [
                    "patientClaims"
                ]
            },
            "properties":
            {
                "patientClaims":
                {
                    "properties":
                    {
                      "diagnosisIcdCode": {
                        "type": "keyword"
                      },
                        "diversity":
                        {
                            "type": "keyword"
                        }
                    }
                }
            }
        }
    }
}

Query:

{
  "from": 0,
  "size": 20,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "function_score": {
                "query": {
                  "has_child": {
                    "type": "claim",
                    "score_mode": "sum", 
                    "query": {
                      "function_score": {
                        "query": {
                          "bool": {
                            "filter": [
                              {
                                "terms": {
                                  "patientClaims.diagnosisIcdCode": [
                                    "E7021"
                                  ]
                                }
                              }
                            ]
                          }
                        },
                        "functions": [
                          {
                            "script_score": {
                              "script": "doc['patientClaims.diversity'].size()==0 ? 0 : (doc['patientClaims.diversity'].value == 'White Non-Hispanic' ? 0 : 1)"
                            }
                          }
                        ]
                      }
                    },
                    "inner_hits":
                    {
                        "name": "patient_claims_matching_count",
                        "size": 0,
                        "_source": false
                    }
                  }
                }
              }
            }
          ]
        }
      }
    }
  }
}

Top score is zero, nothing matches. Can we not use those fields which are excluded from _source in scrip score?

From our scripting docs:

Field values can be accessed from a script using doc-values, the _source field, or stored fields.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.