Hi, I am using Kibana version 7.11.1 and when trying to create an Lens visualization for one of painless scripted fields getting the below error. Any recommendation how to resolve the issue?
Mapping used to create a new daily index:
The indices are created daily and have the same mapping - already checked. However, each document contains either "qslot_modelpath_susp_ids" or "qslot_cwd_susp_ids" and the number varies each day.
"mappings": {
"properties": {
"@timestamp": {
"format": "yyyy-MM-dd HH:mm:ss||epoch_millis",
"type": "date"
},
"id": {
"type": "keyword"
},
"user": {
"type": "keyword"
},
"a": {
"type": "keyword"
},
"b": {
"type": "long"
},
"c": {
"type": "long"
},
"d": {
"type": "text"
},
"qslot_cwd_susp_ids": {
"type": "text"
},
"e": {
"type": "text"
},
"qslot_modelpath_susp_ids": {
"type": "text"
},
"f": {
"type": "long"
},
"g": {
"type": "long"
},
"h": {
"type": "long"
},
"i": {
"type": "long"
},
"g": {
"type": "long"
},
"k": {
"type": "boolean"
},
"l": {
"type": "long"
},
"m": {
"type": "boolean"
}
}
}
Painless Script:
Note: did not use doc['some_field'].value because the field type is text (above).
if (doc.containsKey('qslot_cwd_susp_ids') || doc.containsKey('qslot_modelpath_susp_ids')) {
if(params['_source']['qslot_cwd_susp_ids'] != null){
def cwd = params['_source']['qslot_cwd_susp_ids'];
String cwd_str = cwd[0];
String[] cwd_str_trim = cwd_str.splitOnToken(",");
String[] cwd_str_prj = cwd_str_trim[0].splitOnToken("/");
return cwd_str_prj[2];
}else if(params['_source']['qslot_modelpath_susp_ids'] != null){
def modelpath = params['_source']['qslot_modelpath_susp_ids'];
String modelpath_str = modelpath[0];
String[] modelpath_str_trim = modelpath_str.splitOnToken(",");
String[] modelPath_str_prj = modelpath_str_trim[0].splitOnToken("/");
return modelPath_str_prj[2];
}
}else{
return null;
}
GET xxxxxxxx-*/_search
{
"query": {
"bool": {
"should": [
{
"range": {
"updated": {
"gte": "2019-06-10"
}
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "qslot_modelpath_susp_ids"
}
}
]
}
}
]
}
}
}
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 47,
"successful" : 47,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 95,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "xxxxxxxx-2021-07-xx-reindex",
"_type" : "_doc",
"_id" : "xxxxxxxxxxxxxxxx",
"_score" : 0.0,
"_source" : {
"?" : [
xx,
yy
],
"??" : "",
"???" : "bb",
"????" : "ccc",
"?????" : [ ],
"??????" : 64,
"????????" : 0,
"??????????" : [ ],
"???????????" : [ ],
"??????" : [
"xxxxxx"
],
"?" : [ ],
"qslot_cwd_susp_ids" : [
"x/y/z,/nfs/xxxx,None"
],
"user" : "xxxxxx",
"timestamp" : "2021-07-29T10:10:02"
}
}
....
GET xxxxxx-*/_search
{
"query": {
"bool": {
"should": [
{
"range": {
"updated": {
"gte": "2019-06-10"
}
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "qslot_cwd_susp_ids"
}
}
]
}
}
]
}
}
}
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 47,
"successful" : 47,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1521,
"relation" : "eq"
},
"max_score" : 0.0,
"hits" : [
{
"_index" : "xxxxxx-2021-08-13",
"_type" : "_doc",
"_id" : "xxxxxxxxxx",
"_score" : 0.0,
"_source" : {
"timestamp" : "2021-08-13T13:50:04",
"?" : "xxxxx",
"??" : "xxxxxxxx",
"???" : [
00000
],
"????" : [
"abc",
"zyz"
],
"?????" : [ ],
"??????" : [ ],
"???????" : "true",
"????????" : 0,
"??????????" : "false",
"???????????" : [ ],
"????????????" : [
16,
18
],
"?????????????" : [ ],
"qslot_modelpath_susp_ids" : [
"/x/p/j,/nfs/abc,None",
"/z/p/j/nfs/abc,None",
"/q/p/d,/nfs/abc,None"
],
"???????????????" : [
1111111
]
}
}
....
Error When to trying to visualize data:
{
"took": 19,
"timed_out": false,
"_shards": {
"total": 47,
"successful": 18,
"skipped": 18,
"failed": 29,
"failures": [
{
"shard": 0,
"index": "xxxxxxxx-2021-08-29",
"node": "xxxxxxxxxxxxxxxxx",
"reason": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"... rn s.get() == v;}compare(() -> { if (doc.containsK ...",
" ^---- HERE"
],
"script": "boolean compare(Supplier s, def v) {return s.get() == v;}compare(() -> { if (doc.containsKey('qslot_cwd_susp_ids') || doc.containsKey('qslot_modelpath_susp_ids')) {\r\n if(params['_source']['qslot_cwd_susp_ids'] != null){\r\n def cwd = params['_source']['qslot_cwd_susp_ids'];\r\n String cwd_str = cwd[0];\r\n String[] cwd_str_trim = cwd_str.splitOnToken(\",\");\r\n String[] cwd_str_prj = cwd_str_trim[0].splitOnToken(\"/\");\r\n return cwd_str_prj[2];\r\n \r\n }else if(params['_source']['qslot_modelpath_susp_ids'] != null){\r\n def modelpath = params['_source']['qslot_modelpath_susp_ids'];\r\n String modelpath_str = modelpath[0];\r\n String[] modelpath_str_trim = modelpath_str.splitOnToken(\",\");\r\n String[] modelPath_str_prj = modelpath_str_trim[0].splitOnToken(\"/\");\r\n return modelPath_str_prj[2];\r\n }\r\n}else{\r\n return null;\r\n} }, params.value);",
"lang": "painless",
"position": {
"offset": 65,
"start": 40,
"end": 90
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "not all paths return a value for lambda"
}
}
},
....