From 8ff885759fcc2a5c4f9c487ee37d03da8f3cfc0e Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Sat, 16 Jun 2012 16:31:45 +0100 Subject: [PATCH] [#111,backend/elasticsearch][s]: geo distance filter now working - hurrah!. --- src/backend/elasticsearch.js | 6 +++--- test/backend/elasticsearch.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/backend/elasticsearch.js b/src/backend/elasticsearch.js index ea18ff39..4667f4cc 100644 --- a/src/backend/elasticsearch.js +++ b/src/backend/elasticsearch.js @@ -121,9 +121,9 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {}; out[filter.type] = {} if (filter.type === 'term') { out.term[filter.field] = filter.term; - } else if (filter.type === 'geo_point') { - out.geo_point[filter.field] = filter.point; - out.geo_point[filter.distance] = filter.distance; + } else if (filter.type === 'geo_distance') { + out.geo_distance[filter.field] = filter.point; + out.geo_distance.distance = filter.distance; } return out; }, diff --git a/test/backend/elasticsearch.test.js b/test/backend/elasticsearch.test.js index 7dfeb8ff..9170b5cb 100644 --- a/test/backend/elasticsearch.test.js +++ b/test/backend/elasticsearch.test.js @@ -49,6 +49,31 @@ test("queryNormalize", function() { } }; deepEqual(out, exp); + + var in_ = new recline.Model.Query(); + in_.addFilter({ + type: 'geo_distance', + field: 'xyz' + }); + var out = backend._normalizeQuery(in_); + var exp = { + constant_score: { + query: { + match_all: {} + }, + filter: { + and: [ + { + geo_distance: { + distance: '10km', + 'xyz': { lon: 0, lat: 0 } + } + } + ] + } + } + }; + deepEqual(out, exp); }); var mapping_data = {