Params._source is always null in script query

The following two queries should return the same results:

GET iam-api-accounts/_search
{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": """
            return params._source?.roles?.dance != null && params._source?.roles?.dance != false
          """
        }
      }
    }
  }
}
GET iam-api-accounts/_search
{
  "runtime_mappings": {
    "dance_exists": {
      "type": "boolean",
      "script": """
        emit(params._source?.roles?.dance != null && params._source?.roles?.dance != false);
      """
    }
  },
  "query": {
    "term": {
      "dance_exists": true
    }
  }
}

However, params._source is always null in the first query; only the second one returns the correct results.

Hello @ACoder

I was able to fetch the results using below query :

GET iam-api-accounts/_search
{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": """
            return doc['roles.dance'].size() != 0 && doc['roles.dance'].value != false;
          """
        }
      }
    }
  }
}

I believe at query time we cannot use params._source

Thanks!!