From 98f03d51f8ebde7f2df2294240be07be7a145c79 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Sun, 5 Apr 2015 12:56:02 +0100 Subject: [PATCH] fix bug with construction of multi-term terms queries with AND logic --- es.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/es.js b/es.js index 1eea0af..09b4e18 100644 --- a/es.js +++ b/es.js @@ -187,16 +187,18 @@ function getFilters(params) { function termsFilter(facet, filter_list) { if (facet.logic === "AND") { + var filters = []; for (var i=0; i < filter_list.length; i=i+1) { var value = filter_list[i]; var tq = {"term" : {}}; tq["term"][facet.field] = value; - return tq + filters.push(tq); } + return filters; } else if (facet.logic === "OR") { var tq = {"terms" : {}}; tq["terms"][facet.field] = filter_list; - return tq + return [tq]; } } @@ -238,7 +240,7 @@ function getFilters(params) { var filter_list = filter_definition[field]; if (facet.type === "terms") { - filters.push(termsFilter(facet, filter_list)) + filters = filters.concat(termsFilter(facet, filter_list)); // Note this is a concat not a push, unlike the others } else if (facet.type === "range") { filters.push(rangeFilter(facet, filter_list)) } else if (facet.type === "geo_distance") {