IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Filter context
editFilter context
editUse a Painless script as a filter in a query to include and exclude documents.
Variables
-
params
(Map
, read-only) - User-defined parameters passed in as part of the query.
-
doc
(Map
, read-only) -
Contains the fields of the current document where each field is a
List
of values.
Return
-
boolean
-
Return
true
if the current document should be returned as a result of the query, andfalse
otherwise.
API
The standard Painless API is available.
Example
To run this example, first follow the steps in context examples.
This script finds all unsold documents that cost less than $18.
doc['sold'].value == false && doc['cost'].value < 18
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 $18.
GET seats/_search { "query": { "bool": { "filter": { "script": { "script": { "source": "doc['sold'].value == false && doc['cost'].value < params.cost", "params": { "cost": 18 } } } } } } }