Browse Source

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

using-pelias-ngram
Harish Krishna 10 years ago
parent
commit
aa721b8749
  1. 9
      query/sort.js
  2. 10
      test/unit/query/reverse.js
  3. 7
      test/unit/query/search.js

9
query/sort.js

@ -4,9 +4,7 @@ var weights = require('pelias-suggester-pipeline').weights;
module.exports = [ module.exports = [
{ {
'_script': { '_script': {
'script': 'if (doc.containsKey(\''+ population + '\'))' + 'file': 'population',
' { return doc[\'' + population + '\'].value }' +
' else { return 0 }',
'type': 'number', 'type': 'number',
'order': 'desc' 'order': 'desc'
} }
@ -16,10 +14,7 @@ module.exports = [
'params': { 'params': {
'weights': weights 'weights': weights
}, },
'script': 'if (doc.containsKey(\'_type\')) { '+ 'file': 'weights',
'type=doc[\'_type\'].value; '+
'return ( type in weights ) ? weights[ type ] : 0 }' +
'else { return 0 }',
'type': 'number', 'type': 'number',
'order': 'desc' 'order': 'desc'
} }

10
test/unit/query/reverse.js

@ -11,9 +11,10 @@ module.exports.tests.interface = function(test, common) {
}; };
var sort = [ var sort = [
'_score',
{ {
'_script': { '_script': {
'script': 'if (doc.containsKey(\'population\')) { return doc[\'population\'].value } else { return 0 }', 'file': 'population',
'type': 'number', 'type': 'number',
'order': 'desc' 'order': 'desc'
} }
@ -35,10 +36,7 @@ var sort = [
'admin0': 2 'admin0': 2
} }
}, },
'script': 'if (doc.containsKey(\'_type\')) { '+ 'file': 'weights',
'type=doc[\'_type\'].value; '+
'return ( type in weights ) ? weights[ type ] : 0 }'+
'else { return 0 }',
'type': 'number', 'type': 'number',
'order': 'desc' 'order': 'desc'
} }
@ -89,7 +87,7 @@ module.exports.tests.query = function(test, common) {
'unit': 'km' 'unit': 'km'
} }
} }
].concat(sort), ].concat(sort.slice(1)),
'size': 1, 'size': 1,
'track_scores': true 'track_scores': true
}; };

7
test/unit/query/search.js

@ -14,7 +14,7 @@ var sort = [
'_score', '_score',
{ {
'_script': { '_script': {
'script': 'if (doc.containsKey(\'population\')) { return doc[\'population\'].value } else { return 0 }', 'file': 'population',
'type': 'number', 'type': 'number',
'order': 'desc' 'order': 'desc'
} }
@ -36,10 +36,7 @@ var sort = [
'admin0': 2 'admin0': 2
} }
}, },
'script': 'if (doc.containsKey(\'_type\')) { '+ 'file': 'weights',
'type=doc[\'_type\'].value; '+
'return ( type in weights ) ? weights[ type ] : 0 }'+
'else { return 0 }',
'type': 'number', 'type': 'number',
'order': 'desc' 'order': 'desc'
} }

Loading…
Cancel
Save