Return value True or False based on Kibana Script

Hi,

How can I aggregate to return value as True if doc_count != 0 and False if doc_count == 0 in Kibana response?

Below is my query

{
  "query": {
    "range": {
      "timestamp": {
        "gte": "now-1h/h"
      }
    }
  },
  "size": 0,
  "aggs": {
    "get_cmtsId": {
      "terms": {
        "field": "cmtsId",
        "size": 2
      },
    "aggs": {
      "every30min": {
        "date_histogram": {
          "field": "timestamp",
          "fixed_interval": "30m"
        },
        "aggs": {
          "my_filter": {
            "bucket_selector": {
              "buckets_path": {
                "the_doc_count": "_count"
              },
              "script": "params.the_doc_count != 0"
              }
            }
          }
        }
      }
    }
  }
}

Yes, have you tried using scripted fields
https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-operators-boolean.html#painless-operators-boolean

1 Like

Hi Rashmi, thanks I created the scripted field, however I am unsure how to call it in the kibana query so I can see the value as True or False in the result of the query ?

The scripted field is working as expected when I tested it in the test script section of scripted fields.

I can see the field created in the Discover section as well.

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