Update index patterns automatically - programatically?

Currently there is no great way to do this. Eventually we would like to expose an API for this, or refresh fields automatically. You can track this issue on GitHub here: Remove index pattern mapping cache · Issue #6498 · elastic/kibana · GitHub

There is a workaround solution provided here: