diff --git a/query/search.js b/query/search.js index 9d9916d3..7c52fcfa 100644 --- a/query/search.js +++ b/query/search.js @@ -22,12 +22,28 @@ function generate( params ){ // add search condition to distance query query.query.filtered.query = { - query_string : { - query: params.input, - fields: ['name.default'], - default_operator: 'OR' + 'bool': { + 'must': [{ + 'match': { + 'name.default': params.input + } + } + ] } }; + + if (params.input_admin) { + var admin_fields = ['admin0', 'admin1', 'alpha3']; + query.query.filtered.query.bool.should = []; + + admin_fields.forEach(function(admin_field) { + var match = {}; + match[admin_field] = params.input_admin; + query.query.filtered.query.bool.should.push({ + 'match': match + }); + }); + } query.sort = query.sort.concat(sort);