Append String to the End of a Variable that can be multivalue

Hi All,

I am trying to set up a dashboard which has a variable that can be Multi-value. However I have run into an issue, where the variable needs to have .* appended to the end of it. This is because the query that it is being used for is an Elasticsearch lucene query, and the variable is only a substring of the matches I would like. ex: Variable = 0001, but values it should match are 0001[0-9]{2}, this means I need to append the variable to be either .* or [0-9]{2}. While adding these values to the end of a single variable works fine, this method does not work with Multi-value variables, as the regex string is applied outside of the variable array that is passed in the query. ex: Variable = 0001 + 0002; Appended String = .*, query =(\"0001\" OR \"0002\").*. This causes the query to fail, as this is not approved regex for Elastic lucene. I would need something like query = (\"0001.*\" OR \"0002.*\").

Does anyone know how this could be achieved, either by adding the regex at time of variable creation, or within the query?

1 Like

Anyone can help us on this question?

Unfortunately, I don’t believe I was ever able to achieve exactly this. What I ended up doing was adding an additional field to my index which contained only the first 4 characters for the string. While this is not optimal, and does cause so duplication of data, it was really the only way I could achieve this outcome, as Grafana lacks the ability to prepend and append text to variables.

You may be able to somehow achieve these results by using a text field with a custom analyzer, however I have never tested it out and would not be able to provide any assistance with it.

What about accessing your var as ${var_name:regex}?
So the whole query would be /${var_name:regex}.*/ which would expand to /(0001|0002).*/