{
“query”:
{
“bool”:
{
“must”:
[
{
“script”:
{
“script”: “doc[‘field’].value >= 1”
}
}
]
}
}
}
报错提示field未定义,报错详情
{
"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
}
解决方法:改用双引号包裹包裹字段名
{
"query":
{
"bool":
{
"must":
[
{
"script":
{
"script": "doc[\"field\"].value >= 1"
}
}
]
}
}
}