|
@@ -4,15 +4,82 @@
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('kibana.services', [])
|
|
angular.module('kibana.services', [])
|
|
|
-.service('fields', function() {
|
|
|
|
|
-
|
|
|
|
|
|
|
+.service('fields', function(dashboard, $rootScope, $http) {
|
|
|
// Save a reference to this
|
|
// Save a reference to this
|
|
|
var self = this;
|
|
var self = this;
|
|
|
|
|
|
|
|
this.list = ['_type'];
|
|
this.list = ['_type'];
|
|
|
|
|
+ this.mapping = {};
|
|
|
|
|
|
|
|
this.add_fields = function(f) {
|
|
this.add_fields = function(f) {
|
|
|
- self.list = _.union(f,self.list);
|
|
|
|
|
|
|
+ //self.list = _.union(f,self.list);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ $rootScope.$watch(function(){return dashboard.indices;},function(n) {
|
|
|
|
|
+ if(!_.isUndefined(n) && n.length) {
|
|
|
|
|
+ // Only get the mapping for indices we don't know it for
|
|
|
|
|
+ var indices = _.difference(n,_.keys(self.mapping));
|
|
|
|
|
+ // Only get the mapping if there are indices
|
|
|
|
|
+ if(indices.length > 0) {
|
|
|
|
|
+ self.map(indices).then(function(result) {
|
|
|
|
|
+ self.mapping = _.extend(self.mapping,result);
|
|
|
|
|
+ self.list = mapFields(self.mapping);
|
|
|
|
|
+ });
|
|
|
|
|
+ // Otherwise just use the cached mapping
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.list = mapFields(_.pick(self.mapping,n));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ var mapFields = function (m) {
|
|
|
|
|
+ var fields = [];
|
|
|
|
|
+ _.each(m, function(types,index) {
|
|
|
|
|
+ _.each(types, function(v,k) {
|
|
|
|
|
+ fields = _.union(fields,_.keys(v));
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ return fields;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ this.map = function(indices) {
|
|
|
|
|
+ var request = $http({
|
|
|
|
|
+ url: config.elasticsearch + "/" + indices.join(',') + "/_mapping",
|
|
|
|
|
+ method: "GET"
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return request.then(function(p) {
|
|
|
|
|
+ var mapping = {};
|
|
|
|
|
+ _.each(p.data, function(v,k) {
|
|
|
|
|
+ mapping[k] = {};
|
|
|
|
|
+ _.each(v, function (v,f) {
|
|
|
|
|
+ mapping[k][f] = flatten(v);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ return mapping;
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var flatten = function(obj,prefix) {
|
|
|
|
|
+ var propName = (prefix) ? prefix : '',
|
|
|
|
|
+ dot = (prefix) ? '.':'',
|
|
|
|
|
+ ret = {};
|
|
|
|
|
+ for(var attr in obj){
|
|
|
|
|
+ // For now only support multi field on the top level
|
|
|
|
|
+ // and if if there is a default field set.
|
|
|
|
|
+ if(obj[attr]['type'] === 'multi_field') {
|
|
|
|
|
+ ret[attr] = obj[attr]['fields'][attr] || obj[attr];
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (attr === 'properties') {
|
|
|
|
|
+ _.extend(ret,flatten(obj[attr], propName));
|
|
|
|
|
+ } else if(typeof obj[attr] === 'object'){
|
|
|
|
|
+ _.extend(ret,flatten(obj[attr], propName + dot + attr));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ret[propName] = obj;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ret;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
})
|
|
})
|
|
@@ -383,6 +450,7 @@ angular.module('kibana.services', [])
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// This special function looks for all time filters, and returns a time range according to the mode
|
|
// This special function looks for all time filters, and returns a time range according to the mode
|
|
|
|
|
+ // No idea when max would actually be used
|
|
|
this.timeRange = function(mode) {
|
|
this.timeRange = function(mode) {
|
|
|
var _t = _.where(self.list,{type:'time',active:true});
|
|
var _t = _.where(self.list,{type:'time',active:true});
|
|
|
if(_t.length === 0) {
|
|
if(_t.length === 0) {
|