原文地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-script-query.html, 原文档版权归 www.elastic.co 所有
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Script queryedit
Filters documents based on a provided script. The
script
query is typically used in a filter context.
Example requestedit
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
orfalse
.
Notesedit
Custom Parametersedit
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 } } } } } } }
Allow expensive queriesedit
Script queries will not be executed if search.allow_expensive_queries
is set to false.