Do we need a datasource per index?

A elasticsearch datasource has only one index. So for each index I have to create a datasource, right? Or am I missing something here? :smiley:

I would prefer to define a elasticsearch connection once, and add multiple indices, to avoid adding the same connection information over and over again.

1 Like

A few options:
The best would be to create an alias in Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html
Create an alias (like “grafana” or something) and alias the indexes you want.

Another option:
Just use an asterisk (*) for the index name - that will select all the indexes.

1 Like

Thanks for the help. And when I use * for index how do I select the correct index in the query? I just noticed, that it’s not just the index we specify in the datasource, but the time field name, too. So when the time field name varies between indices, using * does not really makes sense, right?

Correct. The timestamp must be the same for any indexes referenced by the same Data Source. Best solution is to normalize your indexes to use the same field names. Otherwise, you will need different Data Sources where the timestamp field name is different.

For example, we have 2 Data Sources for the SAME index, depending on which timestamp field we want to search against.

This is the nature of a TSDB (Time Series Data Base).

And how do I specify the index in the query builder?

You can’t. The index is a part of the Data Source configuration.

However - I’m not sure what your overall goal is here, but a possible work-around:
If your Data Source is configured for all indexes (with *), AND if you happen to store the indexname as a field in the JSON documents within the index (ie: doc= {timestamp:2018-01-01T01:01:01.000Z,name:bob,index:indexname}), then your query could specify the field index:indexname and get the results for only that index, or some other valid query.

1 Like