How to create visualization on the fly using a script

At the moment, there is no API in the Kibana server for automatically creating index patterns, but it's coming in 5.0: https://github.com/elastic/kibana/pull/5213