New

The executive guide to generative AI

Read more

Script query

edit

Filters documents based on a provided script. The script query is typically used in a filter context.

Example request

edit
GET /_search
{
    "query": {
        "bool" : {
            "filter" : {
                "script" : {
                    "script" : {
                        "source": "doc['num1'].value > 1",
                        "lang": "painless"
                     }
                }
            }
        }
    }
}

Top-level parameters for script

edit
script
(Required, script object) Contains a script to run as a query. This script must return a boolean value, true or false.

Notes

edit

Custom Parameters

edit

Like filters, scripts are cached for faster execution. If you frequently change the arguments of a script, we recommend you store them in the script’s params parameter. For example:

GET /_search
{
    "query": {
        "bool" : {
            "filter" : {
                "script" : {
                    "script" : {
                        "source" : "doc['num1'].value > params.param1",
                        "lang"   : "painless",
                        "params" : {
                            "param1" : 5
                        }
                    }
                }
            }
        }
    }
}
Was this helpful?
Feedback