Skip to content

Instantly share code, notes, and snippets.

@vinh0604
Created May 21, 2017 11:41
Show Gist options
  • Select an option

  • Save vinh0604/cb1887be100a587c7034e017a26c7c67 to your computer and use it in GitHub Desktop.

Select an option

Save vinh0604/cb1887be100a587c7034e017a26c7c67 to your computer and use it in GitHub Desktop.
Medium code sample - Refactoring legacy code base
// adding region filter to the request
// if region is not provided, considering it as select all
if (regions === null || regions.length === 0) {
request.filter.bool.must.push({
match: {
region: 'all'
}
})
} else {
regions.forEach((region) => {
request.filter.bool.must.push({
match: {
region: region
}
})
})
}
// adding price filter to the request
// if min price is not provided, considering it as 0
// if max price is not provided, considering it as INFINITE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment