Challenges embedding Kibana visualizations in elasticsearch _site plugin

I'm developing an elasticsearch _site plugin that lets me create new indexes and upload content.

I can embed Kibana visualizations in an iFrame to good effect but came across 2 issues:

  1. Chrome is happy embedding Kibana iFrames that render data but Safari iFrames have dashboards with this error: "Blocked a frame with origin "http://localhost:5601" from accessing a frame with origin "http://localhost:9200". Protocols, domains, and ports must match". So that's a 9200-served page loading a 5601-served iFrame that then fails to call a 9200 REST endpoint.
  2. If I change the index mapping/content and add a new field "Foo" I need a way to force Kibana to refresh field definitions or I can't embed a visualization for Foo's values. Is there an API I can call to trigger this refresh?


Replying to self: I figured out the CORS setting to solve 1) and by observing the kibana browser/server traffic I can see how to send a revised set of field definitions from the browser to solve 2). Feels a bit hacky but it works.

@Mark_Harwood If you were running code within Kibana you could simply call the indexPattern.refreshFields() method and the field list would be rebuild. Not sure I can imagine a better way to expose this, short of moving this logic to the server and exposing a REST API (a solution we plan to implement someday).

If you were running code within Kibana

No, it's a _site plugin doing it's own thing and just embedding the odd kibana pie-chart here or there. Index deletion, creation and content uploading are part of the tool's function for a variety of doc types and so I need to keep kibana server updated with these changes.
A REST endpoint would make a lot of sense in this context where the usual "kibana experience" is not required and I just need to embed some piecharts etc.