Skip to content

Commit ac813b3

Browse files
Small fix on search ES query
1 parent 9dcb15b commit ac813b3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/services/ChallengeService.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,25 @@ async function searchChallenges (currentUser, criteria) {
171171
})
172172
}
173173

174+
const finalQuery = {
175+
bool: {}
176+
}
177+
178+
if (mustQuery.length > 0) {
179+
finalQuery.bool.must = { ...mustQuery }
180+
}
181+
182+
if (!_.isUndefined(mustNotQuery)) {
183+
finalQuery.bool.must_not = { ...mustNotQuery }
184+
}
185+
174186
const esQuery = {
175187
index: config.get('ES.ES_INDEX'),
176188
type: config.get('ES.ES_TYPE'),
177189
size: criteria.perPage,
178190
from: (criteria.page - 1) * criteria.perPage, // Es Index starts from 0
179191
body: {
180-
query: mustQuery.length > 0 || !_.isUndefined(mustNotQuery) ? {
181-
bool: {
182-
must: mustQuery,
183-
must_not: mustNotQuery
184-
}
185-
} : {
192+
query: mustQuery.length > 0 || !_.isUndefined(mustNotQuery) ? finalQuery : {
186193
match_all: {}
187194
},
188195
sort: [{ 'created': { 'order': 'asc', 'missing': '_last', 'unmapped_type': 'String' } }]

0 commit comments

Comments
 (0)