Skip to content

Commit

Permalink
Add map panel and clean up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
athana committed Aug 28, 2015
1 parent b5770a2 commit e387fbf
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/kibana/components/agg_types/buckets/geo_hash.js
Expand Up @@ -23,7 +23,8 @@ define(function (require) {

return new BucketAggType({
name: 'geohash_grid',
title: 'Geohash',
// title: 'Geohash',
title: 'Location',
params: [
{
name: 'field',
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/index.js
Expand Up @@ -25,7 +25,7 @@ define(function (require) {
Private(require('components/agg_types/buckets/terms')),
Private(require('components/agg_types/buckets/filters')),
// Private(require('components/agg_types/buckets/significant_terms')),
// Private(require('components/agg_types/buckets/geo_hash'))
Private(require('components/agg_types/buckets/geo_hash'))
]
};

Expand Down
56 changes: 51 additions & 5 deletions src/kibana/components/courier/fetch/_call_client.js
@@ -1,6 +1,7 @@
define(function (require) {
return function CourierFetchCallClient(Private, Promise, es, configFile, sessionId, $http) {
var _ = require('lodash');
var latlonGeohash = require('latlon-geohash');

var isRequest = Private(require('components/courier/fetch/_is_request'));
var mergeDuplicateRequests = Private(require('components/courier/fetch/_merge_duplicate_requests'));
Expand Down Expand Up @@ -353,6 +354,7 @@ define(function (require) {
}
}

/************** Now we start to parse reqsFetchParams **************/
// reqsFetchParams is an array of requests, we have to process them all.
var clientPromises = _.map(reqsFetchParams, function (req) {
// console.log('reqsFetchParams req =', req);
Expand All @@ -362,6 +364,8 @@ define(function (require) {
var metricId; // Each aggregate will contain metricId.
var metricIdForBucket; // Used for storing subMetricId in Filters bucket agg.
var aggType; // Determine stats func inside aggs object.
var locationField; // For geospatial search.
var precision; // For geohash encode.

//Facet check
if (strategy.clientMethod === 'msearch') {
Expand Down Expand Up @@ -418,6 +422,7 @@ define(function (require) {
* range
* terms
* filters
* geohash_grid
*
* NOTES: If the request contains both buckets and metrics (for example, to compute stats on facet.range),
* then item will contain another 'aggs' obj with its own metricIds for each of the metrics that
Expand Down Expand Up @@ -477,6 +482,16 @@ define(function (require) {
facetQuery += '&facet.query=' + filterObj.query.query_string.query;
});
}

if (_.has(item, 'geohash_grid')) {
aggregationType.push('geohash_grid');
bucketFacet = 'geohash_grid';
locationField = item.geohash_grid.field;
precision = item.geohash_grid.precision;
// TESTING
// Use facetQuery variable for geo query. BUT we currently have no way to specify bbox and d in UI.
// facetQuery = '&spatial=true&fq=%7B!bbox%7D&pt=35%2C-97&d=10&sfield=' + locationField;
}
/************** end of Buckets **************/
/************** Metrics *******************/
if (_.has(item, 'avg')) {
Expand Down Expand Up @@ -847,6 +862,41 @@ define(function (require) {
}
aggregations[metricId] = { buckets };
}

if (aggregationType.indexOf('geohash_grid') !== -1) {
var buckets = [];
if (aggregationType.indexOf('aggs') === -1) {
// For Count metric
// Example:
// buckets = [
// { "key": "svz", "doc_count": 10000 },
// { "key": "sv8", "doc_count": 3000 }
// ];
buckets = _.compact(_.map(docs, function(doc) {
if (doc._source[locationField]) {
var latlon = doc._source[locationField].split(',');
var lat, lon;

if (latlon.length === 2) {
lat = latlon[0];
lon = latlon[1];
} else {
defer.reject('Geo field is not the correct format.');
}

return {
'key': latlonGeohash.encode(lat, lon, precision)
}
}
}));
// Need to sum doc_count values for the same key in buckets.
buckets = _.map(_.countBy(buckets, 'key'), function(v,k) {
return {'key': k, 'doc_count': v}
});

}
aggregations[metricId] = { buckets };
}
/*************** end of Buckets aggregations ***************/
/************** Metrics aggregations ****************/
if (statsField) {
Expand Down Expand Up @@ -888,9 +938,7 @@ define(function (require) {
}
}
/************** end of Metrics aggregations ****************/

// console.log("aggregations = ", aggregations);

var clientResp = [
{
"_shards": {
Expand All @@ -908,16 +956,14 @@ define(function (require) {
"took": qtime
}
];

// console.log('clientResp =',clientResp);
return clientResp;
} else if (strategy.clientMethod === 'mget') {
// Deserialize _source field into JSON and convert clientResp into array for ES compat
var clientResp = resp.data.response.docs[0];
clientResp._source = angular.fromJson(clientResp._source);
clientResp = [clientResp];

// console.log('mget clientResp =', clientResp);

return clientResp;
}
});
Expand Down
6 changes: 4 additions & 2 deletions src/kibana/plugins/discover/controllers/discover.js
Expand Up @@ -38,9 +38,11 @@ define(function (require) {
.then(function (list) {
var stateRison = $location.search()._a;
var state;
try { state = rison.decode(stateRison); console.log('state json decoded from rison = ',state);} catch (e) {}
try {
state = rison.decode(stateRison);
// console.log('state json decoded from rison = ',state);
} catch (e) {}
state = state || {};

var specified = !!state.index;
var exists = _.contains(list, state.index);
var id = exists ? state.index : config.get('defaultIndex');
Expand Down
3 changes: 1 addition & 2 deletions src/kibana/plugins/vis_types/index.js
Expand Up @@ -6,6 +6,5 @@ define(function (require) {
visTypes.register(require('plugins/vis_types/vislib/line'));
visTypes.register(require('plugins/vis_types/vislib/pie'));
visTypes.register(require('plugins/vis_types/vislib/area'));
// Disable tile_map, it's not working with Solr geospatial search yet.
// visTypes.register(require('plugins/vis_types/vislib/tile_map'));
visTypes.register(require('plugins/vis_types/vislib/tile_map'));
});
4 changes: 3 additions & 1 deletion src/kibana/plugins/vis_types/vislib/tile_map.js
Expand Up @@ -25,7 +25,9 @@ define(function (require) {
title: 'Value',
min: 1,
max: 1,
aggFilter: ['count', 'avg', 'sum', 'min', 'max', 'cardinality'],
// aggFilter: ['count', 'avg', 'sum', 'min', 'max', 'cardinality'],
// Disable 'avg', 'sum', 'min', 'max', 'cardinality' aggFilter. We don't support it yet.
aggFilter: ['count'],
defaults: [
{ schema: 'metric', type: 'count' }
]
Expand Down
1 change: 1 addition & 0 deletions src/kibana/require.config.js
Expand Up @@ -7,6 +7,7 @@ require.config({
errors: 'components/errors',
modules: 'utils/modules',
lodash: 'utils/_mixins',
'latlon-geohash': 'utils/latlon-geohash',

// bower_components
'angular-bindonce': 'bower_components/angular-bindonce/bindonce',
Expand Down

0 comments on commit e387fbf

Please sign in to comment.