Skip to content

Instantly share code, notes, and snippets.

@radzserg
Last active January 10, 2017 19:00
Show Gist options
  • Select an option

  • Save radzserg/635aa1540159524ffde38587b10ac210 to your computer and use it in GitHub Desktop.

Select an option

Save radzserg/635aa1540159524ffde38587b10ac210 to your computer and use it in GitHub Desktop.
An example of building ES query for raw user input.
<?php
if (!empty($filterParams['q'])) {
$query = CMap::mergeArray($query, [
[
'bool' => [
'should' => [
['match' => ['name' => ['query' => $filterParams['q'], 'boost' => 5]]],
['match' => ['short_description' => ['query' => $filterParams['q'], 'boost' => 3]]],
['match' => ['tag_names' => ['query' => $filterParams['q'], 'boost' => 1]]]
]
]
]
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment