Dynamic textbox from kibana dataview

Hi community,

with directly in json embedded data a dynamic text will work like this:

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": {
    "name": "dataName",
    "values": [
      {"c1": "1", "c2": "2", "text": "TextboxText01"},
      {"c1": "1", "c2": "2", "text": "TextboxText01"},
    ]
  },

  "marks":[  
    {"type": "text",
      "encode": {
        "enter": {
          "text": {"signal": "data('dataName')[0]['text']"},
        }
      }
    },
  ]
}

The textbox shows 'TextboxText01'. But when I try to do the same with a Kibana-Dataview the procedure fails and it just doesn't show anything

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": {
    "name":"dataName"
    "url": {
      "index": "questions",
    }
    "format": {"property": "hits.hits"}
  },

  "marks":[  
    {"type": "text",
      "encode": {
        "enter": {
          "text": {"signal": "data('dataName')[0]['questionText']"}
        }
      }
    }
  ]
}

Thereby 'questionText' is one field of the index 'questions'. What would be the correct expression to show one field of the index (of one row, of course) in the textbox?

Hi @joerg55

you're pretty close to that, just missing to access the _source path before questionText:

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": {
    "name":"dataName"
    "url": {
      "index": "questions",
      body: {
      }
    }
    "format": {"property": "hits.hits"}
  },

  "marks":[  
    {"type": "text",
      "encode": {
        "enter": {
          "text": {"signal": "data('dataName')[0]['_source']['questionText']"}
        }
      }
    }
  ]
}

In general, I would recommend to avoid to specify which fields to retrieve in the search request because:

  • makes the response lighter and use less bandwidth
  • retrieve only what's needed and it's easier to debug
{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": {
    "name":"dataName"
    "url": {
      "index": "questions",
      body: {
        _source: false,
       fields: ["questionText"]
      }
    }
    "format": {"property": "hits.hits"}
  },

  "marks":[  
    {"type": "text",
      "encode": {
        "enter": {
          "text": {"signal": "data('dataName')[0]['fields']['questionText'][0]"} // note here the changes
        }
      }
    }
  ]
}

To debug this types of Vega issues I can recommend to open the Inspect > Vega debug > Spec panel, and copy there the full spec with values. Then paste it in the Vega playground which provides more advanced tools to debug: Vega Editor

@marco. Thanks a lot. I didn't think I'd ever get it right

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