ES版本7.6.0
想篩選某兩個字段之和大于10的文檔,需要用到腳本,簡化的請求如下
{
"query":
{
"bool":
{
"must":
[
{
"script":
{
"script": "doc['field'].value >= 1"
}
}
]
}
}
}
報錯提示field未定義,報錯詳情文章來源:http://www.zghlxwxcb.cn/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
}
解決方法:改用雙引號包裹包裹字段名文章來源地址http://www.zghlxwxcb.cn/news/detail-722303.html
{
"query":
{
"bool":
{
"must":
[
{
"script":
{
"script": "doc[\"field\"].value >= 1"
}
}
]
}
}
}
到了這里,關(guān)于ElasticSearch script查詢報錯Variable [field] is not defined的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!