Allow index 0 for dynamic queries

Previous code would just take the metric name instead of the first node. Explicitly checking whether index is defined make sure we really use the intended index when given.