Skip to content

Instantly share code, notes, and snippets.

@sl-digital
Created June 14, 2017 21:44
Show Gist options
  • Save sl-digital/b760f1d1a90848ed7566cb533e14e60d to your computer and use it in GitHub Desktop.
Save sl-digital/b760f1d1a90848ed7566cb533e14e60d to your computer and use it in GitHub Desktop.
ElasticSearch Query String Search
$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