YY of XX shards failed - illegal_argument_exception

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"
          }
        }
      },
.... 




Hi @ehsan001, here's the root cause of the error.

"reason": "not all paths return a value for lambda"

The code need to return something for every branch.

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];
    }
    // TODO return here
}else{
    return null;
}

Perhaps you can simply drop the top else?

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];
    }
}
return null;

@stu I have tried both cases and still getting an error - This time null pointer exception. Any additional thought? Please let me know if more info is needed.



{
  "took": 37,
  "timed_out": false,
  "_shards": {
    "total": 48,
    "successful": 18,
    "skipped": 18,
    "failed": 30,
    "failures": [
      {
        "shard": 0,
        "index": "xxxxxxxxxxx-2021-08-29",
        "node": "xxxxxxxxxxxxxxxxxxxxxxxxx",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "if(params['_source']['qslot_cwd_susp_ids'] != null){\r\n        def ",
            "         ^---- 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')) { ...",
          "lang": "painless",
          "position": {
            "offset": 179,
            "start": 170,
            "end": 236
          },
          "caused_by": {
            "type": "null_pointer_exception",
            "reason": null
          }
        }
      }
.....

Also I changed null to "N/A" and same error:

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 "N/A";
    }
}
return "N/A";

{
  "took": 18,
  "timed_out": false,
  "_shards": {
    "total": 48,
    "successful": 18,
    "skipped": 18,
    "failed": 30,
    "failures": [
      {
        "shard": 0,
        "index": "xxxxxx-2021-08-29",
        "node": "XXXXXXXXXXX",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "if(params['_source']['qslot_cwd_susp_ids'] != null){\r\n        def ",
            "         ^---- 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')) { ...",
          "lang": "painless",
          "position": {
            "offset": 179,
            "start": 170,
            "end": 236
          },
          "caused_by": {
            "type": "null_pointer_exception",
            "reason": null
          }
        }
      },
....

An error occurred when loading data.

Show details of error
[lens_merge_tables] > [esaggs] > Cannot read properties of undefined (reading 'other-filter')

I notice you're checking if the document contains the key, but then accessing params['_source'][XXX].

Try using doc instead of params['_source'],
eg

if (doc['qslot_cwd_susp_ids'].size() > 0) { 
  def cwd = doc['qslot_cwd_susp_ids'].value
  ...

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.