From 2127ebe258f2ab48f0d3ede84c4fb7731690d6bc Mon Sep 17 00:00:00 2001 From: Harish Krishna Date: Tue, 17 Feb 2015 19:25:09 -0500 Subject: [PATCH] switching to bool with a 'must' match (AND) and a few 'should's (OR) --- query/search.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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);