﻿---
title: Filter context
description: Use a Painless script as a filter in a query to include and exclude documents. Variables Return API The standard Painless API is available. Example To...
url: https://www.elastic.co/elastic/docs-builder/docs/2509/reference/scripting-languages/painless/painless-filter-context
products:
  - Painless
---

# Filter context
Use a Painless script as a [filter](https://www.elastic.co/elastic/docs-builder/docs/2509/reference/query-languages/query-dsl/query-dsl-script-query) in a query to include and exclude documents.
**Variables**
<definitions>
  <definition term="params (Map, read-only)">
    User-defined parameters passed in as part of the query.
  </definition>
  <definition term="doc (Map, read-only)">
    Contains the fields of the current document where each field is a `List` of values.
  </definition>
</definitions>

**Return**
<definitions>
  <definition term="boolean">
    Return `true` if the current document should be returned as a result of the query, and `false` otherwise.
  </definition>
</definitions>

**API**
The standard [Painless API](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared.html) is available.
**Example**
To run this example, first follow the steps in [context examples](https://www.elastic.co/elastic/docs-builder/docs/2509/reference/scripting-languages/painless/painless-context-examples).
This script finds all unsold documents that cost less than $25.
```java
doc['sold'].value == false && doc['cost'].value < 25
```

Defining `cost` as a script parameter enables the cost to be configured in the script query request. For example, the following request finds all available theatre seats for evening performances that are under $25.
```json

{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": {
            "source": "doc['sold'].value == false && doc['cost'].value < params.cost",
            "params": {
              "cost": 25
            }
          }
        }
      }
    }
  }
}
```