How to query multiple elasticsearch indices at once

I have a query and I need to execute that query at once, on two indices, namely: index_name1 and index_name2. I have to fetch unique count of a field from these two indices, so executing query once for each index won’t work. Is there a way I can configure that query to view those two indices as a single index?

Try to create Elasticsearch datasource with index: index_name*
Then build the panel using that datasource.

Fadjar Tandabawana

Well there are also other indices with names index_name3 and so on which I don’t want to include while querying

You could setup an index alias in elasticsearch that links all the indices you need.
Then configure the grafana datasource with the alias as the index.