我使用 elasticsearch 已經兩年多了。
這些天我發現了一個將無痛變數命名為“數字”的奇怪問題。在無痛腳本中使用“數字”(第一個字母大寫)時,發生錯誤。
我成功地重現了這個場景。我使用的是 elasticsearch 6.8 版。
curl -X POST "http://localhost:9201/logs-my_app-default/_search?size=2&pretty" -H 'Content-Type: application/json' -d '{"_source": ["-1"], "script_fields": {"SCRIPT_FLAG": {"script": {"lang": "painless", "source": " def Number = 0; "}}}}'
問題出在: def Number = 0;
拋出的錯誤是:
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
" def Number = 0; ",
" ^---- HERE"
],
"script" : " def Number = 0; ",
"lang" : "painless"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "logs-my_app-default",
"node" : "9jBNNKjdSIO6I8UH_HLVRw",
"reason" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
" def Number = 0; ",
" ^---- HERE"
],
"script" : " def Number = 0; ",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "invalid sequence of tokens near ['Number'].",
"caused_by" : {
"type" : "no_viable_alt_exception",
"reason" : null
}
}
}
}
]
},
"status" : 500
}
這發生在我的任何彈性搜索索引上,es 6.8 版
更準確地說,這是此處顯示的場景中使用的索引。
curl -X POST "localhost:9201/logs-my_app-default/_doc?pretty" -H 'Content-Type: application/json' -d'
{
"@timestamp": "2099-05-06T16:21:15.000Z",
"event": {
"original": "192.0.2.42 - - [06/May/2099:16:21:15 0000] \"GET /images/bg.jpg HTTP/1.0\" 200 24736"
}
}
'
映射也是:
curl -X GET "localhost:9201/logs-my_app-default/_mapping?pretty"
{
"logs-my_app-default" : {
"mappings" : {
"_doc" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"event" : {
"properties" : {
"original" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
}
字串“Number”作為“number”(全部小寫)的任何變體都有效。“麻木”,“麻木”也有效..
有什么幫助嗎?
謝謝你。
解決方案:
幾乎所有這里提到的區分大小寫的關鍵字都拋出與上面相同的錯誤。
對我來說,好的做法是在創建與 elasticsearch 欄位同名的無痛變數時使用下劃線作為前綴。
例如:
def _Number = 0; // instead of def Number = 0,
def _Void = 0; // instead of def Void = 0; ,
def _System = 0; // instead of def System = 0; ..
uj5u.com熱心網友回復:
在無痛的腳本語言是非常相似的Java編程語言,編譯直接進入JVM位元組碼,它的API從Java API,即借用了很多Number類。
因此,您不能Number用作任意變數識別符號。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/365795.html
上一篇:如何剪輯影像以洗掉其填充
