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 = [
{
'_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'
}

10
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
};

7
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'
}

Loading…
Cancel
Save