diff --git a/lib/database/elasticsearch_adapter.js b/lib/database/elasticsearch_adapter.js index 2e910ca..4e6cc83 100644 --- a/lib/database/elasticsearch_adapter.js +++ b/lib/database/elasticsearch_adapter.js @@ -245,8 +245,19 @@ ElasticSearchDB.prototype.searchObjects = function(options, callback) { } }); } else { - if (options.sort) - reqBody.sort = options.sort; + if (sort) { + reqBody.sort = {}; + + if (!sort.type) { + reqBody.sort = [sort]; + } else if (sort.type == 'default') { + reqBody.sort[sort.field] = sort.order; + } else if (sort.type == 'geo') { + reqBody.sort._geo_distance = {}; + reqBody.sort._geo_distance[sort.field] = {lat: sort.poi.lat || 0.0, lon: sort.poi.long || 0.0}; + reqBody.sort._geo_distance.order = sort.order; + } + } this.connection.search({ index: this.config.index,