Vega-Lite condition in Kibana unexpected behaviour

Hi.

I'm creating a custom visualization using Vega-Lite in Kibana. I have one rectangle per document in my index, and based on a field (flag) in the document color the box either red or green.

However, I've come across some strange behaviour, and would appreciate if anyone can explain if this is expected and if so how to deal with it, or if it might be a bug.

This is what I'd like my visualization to look like:

However, when I use the following code, I only get green boxes (the defaul value if the condition is not met)

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json"
  "data":
    {
      "name": "check_data",
      "url": {
        "index": "my_index",
        "body": {
          query: {
                bool: {
                  must: [
                    "%dashboard_context-must_clause%"
                  ]
                  must_not: [
                    "%dashboard_context-must_not_clause%"
                  ]
                  filter: [
                    "%dashboard_context-filter_clause%"
                  ]
                }
              }
          "size": 200
        }
      },
      "format": {"property": "hits.hits"}
    },
  "concat": [
    {
      "columns": 14,
      "facet": {
        "field": "_source.actor_cp_id",
        "title": "Status"
      },
      "spec": {
          "layer": [
            {
              "mark": {
                "type": "rect"
              },
              "width": 60,
              "height": 40,
              "encoding": {
                "href": {"field": "url"},
                "color": {
                  "condition":{"test": "datum['_source.alvorlig_feil'] == 1", "value" : "red"},
                  "value": "green"
                }
              }
            },
            {
              "mark": {
              "type": "text"
              },
              "encoding": {
                "text": {
                  "condition": {"test": "datum['_source.alvorlig_feil'] == 1", "value" : "Problem"},
                  "value": "OK"
                },
                "color": {
                  "value": "white"
                }
              }
            }
        ]
      }
    }
  ]
}

This code produces the following visualization:

Only when I include a mark where I use the field that is also part of the condition, does it seem like the condition is actually able to evaluated to true. Heres the code that gives the correct visualization shown in the start of this topic. Note the first mark which uses the field but is hidden behind the other layers (I do not wish to include the value of the field, as it is just a flag):

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json"
  "data":
    {
      "name": "check_data",
      "url": {
        "index": "my_index",
        "body": {
          query: {
                bool: {
                  must: [
                    "%dashboard_context-must_clause%"
                  ]
                  must_not: [
                    "%dashboard_context-must_not_clause%"
                  ]
                  filter: [
                    "%dashboard_context-filter_clause%"
                  ]
                }
              }
          "size": 200
        }
      },
      "format": {"property": "hits.hits"}
    },
  "concat": [
    {
      "columns": 14,
      "facet": {
        "field": "_source.actor_cp_id",
        "title": "Status"
      },
      "spec": {
          "layer": [
            {
              "mark": {
              "type": "text",
              },
              "encoding": {
                "text": {"field": "_source.alvorlig_feil"},
                "color": {
                  "value": "white"
                }
              }
            },
            {
              "mark": {
                "type": "rect"
              },
              "width": 60,
              "height": 40,
              "encoding": {
                "href": {"field": "url"},
                "color": {
                  "condition":{"test": "datum['_source.alvorlig_feil'] == 1", "value" : "red"},
                  "value": "green"
                }
              }
            },
            {
              "mark": {
              "type": "text"
              },
              "encoding": {
                "text": {
                  "condition": {"test": "datum['_source.alvorlig_feil'] == 1", "value" : "Problem"},
                  "value": "OK"
                },
                "color": {
                  "value": "white"
                }
              }
            }
        ]
      }
    }
  ]
}

Expected? It seems like I somehow need to make the information in the field availabe to be evaluated? Any input is appreciated.

Thanks!

datum['_source.alvorlig_feil'] is right syntax?
How about datum['_source']['alvorlig_feil'] or datum._source.alvorlig_feil??

Thank you for the suggestion! This

datum._source.alvorlig_feil

seems to be the correct way to do it.

1 Like

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