使用ES和Angular的Kibana自定义可视化不起作用
Kibana Customized Visualization with ES and Angular Doesn't Work
首先,我尝试在Kibana中使用这里的学习制作自定义可视化。
然后,我希望我的自定义可视化像时钟一样动态地显示我的elasticsearch索引有多少次点击。
所以,我改变了一些代码在上面的教程,但他们不工作。
Chrome Devtools告诉说Error: The elasticsearch npm module is not designed for use in the browser. Please use elasticsearch-browser
我知道我最好使用elasticsearch-browser。
然而,我想知道什么是错的,为什么。
public/myclock.js
define(function(require) {
require('plugins/<my-plugin>/mycss.css');
var module = require('ui/modules').get('<my-plugin>');
module.controller('MyController', function($scope, $timeout) {
var setTime = function() {
$scope.time = Date.now();
$timeout(setTime, 1000);
};
setTime();
var es = function(){
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
client.search({
index: 'myindex',
}).then(function (resp) {
$scope.tot = resp.hits.total;
}, function (err) {
console.trace(err.message);
});
};
es();
});
function MyProvider(Private) {
...
}
require('ui/registry/vis_types').register(MyProvider);
return MyProvider;
});
public/clock.html
<div class="clockVis" ng-controller="MyController">
{{ time | date:vis.params.format }}
{{tot}}
</div>
感谢您的阅读。
看起来angularjs中的控制器将elasticsearch javascript客户端视为从浏览器访问。
为了避免这种情况,一种选择是在index.js中构建服务器API,然后通过执行http请求使kibana访问elasticsearch。 <标题> 例子index.js
// Server API (init func) will call search api of javascript
export default function (kibana) {
return new kibana.Plugin({
require: ['elasticsearch'],
uiExports: {
visTypes: ['plugins/sample/plugin']
},
init( server, options ) {
// API for executing search query to elasticsearch
server.route({
path: '/api/es/search/{index}/{body}',
method: 'GET',
handler(req, reply) {
// Below is the handler which talks to elasticsearch
server.plugins.elasticsearch.callWithRequest(req, 'search', {
index: req.params.index,
body: req.params.body
}).then(function (error, response) {
reply(response);
});
}
});
}
});
}
controller.js
在控制器中,您需要调用上面示例中的GET请求。
$http.get( url ).then(function(response) {
$scope.data = response.data;
}, function (response){
$scope.err = "request failed";
});
在我的例子中,我使用url而不是绝对路径或相对路径,因为仪表板应用程序的路径是深的。
http://[serverip]:5601/iza/app/kibana#/dashboard/[Dashboard Name]
*
Your here
http://[serverip]:5601/iza/[api path]
*
api path will start here
我以这篇参考文献为例
标题>相关文章:
- 如何在谷歌可视化中组合数字和模式格式化程序
- 加载泰坦尼克号可视化数据时出现问题
- 如何使用图表包装函数有条件地格式化谷歌可视化表单元格
- AngularJS&Google可视化-使用状态更改处理程序(Google API)在HTML页面上查看$sco
- Javascript图形可视化工具包,具有高性能(500-1000个节点)
- Google可视化addListener调用函数引用错误
- 谷歌可视化树图-如何创建自定义文本
- 使用 QGIS 和 D3 可视化自定义地图.js会受到投影的损害
- 基于 d3.js 的自定义可视化出现问题
- 可视化:未捕获类型错误:无法读取未定义的属性“arrayToDataTable”
- 谷歌可视化:堆叠列.HTML自定义工具提示的问题
- 谷歌可视化循环-返回谷歌.可视化未定义
- 未捕获的TypeError: Cannot read property 'row'未定义的-谷歌可视化a
- 使用join提高自定义CartoDB层可视化的性能
- 如何为谷歌数据表编写自定义格式化程序(用于可视化api)
- 自定义Soundcloud可视化工具
- 使用ES和Angular的Kibana自定义可视化不起作用
- SoundCloud的可视化音频's自定义播放器
- 自定义谷歌可视化表中的排序列
- 使用自定义可视化组件(CVC)的Highchart Jasper导出问题