2020-10-08 13:47:26 +02:00
|
|
|
var editor = ace.edit("elasticsearch_editor");
|
|
|
|
editor.setValue(`GET _search \n{\n "query": {\n "match_all": {}\n }\n}`);
|
|
|
|
editor.clearSelection();
|
|
|
|
|
|
|
|
var view = ace.edit("elasticsearch_view");
|
|
|
|
view.setTheme("ace/theme/textmate");
|
|
|
|
view.session.setMode("ace/mode/json");
|
|
|
|
view.renderer.setShowGutter(false);
|
|
|
|
view.setReadOnly(true);
|
|
|
|
view.setShowPrintMargin(false);
|
|
|
|
|
2023-03-14 17:28:17 +01:00
|
|
|
$("#button-execute_query").click(function() {
|
2020-10-08 13:47:26 +02:00
|
|
|
view.setValue("");
|
2022-02-07 13:48:25 +01:00
|
|
|
let text;
|
2020-10-08 13:47:26 +02:00
|
|
|
let selectText = editor.getSelectedText();
|
|
|
|
if (selectText === "") {
|
|
|
|
let allText = editor.getValue();
|
|
|
|
if (allText === "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
allText = allText.split("\n").join("");
|
|
|
|
allText = allText.concat("\n");
|
2022-02-07 13:48:25 +01:00
|
|
|
text = allText.match("(GET|PUT|POST)(.*?)({.*?}.*?)?(GET|POST|PUT|\n)");
|
2020-10-08 13:47:26 +02:00
|
|
|
} else {
|
|
|
|
selectText = selectText.split("\n").join("");
|
|
|
|
selectText = selectText.concat("\n");
|
2022-02-07 13:48:25 +01:00
|
|
|
text = selectText.match("(GET|PUT|POST)(.*?)({.*?}.*?)?(\n)");
|
2020-10-08 13:47:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
text === null ||
|
|
|
|
text === undefined ||
|
|
|
|
text[2] === "" ||
|
|
|
|
text[2] === undefined
|
|
|
|
) {
|
|
|
|
view.setValue(`Syntax error`);
|
|
|
|
view.clearSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const head = text[1];
|
|
|
|
let index = text[2].trim();
|
|
|
|
if (index.match("^/") === null) {
|
|
|
|
index = `/${index}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
let json = text[3];
|
|
|
|
if (json !== "" && json !== undefined) {
|
|
|
|
json = json.match("^{.*}")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery.post(
|
|
|
|
$("#pandora_full_url").text() + "ajax.php",
|
|
|
|
{
|
|
|
|
page: "enterprise/include/ajax/log_viewer.ajax",
|
|
|
|
elasticsearch_curl: 1,
|
|
|
|
head: head,
|
|
|
|
index: index,
|
|
|
|
json: json
|
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
view.setValue(data);
|
|
|
|
view.clearSelection();
|
|
|
|
|
|
|
|
forced_title_callback();
|
|
|
|
},
|
|
|
|
"html"
|
|
|
|
);
|
|
|
|
});
|