@@ -23,7 +23,7 @@ module.exports = function (koop) {
23
23
featureCollection . metadata . timeInfo . timeExtent = [ this . startFieldStats . min , this . endFieldStats . max ] ;
24
24
} ;
25
25
26
- this . getTileOffset = function ( z , minimumOffset = 4.864 ) {
26
+ this . getTileOffset = function ( z , minimumOffset = 4.864 ) {
27
27
// Emulate the offset that would come from a feature service request with a minimum of 4.864
28
28
// Level 22 has 0.019 meters per pixel and this increases by a factor of 2 as the tile level goes down
29
29
return Math . max ( minimumOffset , 0.019 * Math . pow ( 2 , 22 - parseInt ( z ) ) ) ;
@@ -151,7 +151,7 @@ module.exports = function (koop) {
151
151
} ) ;
152
152
this . esClients [ esId ] . count ( countQuery ) . then ( function ( resp ) {
153
153
logger . debug ( "count resp:" , resp ) ;
154
- featureCollection . count = resp . count ;
154
+ featureCollection . count = resp . body . count ;
155
155
callback ( null , featureCollection ) ;
156
156
} , function ( err ) {
157
157
logger . error ( err . message ) ;
@@ -195,6 +195,7 @@ module.exports = function (koop) {
195
195
// let startESQueryMillis = Date.now().valueOf();
196
196
// console.log(JSON.stringify(esQuery, null, 2));
197
197
let searchResponse = await this . esClients [ esId ] . search ( esQuery ) ;
198
+ searchResponse = searchResponse . body ;
198
199
// logger.debug(`Got ES Response In: ${(Date.now().valueOf() - startESQueryMillis)/1000} seconds`);
199
200
// let startParseMillis = Date.now().valueOf();
200
201
let totalHits = isNaN ( searchResponse . hits . total ) ? searchResponse . hits . total . value : searchResponse . hits . total ;
@@ -391,37 +392,34 @@ module.exports = function (koop) {
391
392
}
392
393
393
394
394
- function queryHashAggregations ( indexConfig , mapping , esQuery , geohashUtil , esClient ) {
395
- return new Promise ( ( resolve , reject ) => {
396
- // just aggs, no need to get documents back
397
- esQuery . body . size = 1 ;
398
-
399
- esQuery . body . aggregations = {
400
- agg_grid : {
401
- geohash_grid : {
402
- field : indexConfig . geometryField ,
403
- precision : geohashUtil . precision
404
- }
395
+ async function queryHashAggregations ( indexConfig , mapping , esQuery , geohashUtil , esClient ) {
396
+ // just aggs, no need to get documents back
397
+ esQuery . body . size = 1 ;
398
+ esQuery . body . aggregations = {
399
+ agg_grid : {
400
+ geohash_grid : {
401
+ field : indexConfig . geometryField ,
402
+ precision : geohashUtil . precision
405
403
}
406
- } ;
407
-
408
- esClient . search ( esQuery ) . then ( response => {
409
- let geohashFeatures = [ ] ;
410
- let hitConverter = new HitConverter ( ) ;
411
- for ( let i = 0 ; i < response . aggregations . agg_grid . buckets . length ; i ++ ) {
412
- let feature = hitConverter . featureFromGeoHashBucket ( response . aggregations . agg_grid . buckets [ i ] ,
413
- response . hits . hits [ 0 ] , indexConfig , mapping , esQuery . body . query . bool ) ;
414
- if ( feature ) {
415
- geohashFeatures . push ( feature ) ;
416
- }
404
+ }
405
+ } ;
406
+ try {
407
+ let result = await esClient . search ( esQuery ) ;
408
+ let response = result . body ;
409
+ let geohashFeatures = [ ] ;
410
+ let hitConverter = new HitConverter ( ) ;
411
+ for ( let i = 0 ; i < response . aggregations . agg_grid . buckets . length ; i ++ ) {
412
+ let feature = hitConverter . featureFromGeoHashBucket ( response . aggregations . agg_grid . buckets [ i ] ,
413
+ response . hits . hits [ 0 ] , indexConfig , mapping , esQuery . body . query . bool ) ;
414
+ if ( feature ) {
415
+ geohashFeatures . push ( feature ) ;
417
416
}
418
- resolve ( geohashFeatures ) ;
419
- } ) . catch ( error => {
420
- logger . error ( error ) ;
421
- reject ( error ) ;
422
- } )
423
-
424
- } ) ;
417
+ }
418
+ return Promise . resolve ( geohashFeatures ) ;
419
+ } catch ( e ) {
420
+ logger . error ( e ) ;
421
+ return Promise . reject ( e ) ;
422
+ }
425
423
}
426
424
427
425
function tile2long ( x , z ) {
@@ -481,7 +479,7 @@ module.exports = function (koop) {
481
479
try {
482
480
logger . debug ( JSON . stringify ( queryBody , null , 2 ) ) ;
483
481
let response = await esClient . search ( queryBody ) ;
484
- let shapeHits = response . hits . hits ;
482
+ let shapeHits = response . body . hits . hits ;
485
483
return Promise . resolve ( shapeHits ) ;
486
484
} catch ( e ) {
487
485
return Promise . reject ( e ) ;
@@ -896,7 +894,7 @@ module.exports = function (koop) {
896
894
} ,
897
895
properties : customAggregation . defaultReturnFields ( mapping , indexConfig , query . customAggregations )
898
896
} ;
899
- if ( defaultFeature . geometry . type === "Point" ) {
897
+ if ( defaultFeature . geometry . type === "Point" ) {
900
898
defaultFeature . geometry . coordinates = defaultFeature . geometry . coordinates [ 0 ] [ 0 ] ;
901
899
}
902
900
aggCollection . features = [ defaultFeature ] ;
0 commit comments