# \_source variables in post\_filter

**URL:** <https://discuss.elastic.co/t/source-variables-in-post-filter/139841>\
**Category:** Elasticsearch\
**Created:** [July 12, 2018, 9:43pm UTC](https://discuss.elastic.co/t/source-variables-in-post-filter/139841 "2018-07-12T21:43:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Keith](https://avatars.discourse-cdn.com/v4/letter/b/c57346/32.png) [@Brian\_Keith](https://discuss.elastic.co/u/Brian_Keith)\
**Post date:** [July 12, 2018, 9:43pm UTC](https://discuss.elastic.co/t/source-variables-in-post-filter/139841/1 "2018-07-12T21:43:53Z")

</div>

I was using ES 5.4 and upgraded to 6.3. In 5.4 using a painless script in a post\_filter I was able to access array data from a document like `def lists = params._source['lists'];`. Now in 6.3 I don't seem to be able to access the data.

```auto
PUT my_index/_doc/1
{
  "message": "some arrays in this document...",
  "tags": ["elasticsearch", "wow"], 
  "lists": [ 
    {
      "name": "prog_list",
      "description": "programming list"
    },
    {
      "name": "cool_list",
      "description": "cool stuff list"
    }
  ]
}

PUT my_index/_doc/2 
{
  "message": "no arrays in this document...",
  "tags": "elasticsearch",
  "lists": {
    "name": "prog_list 2",
    "description": "programming list 2"
  }
}

GET my_index/_search
{
  "query": {
    "match": {
      "tags": "elasticsearch" 
    }
  },
  "stored_fields": [
    "_source"
  ],
  "post_filter": {
    "script": {
      "script": {
        "source": """
            def lists = params._source.lists ;
            if (lists[0].name === 'prog_list') {
              return true;
            }
            return false;
        """
      }
    }
  }
}

```

Result is

```auto
{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 3,
    "skipped": 0,
    "failed": 2,
    "failures": [
      {
        "shard": 2,
        "index": "my_index",
        "node": "mDf0dL9ISkSrEqNjWe2BFQ",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "lists = params._source['lists'];\n ",
            " ^---- HERE"
          ],
          "script": """
            def lists = params._source['lists'];
            if (lists[0].name === 'prog_list') {
              return true;
            }
            return false;
""",
          "lang": "painless",
          "caused_by": {
            "type": "null_pointer_exception",
            "reason": null
          }
        }
      }
    ]
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

```

I tried using doc['lists'] and got an `No field found for [lists] in mapping with types []`

Is there anyway to access that array?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [July 12, 2018, 10:34pm UTC](https://discuss.elastic.co/t/source-variables-in-post-filter/139841/2 "2018-07-12T22:34:10Z")

</div>

Access to \_source was intentionally removed in filter scripts as it is incredibly trappy due to the orders of magnitude performance difference compared to using doc values.

Have you considered denormalizing your inner objects? Or using an inner hits query?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 9, 2018, 10:34pm UTC](https://discuss.elastic.co/t/source-variables-in-post-filter/139841/3 "2018-08-09T22:34:10Z")

</div>

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