ES版本7.6.0
想筛选某两个字段之和大于10的文档,需要用到脚本,简化的请求如下
{
"query":
{
"bool":
{
"must":
[
{
"script":
{
"script": "doc['field'].value >= 1"
}
}
]
}
}
}
报错提示field未定义,报错详情文章来源:https://www.toymoban.com/news/detail-722303.html
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"doc[field]. ...",
" ^---- HERE"
],
"script" : "doc[field].value >= 1",
"lang" : "painless"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "...",
"node" : "...",
"reason" : {
"type" : "query_shard_exception",
"reason" : "failed to create query: ...",
"index_uuid" : "...",
"index" : "...",
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"doc[field]. ...",
" ^---- HERE"
],
"script" : "doc[field].value >= 1",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [field] is not defined."
}
}
}
}
],
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"doc[field]. ...",
" ^---- HERE"
],
"script" : "doc[field].value >= 1",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [field] is not defined."
}
}
},
"status" : 400
}
解决方法:改用双引号包裹包裹字段名文章来源地址https://www.toymoban.com/news/detail-722303.html
{
"query":
{
"bool":
{
"must":
[
{
"script":
{
"script": "doc[\"field\"].value >= 1"
}
}
]
}
}
}
到了这里,关于ElasticSearch script查询报错Variable [field] is not defined的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!