From aa721b8749e2cb7b93019e35eae6e6cc14363273 Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Wed, 11 Feb 2015 17:01:21 -0500 Subject: [PATCH] moving groovy scripts to a file on disk @ elasticsearch/config/scripts to avoid dynamic script loading look at http://www.elasticsearch.org/blog/running-groovy-scripts-without-dynamic-scripting/ and https://github.com/pelias/scripts --- query/sort.js | 9 ++------- test/unit/query/reverse.js | 10 ++++------ test/unit/query/search.js | 7 ++----- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/query/sort.js b/query/sort.js index 7da2db5f..8ddbdfc0 100644 --- a/query/sort.js +++ b/query/sort.js @@ -4,9 +4,7 @@ var weights = require('pelias-suggester-pipeline').weights; module.exports = [ { '_script': { - 'script': 'if (doc.containsKey(\''+ population + '\'))' + - ' { return doc[\'' + population + '\'].value }' + - ' else { return 0 }', + 'file': 'population', 'type': 'number', 'order': 'desc' } @@ -16,10 +14,7 @@ module.exports = [ 'params': { 'weights': weights }, - 'script': 'if (doc.containsKey(\'_type\')) { '+ - 'type=doc[\'_type\'].value; '+ - 'return ( type in weights ) ? weights[ type ] : 0 }' + - 'else { return 0 }', + 'file': 'weights', 'type': 'number', 'order': 'desc' } diff --git a/test/unit/query/reverse.js b/test/unit/query/reverse.js index fb423895..a8d6d327 100644 --- a/test/unit/query/reverse.js +++ b/test/unit/query/reverse.js @@ -11,9 +11,10 @@ module.exports.tests.interface = function(test, common) { }; var sort = [ + '_score', { '_script': { - 'script': 'if (doc.containsKey(\'population\')) { return doc[\'population\'].value } else { return 0 }', + 'file': 'population', 'type': 'number', 'order': 'desc' } @@ -35,10 +36,7 @@ var sort = [ 'admin0': 2 } }, - 'script': 'if (doc.containsKey(\'_type\')) { '+ - 'type=doc[\'_type\'].value; '+ - 'return ( type in weights ) ? weights[ type ] : 0 }'+ - 'else { return 0 }', + 'file': 'weights', 'type': 'number', 'order': 'desc' } @@ -89,7 +87,7 @@ module.exports.tests.query = function(test, common) { 'unit': 'km' } } - ].concat(sort), + ].concat(sort.slice(1)), 'size': 1, 'track_scores': true }; diff --git a/test/unit/query/search.js b/test/unit/query/search.js index dc1f504e..2d99d0ff 100644 --- a/test/unit/query/search.js +++ b/test/unit/query/search.js @@ -14,7 +14,7 @@ var sort = [ '_score', { '_script': { - 'script': 'if (doc.containsKey(\'population\')) { return doc[\'population\'].value } else { return 0 }', + 'file': 'population', 'type': 'number', 'order': 'desc' } @@ -36,10 +36,7 @@ var sort = [ 'admin0': 2 } }, - 'script': 'if (doc.containsKey(\'_type\')) { '+ - 'type=doc[\'_type\'].value; '+ - 'return ( type in weights ) ? weights[ type ] : 0 }'+ - 'else { return 0 }', + 'file': 'weights', 'type': 'number', 'order': 'desc' }