How to modify the selected values from the filter in Grafana?

I am using a template variable for the filter to list down some of the string value from elasticsearch like

string1_dev_01
string1_prod_01
string2_dev_02
string2_prod_02

template variable name = version_name
column name in elastic search = version

Lucene Query : version:$version_name

when the user selects “string1_dev_01” it fetches data belongs to “string1_dev_01” from elasticsearch and display in a table panel.

But I want, when selecting either string1_dev_01 or string1_prod_01 it should fetch all data belongs to both the dev and prod.

After selected the version the string value should be modified and assigned to template variable

version_name:"string1_*_01"

Final value assign to version like

version:"string1_*_01"

Questions.

  1. How can I modified the selected value like string1_*_01
  2. Lucene query should fetch value
    • starts with - string1_
    • ends with - _01

How can I achieve this in grafana? Thanks in advance.