原英文版地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-script-query.html, 原文档版权归 www.elastic.co 所有
本地英文版地址: ../en/query-dsl-script-query.html
本地英文版地址: ../en/query-dsl-script-query.html
重要: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 当前版本文档。
基于指定的 script 过滤文档。
script 查询通常在 filter上下文中使用。
GET /_search
{
"query": {
"bool" : {
"filter" : {
"script" : {
"script" : {
"source": "doc['num1'].value > 1",
"lang": "painless"
}
}
}
}
}
}
-
script -
(必需, script object) 包含作为查询运行的脚本。
这个脚本必须返回一个布尔值,
true或false。
像 filters 一样,脚本被缓存以加快执行速度。
如果经常更改脚本的参数,建议将它们存储在脚本的 params 参数中。
例如:
GET /_search
{
"query": {
"bool" : {
"filter" : {
"script" : {
"script" : {
"source" : "doc['num1'].value > params.param1",
"lang" : "painless",
"params" : {
"param1" : 5
}
}
}
}
}
}
}
如果 search.allow_expensive_queries 设置为 false,脚本查询不会被执行。