Search code examples
elasticsearchkibana

Elasticsearch 3 of 280 shards failed error - has anyone seen anything like this before and knows how to fix it?


Every time I load the dashboard based on this index, this error keeps popping up

My visualisations still look fine and the data is still appearing, I have just never come across this error before. Any ideas on how I can fix this issue?

Here is the response from the error popup:

{
  "took": 1137,
  "timed_out": false,
  "terminated_early": false,
  "_shards": {
    "total": 280,
    "successful": 277,
    "skipped": 0,
    "failed": 3,
    "failures": [
      {
        "shard": 1,
        "index": "nbs_comprehend-2021-w41",
        "node": "oGEHA-aRSnmwuEmqSZc6Kw",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "org.elasticsearch.index.fielddata.ScriptDocValues$Longs.get(ScriptDocValues.java:121)",
            "org.elasticsearch.index.fielddata.ScriptDocValues$Longs.getValue(ScriptDocValues.java:115)",
            "doc['user.followers_count'].value > 9999 ? 1 : 0",
            "                           ^---- HERE"
          ],
          "script": "doc['user.followers_count'].value > 9999 ? 1 : 0",
          "lang": "painless",
          "position": {
            "offset": 27,
            "start": 0,
            "end": 48
          },
          "caused_by": {
            "type": "illegal_state_exception",
            "reason": "A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"
          }
        }
      }
    ]
  },
  "hits": {
    "total": 696059,
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "termsAgg": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": 0,
          "doc_count": 604397
        },
        {
          "key": 1,
          "doc_count": 91662
        }
      ]
    }
  }
}

Solution

  • you've got a document with a field that doesn't have a value for user.followers_count. your scripted field is not checking for that at all and so things error when it can't return any value. that's what A document doesn't have a value for a field is saying in the error

    try this, which will return a zero if the field is empty, basically creating a default value;

    if (doc['user.followers_count'].size() == 0) { return "0" } else { return doc['user.followers_count'].value > 9999 ? 1 : 0 }