Kibana scripted field is not showing value

I am new to kibana..
I am trying to create a scripted field, when I run the script nothing is displayed in the result.
however, when I filter the field I get the expected result.. why is this not propagating?... what am I doing wrong ?

if (doc['failed_login_count'].value <= 5) {
     "Low"
}else if (doc['failed_login_count'].value > 5 && doc['failed_login_count'].value <= 10) {
     "Medium"
}else {
    "High"

Can you try to execute the script directly in a query in the Kibana DevTools? You may get better feedback there.

I've created a minimal index with some data and your script runs as expected.

# Create index
PUT discuss-322183
{
  "settings": {
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "failed_login_count": {"type": "integer"}
    }
  }
}

# Add some data
POST discuss-322183/_bulk
{"index": {}}
{"failed_login_count": 1}
{"index": {}}
{"failed_login_count": 7}
{"index": {}}
{"failed_login_count": 15}

# Search with an scripted field
GET discuss-322183/_search
{
  "_source": ["failed_login_count"], 
  "script_fields": {
    "count": {
      "script": {
        "source": """
if (doc['failed_login_count'].value <= 5) {
     "Low"
}else if (doc['failed_login_count'].value > 5 && doc['failed_login_count'].value <= 10) {
     "Medium"
}else {
    "High"
}
        """,
        "lang": "painless"
      }
    }
  },
  "query": {
    "match_all": {}
  }
}

# clean up
DELETE discuss-322183

I don't have permission to use DevTool and need to do it using scripted field... I have been told its because I have not questioned if it exists or not... but not sure the right coding to do so... I have tried a few but nothing works so far

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