Using Regex/Substring of a Template Variable and adding it to a Query Elasticsearch db

Grafana Version - Grafana v10.0.2 (b2bbe10fbc)
Operating System - Windows 11

  • What are you trying to achieve - I want to use Regex / Substring operation on a Template Variable called $SerialID

  • How are you trying to achieve it - 1. I created a TextBox Template variable with the name SerialID which takes a 16 character user input. 2. The database source is Elasticsearch logs. 3. I need to extract substring from index 5-12 of the 16 character $SerialID value, and then use it to query a field called “id”.

  • What did you expect to happen?
    This is what I have -

    And this is something I am trying to achieve - I want either substring or regex here

  • What happened?
    If I have a look at the query inspector - It does not recognize the variable when substring is used -

    But it recognizes its value normally without the substring operation -

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were. - No errors by Grafana - just the fact that I am not able to do a basic regex on a template variable and would love to know how to write a query properly for ElasticSearch DB

  • Did you follow any online instructions? If so, what is the URL?
    I also saw something like this -Elasticsearch template variables | Grafana documentation
    But I haven’t quite understood how it works or how to form my query based on the explanation above.

Is this the same as this thread?

so from OM7MD0000DN0857 which part do you want?

Check this out

Oh yes - its the same thread -
The regex would be something like this -
/^.{5}(.{4})(.{2})(.{4})*/ out of which I want Group 1 and Group 3 and concatenate them.

Do you happen to know what the query would look like?
PS: Here is the link to what I am trying to achieve. regex101: build, test, and debug regex

if same thread can we close this one? it helps to keep things neat and tidy

1 Like