How can I link the change of dashboard to vega when I use url.body.query?

What I want to do is under below here.

  1. You have a non-vega graph(tag cloud) on dashbord like this.

  2. When a particular user is selected by clicking tag cloud, userName.keyword would be that user.

  3. Now, vega graph will send url.body.query.match_phrase to elasticsearch which includes the user name selected in No.2.
    But, it says error, url.%context% and url.%timefield% must not be used when url.body.query is set.

How should I fix?

my vega code is below.

{
    "url": {
      "%context%": true,
      "%timefiled%":"@timestamp",
      "index":"cwat_index_audit_it1dev_*",
      "body": {
        "size": 0,
        "query": {
            "match_phrase": {
                "userName.keyword": "userName.keyword"
            }
        },
        "aggs": {
            "histogram_daily": {
                "date_histogram": {
                    "field": "eventCreateCwatGmt",
                    "calendar_interval": "1d"
                },
                "aggs": {
                    "max_daily_total": {
                        "max": {
                            "field": "eventCreateCwatGmt"
                        }
                    },
                    "min_daily_total": {
                        "min": {
                            "field": "eventCreateCwatGmt"
                        }

Unfortunately it's currently not possible to use "%context%": true, (which pulls in the filters from the dashboard) and a query defined within the vega spec itself together - it's either one or the other.

In your specific case though that shouldn't be a problem, because it seems like you just want to do a simple match phrase for a given field in vega. Instead of doing this in the vega query itself, add a filter in the vega visualization editor with the same match. As long as you have "%context%": true, in your spec, it will result in the same query being sent to Elasticsearch. As unpinned filters are saved along with the visualization this filter is also active on the Dashboard, but it will get mixed correctly with the filter created by tagcloud.

So in summary:

  • Use %context% as you already doing
  • Remove query in your vega spec
  • Add a filter in the visualization filtering by the same thing as your query clause (will get saved along with the vega spec)

Hi, @flash1293.
Thank you for your reply.

I fixed my code according to your suggestions.
Now I have another error Cannot read property 'user' of undefined.
I think I set timefield not correctly, because this error fades when I comment out it.

      "url": {
        "%context%":true,
        "%timefilter%":"eventCreateCwatGmt",
        "index": "cwat_index_audit_it1dev_*",
        "body": 
        {
        "size":0,
        "aggs": {
          "user": {
            "filter": {
              "term": {
                "userName.keyword": "userName.keyword"
              }
            },
            "aggs": {
                  "histogram_daily": {
                      "date_histogram": {
                          "field": "eventCreateCwatGmt",
                          "calendar_interval": "1d",
                          "time_zone": "Asia/Tokyo",
                          "order": {"_key": "desc"}
                      },
                      "aggs": {
                          "max_daily_total": {
                              "max": {
                                  "field": "eventCreateCwatGmt"
                              }
                          },
                          "min_daily_total": {
                              "min": {
                                  "field": "eventCreateCwatGmt"
                              }
                          }

Hi, @flash1293.
What I posted previous, I had a spell miss of timefield, which I spelled it timefilter.
It's now no errors with my code, sorry and thanks for your solution.