I want to put the half of query in variable $query
and put it in $params
in ElasticSearch.
This is my $query
:
if (Input::has('_id')) {
$_id = $this->input['_id'];
$path = 'data';
$field = 'data.city';
// Querying city
if (Input::has('city')) {
$city = $this->input['city'];
$query = array('query'=> [
'bool' => [
'must' => [
[
'match' => [
'_id' => $_id
]
],
[
'nested' => [
'path' => $path,
'query' => [
'bool' => [
'must' => [
[
'match' => [
$field => $city
]
]
]
]
]
]
]
]
]
]);
}
And I want to put that variable in $params
like this:
$params = [
'index' => 'channels',
'type' => 'users',
'body' => [
'from' => $defaultPerPage * ($page - 1),
'size' => $defaultPerPage,
$query
]
];
I try to print_r($params)
and got the right result.
But I always got the error notification when try do query.
Anyone knows how to do it ?
Thanks
Error :
{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[6fZ0ud3kSTSYsMI-o-mg4w][channels][0]: SearchParseException[[channels][0]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"0\":{\"query\":{\"bool\":{\"must\":[{\"match\":{\"_id\":\"9121200asda121\"}},{\"nested\":{\"path\":\"data\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"data.city\":\"california\"}}]}}}}]}}}}]]]; nested: SearchParseException[[channels][0]: from[0],size[10]: Parse Failure [No parser for element [0]]]; }{[W5E62t0EQ16lckCUnf8atw][channels][1]: RemoteTransportException[[Bima][inet[/10.200.7.69:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[channels][1]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"0\":{\"query\":{\"bool\":{\"must\":[{\"match\":{\"_id\":\"9121200asda121\"}},{\"nested\":{\"path\":\"data\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"data.city\":\"california\"}}]}}}}]}}}}]]]; nested: SearchParseException[[channels][1]: from[0],size[10]: Parse Failure [No parser for element [0]]]; }{[6fZ0ud3kSTSYsMI-o-mg4w][channels][2]: SearchParseException[[channels][2]: from[0],size[10]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":10,\"0\":{\"query\":{\"bool\":{\"must\":[{\"match\":{\"_id\":\"9121200asda121\"}},{\"nested\":{\"path\":\"data\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"data.city\":\"california\"}}]}}}}]}}}}]]]; nested: SearchParseException[[channels][2]: from[0],size[10]: Parse Failure [No parser for element [0]]]; }]","status":400}