Filter context
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
Use a Painless script as a filter in a query to include and exclude documents.
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
Listof values.
boolean- Return
trueif the current document should be returned as a result of the query, andfalseotherwise.
The standard Painless API is available.
To run the example, first install the eCommerce sample data.
This example filters documents where the average price per item in an order exceeds a minimum threshold of 30.
Filters answer the question “Does this document match?” with a simple “Yes or No” response. Use filter context for all conditions that don’t need scoring. Refer to Query and filter context to learn more.
GET kibana_sample_data_ecommerce/_search
{
"query": {
"bool": {
"filter": {
"script": {
"script": {
"source": """
(doc['taxful_total_price'].value / doc['total_quantity'].value) > params.min_avg_price
""",
"params": {
"min_avg_price": 30
}
}
}
}
}
}
}