How to add Regex to a TextBox Variable and use it inside a Query to visualize data from Elasticsearch

Sorry I am really new to Grafana, I assumed creating a variable in the Text Panel would allow me to use that variable in the Table Panel since they both belong to the same dashboard.

so is this new variable being used to filter stuff in the table panel or fed to elastic search query?

The table panel has the data source as ElasticSearch, and there are 2-3 lucene queries within the table panel (I am assuming here that the query directly queries the elasticsearch logs and just visualizes the results in the table.)

So in short, yes the variable from the text panel needs to be used in a query. To clarify - pasting a picture here to let you know what I am talking about.

1 Like

Click on Options? Is there a regex?

Unfortunately no, the only Options is “Limit” on the number of logs to be displayed.

maybe a different approach to this? What visualization will you be using for this? time series or bar chart? or what

No other visualization - this dashboard is more like a query tool - where in I can see any of the logs and the resources related to it using a search tool (in this case searching a log using its ID). I need to integrate the NewVariable into the query instead of $Serial_ID and my dashboard should be usable enough.

interesting use case. why not just use kibana or some other es search tools? what does grafana provide you other tools cannot?

XD Client Requirements - they already have Grafana Enterprise and want to use it.

1 Like

ok let’s try this approach if you are willing, instead of elastic search datasource you can try using infinity plugin that gives you more flexibility on what you are trying to do with modifying things as you want to.

1 Like

I’ll try the infinity plugin!!
I’ll keep posted here about my progress.

Appreciate everyone’s help, thanks a ton!

check this thread out.

and others like it that deal with elastic search and infinity. You can also leverage Dynamic Text to make your es endpoint calls via fetch. etc

1 Like

And another one

Here it is with opensearch I spun up with sample data flight

Continuing this thread. So @roleyroley did you try the above approach and did it not work for you? if you do not want to use the above recommendation or it did not work for you, from your Serial Number what part of it do you want to extract and concatenate

Installing the plugin is going to take some time by admins(unfortunately I am not authorized to install anything new) -

I am trying to find a workaround until then. I saw this page Variable syntax | Grafana documentation

Which gives a brief about how to use variables with regex - any idea on how I can structure my query using this info?

1 Like

Since you are trying to do conditional formatting of the $SerialID, I am not sure you can accomplish that other than using something else. imo

Also I do not see this approach documented ${SerialID:substring(5.9)} Can you point us to where you got this?

This approach is not documented - This is something I would like to try out or hope to achieve. I’m sorry if it was misleading.

1 Like

not misleading, it was just in case I missed some new feature.

Hi @yosiasz ,

some updates - I configured the Infinity Data source plugin and tried a query on the Jsonata Excercizer to filter out the results - https://try.jsonata.org/I71uy_vY7

The problem I’m facing right now is that this query doesnt visualize the result in my dashbaord.

Query:

The Response seems to return all the objects in the test data:

Do you happen to know where I could be going wrong?

The solution to the above substring problem is:

parse-json
  scope "hits.hits"
  jsonata "*[_id=$string($substring('${BSN_Long}',5,4)&$substring('${BSN_Long}',11,4))][]"
1 Like