How to use variable in a panel with time series format(elasticsearch data source)

I used ElasticSearch as a data source in Grafana 9 and set the metric to “Raw Data” mode, then selected some fields using “Organize Fields Transform” and hid the rest. I also placed the visualization on the “time series”. Now I want to define a variable for the fields that are placed in the legend and the user can use this variable and select any field he likes so that only it is displayed in the graph.
But I don’t know how to do this