Skip to content

Index Pattern functions

ytzlax edited this page Nov 2, 2017 · 2 revisions

isIndexPatternExist

Check if index-pattern exist

Request:

this.iframeElement = document.getElementById('iframe');
this.iframeWindow = (<HTMLIFrameElement>this.iframeElement).contentWindow;

let message={actionType: "isIndexPatternExist", indexPattern: "logstash-*"}

this.iframeWindow.postMessage(message, '*');

Response:

Use the next code to listen the response from the plugin

private iFrameAddListener() {
    let that = this;
    let eventMethod = "addEventListener";
    let eventer = window[eventMethod];
    let messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

    // Listen to message from parent (or any other) window
    eventer(messageEvent, this.pluginNotification);
}
private pluginNotification = (e) => {
    let that = this;
    let func = e.data.split('##')[0];
    let res = JSON.parse(e.data.split('##')[1]);
    console.log("func:", func, "res:", res);    
};


 this.iFrameAddListener();


createIndexPattern

Create new index-pattern

Request:

this.iframeElement = document.getElementById('iframe');
this.iframeWindow = (<HTMLIFrameElement>this.iframeElement).contentWindow;

let message={actionType: "createIndexPattern", index: "logstash-*", timeField: "@timestamp"}

this.iframeWindow.postMessage(message, '*');

Response:

Use the next code to listen the response from the plugin

private iFrameAddListener() {
    let that = this;
    let eventMethod = "addEventListener";
    let eventer = window[eventMethod];
    let messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

    // Listen to message from parent (or any other) window
    eventer(messageEvent, this.pluginNotification);
}
private pluginNotification = (e) => {
    let that = this;
    let func = e.data.split('##')[0];
    let res = JSON.parse(e.data.split('##')[1]);
    console.log("func:", func, "res:", res);    
};


 this.iFrameAddListener();


If your Index not contains time-based events don't send timeField property

setDefaultIndexPattern

Set default index-pattern

Request:

this.iframeElement = document.getElementById('iframe');
this.iframeWindow = (<HTMLIFrameElement>this.iframeElement).contentWindow;

let message={actionType: "setDefaultIndexPattern", indexPattern: "logstash-*"}

this.iframeWindow.postMessage(message, '*');

Response:

Use the next code to listen the response from the plugin

private iFrameAddListener() {
    let that = this;
    let eventMethod = "addEventListener";
    let eventer = window[eventMethod];
    let messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

    // Listen to message from parent (or any other) window
    eventer(messageEvent, this.pluginNotification);
}
private pluginNotification = (e) => {
    let that = this;
    let func = e.data.split('##')[0];
    let res = JSON.parse(e.data.split('##')[1]);
    console.log("func:", func, "res:", res);    
};


 this.iFrameAddListener();


Clone this wiki locally