# Filtered documents still get passed to plugin

**URL:** <https://discuss.elastic.co/t/filtered-documents-still-get-passed-to-plugin/49632>\
**Category:** Elasticsearch\
**Created:** [May 10, 2016, 9:40am UTC](https://discuss.elastic.co/t/filtered-documents-still-get-passed-to-plugin/49632 "2016-05-10T09:40:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JrSchild](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jrschild/32/9686_2.png) [@JrSchild](https://discuss.elastic.co/u/JrSchild)\
**Post date:** [May 10, 2016, 9:40am UTC](https://discuss.elastic.co/t/filtered-documents-still-get-passed-to-plugin/49632/1 "2016-05-10T09:40:23Z")

</div>

In our current set-up we use a function\_score in combination with a native Java plugin to calculate the price of lease cars. I would like to add a not filter around it. Currently it looks something like this:

```
"query": {
  "filtered": {
    "filter": {
      "not": {
        "term": {
          "make.facet": "Audi"
        }
      }
    },
    "query": {
      "function_score": {
        "functions": [
          {
            "script_score": {
              "script": "native-score",
              "lang": "native",
              "params": {...}
            }
          }
        ],
        "query": {
          "match_all": {}
        },
        "boost_mode": "replace",
        "min_score": 0
      }
    }
  }
}

```

The problem I am having though is that for the filtered documents the plugin is still called, but without the expected fields. Right now I have solved this with a dirty check in the plugin to see if any of the required fields are set, and if not I simply return `null` to prevent ending up with NPE's. Surely this isn't the best way to fix this. We are using elasticsearch 1.7.5. Is this a bug, or can I re-organize my query in such a way that it works as expected?

---

<div class="post-metadata">

**Author:** ![JrSchild](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jrschild/32/9686_2.png) [@JrSchild](https://discuss.elastic.co/u/JrSchild)\
**Post date:** [May 10, 2016, 9:55am UTC](https://discuss.elastic.co/t/filtered-documents-still-get-passed-to-plugin/49632/2 "2016-05-10T09:55:00Z")

</div>

FWIW; our query generator places the filter inside the query of function\_score. This has the same unwanted effect with the plugin.

---

<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:** [July 5, 2017, 10:52pm UTC](https://discuss.elastic.co/t/filtered-documents-still-get-passed-to-plugin/49632/3 "2017-07-05T22:52:49Z")

</div>

Closed on July 5, 2017, 10:52pm UTC


