Grafana variables does not filter

  • What Grafana version and what operating system are you using?
    10.4.2
  • What are you trying to achieve?
    I’m trying to use variables to filter my data
  • How are you trying to achieve it?
    I’m using query variables with ElasticSearch data. My query is:
{"find": "terms", "field": "area", "size": 1000}
  • What happened?
    When i run the query it shows the areas correctly. But when I save, it tells me that this variable is not being used in my dashboard. I have a full built dashboard that uses the variable family in tables, graphs, timelines and gauges so I don’t understand why it says that.
  • What did you expect to happen?
    I expected to select one of the production areas and all the dashboard gets filtered by that area, but it doesn’t do anything.
  • Can you copy/paste the configuration(s) that you are having problems with?
    This is the query of the variable:
{"find": "terms", "field": "area", "size": 1000}

This is the JSON query of one of my panels:

{
  "datasource": {
    "type": "elasticsearch",
    "uid": "edivx6uxe1tz4a"
  },
  "description": "Shows the total alarms in Body 1 in the selected time range",
  "fieldConfig": {
    "defaults": {
      "mappings": [],
      "thresholds": {
        "mode": "percentage",
        "steps": [
          {
            "color": "blue",
            "value": null
          }
        ]
      }
    },
    "overrides": []
  },
  "gridPos": {
    "h": 4,
    "w": 2,
    "x": 0,
    "y": 1
  },
  "id": 10,
  "options": {
    "reduceOptions": {
      "values": true,
      "calcs": [],
      "fields": ""
    },
    "orientation": "auto",
    "showThresholdLabels": false,
    "showThresholdMarkers": true,
    "sizing": "auto",
    "minVizWidth": 75,
    "minVizHeight": 75
  },
  "pluginVersion": "10.4.2",
  "targets": [
    {
      "alias": "",
      "bucketAggs": [
        {
          "field": "area",
          "id": "2",
          "settings": {
            "min_doc_count": "1",
            "order": "desc",
            "orderBy": "_term",
            "size": "10"
          },
          "type": "terms"
        }
      ],
      "datasource": {
        "type": "elasticsearch",
        "uid": "edivx6uxe1tz4a"
      },
      "metrics": [
        {
          "id": "1",
          "type": "count"
        }
      ],
      "query": "area:\"Body 1\"",
      "refId": "A",
      "timeField": "date"
    }
  ],
  "title": "Body 1",
  "type": "gauge"
}
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    It says "This variable is not referenced by any variable or dashboard.
  • Did you follow any online instructions? If so, what is the URL?
    Yes, i followed the official YT channel guide and some documentation.

what did you call your query variable, and where are you referencing it in your panel query?

Hello sowdenraymond. I’m not sure if I’m understanding your question, but here is some screenshots that may answer you.

For example, here I have a gauge panel where I use the “area” field, filtered by one of my areas:


This query makes a count of the elements inside this area, then the variable area is called in this query. I have this panel like 5 or 6 times, one per each area.

Also, I have some pannels with tables and other counts that I would like to see filtered. For example, I have a pannel which counts the ammount of “robots” I have in total, so I would like to filter this ammount according to the area selected at the variable selection.

Sorry if I didn’t answered your question, tell me if you need more info and ty for help!

Update: I’ve seen that this error may happen when the query isn’t working correctly. I’ve checked this and the query returns the areas correctly, so I’m still wondering whats happening:
image

You have to use variable in your Lucene query, e. g. area: "${variable:raw}"

Now the panel reacts to the variable, but not in a proper way. When I don’t select any area, it shows “no data”, as you can see in this pic:
image
image

But if I select more than 1 data, it does not show any data again, as you can see in this screenshot:
image

All dashboards I’ve seen can select multiple values on its variables and the dashboard shows all of them. I really don’t know why I’m having this problems, this has to be much simplier than it seems.

Instead of copy&paste solution I’ll give you advice how you can solve it on your own.
Use query inspector, so you will see how is Lucene query generated.

  • Make sure that All value will generate valid Lucene syntax, which will select all documents - you can customize that all value and you can use wildchar (lucene *) there
  • make sure that multivalue will generate correct Lucene syntax, so learn how you can write it in Lucene and then use correct variable format

Hi @fgineral,

definitely inspect the queries like @jangaraj said. Once the syntax is proper:

It sounds like you want to see either multiple gauges when you select multiple areas, or you want to see multiple values on the same gauge.

I happen to have a multi-gauge visu ready:

To get grafana to do this, make sure the table is in the following format:

This was an old, standard grafana visualization. I don’t think it can show multiple values on the same gauge.

Here’s another plugin for you (this one really saved me, I use it exclusively now). It looks way better than grafana visualizations and is way more customizable (through code). They also actually documented the format which the visualizations expect:

Here you can see some of the possibilities (including several values on one gauge):

https://echarts.volkovlabs.io/d/pL5iH7FVk/home?orgId=1&refresh=5s

Hello rob.loh

I’ve been searching for info of this plugin. It is very good but I’m having problems at the time of displaying my data. I’ve inspected the query as you and jangaraj told me to do and the data is correct, but i want to display it with a bar graph and I can’t do it. Do you know how can I do it?

Also, thanks @jangaraj for help. The info you provided to me helped to understand some concepts of the Lucene queries. To add a solution to this post, this is how I made it:

To get a gauge pannel that reacts to the filters, showing all the values or just the filtered ones, I used area:($area) (area is the field I want to filter and the variable name) like this:

This allows me to show all the values I want. F.E. let’s say I want to show all the types of fruits in my shop and the number of fruits I’ve sold (the numbers may not be realistic, but you get the point). The user (in this case, you) wants to filter the gauge pannel and all the other pannels by one, 2 or the fruit type ammount you want, so with the Lucene query I’ve posted, it will look like this:

And also like this:

You can also apply this to every type of visualization, like histrogram or bars, to get it filtered the same way. Thanks everyone on this post for help, glad to see this community is full of kind and helpful people! :smiley:

1 Like