You can do this using an macro with a subsearch.
If you create a search field in your subsearch it will expand out into a search, and you can use replace to format your string correctly, like so:
index=_internal metrics [ stats count | eval test="per_host_thruput,per_index_thruput" | eval search = "group=" + replace(test,",", " OR group=") ]
Which could be converted into a macro which specified the variable fields, and the field name.
You can also do this be creating a python script that returns a field called search, and then call it inside a subsearch.
... View more