Created
June 14, 2017 21:44
-
-
Save sl-digital/b760f1d1a90848ed7566cb533e14e60d to your computer and use it in GitHub Desktop.
ElasticSearch Query String Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$default = [ | |
"query_string" => [ | |
"default_operator" => "AND", | |
"fields" => ["name","desc","tags","city"], | |
"query" => $query | |
] | |
]; | |
$filtered = [ | |
"bool" => [ | |
"must" => [ | |
["query_string" => [ | |
"default_operator" => "AND", | |
"fields" => ["name","desc","tags","city"], | |
"query" => $query | |
]] | |
], | |
"filter" => [ | |
["terms" => ["region" => $regions]] | |
] | |
] | |
]; | |
$params = [ | |
"index" => "listings", | |
"body" => [ | |
"from" => ($page - 1) * $size, | |
"size" => $size, | |
"query" => $default | |
] | |
]; | |
if( !empty($types) ){ | |
$params["type"] = implode(",", $types); | |
} | |
if( !empty($regions) ){ | |
$params["body"]["query"] = $filtered; | |
} | |
return $this->client->search($params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment