So i am using this library for elastic search in codeigniter. and i want to return documents with size of 30
public function index()
{
$data = $this->data;
$query = '{
"query" : {
"match" : {
"sch_id" : 45
}
}
}';
echo "<pre>";
var_dump($data['elastic']->query_wresultSize('_search',$query,30));
echo "</pre>";
// return view('dashboard/dashboard',$data);
}
But now it shows an error
["root_cause"]=>
array(1) {
[0]=>
array(4) {
["type"]=>
string(21) "query_shard_exception"
["reason"]=>
string(90) "Failed to parse query [{
"query" : {
"match" : {
"sch_id" : 45
}
}
}]"
["index_uuid"]=>
string(22) "xbrATjiKR_uKtAGN3-GrRw"
["index"]=>
string(7) "article"
}
}
["reason"]=>
string(90) "Failed to parse query [{
"query" : {
"match" : {
"sch_id" : 45
}
}
}]"
["index_uuid"]=>
string(22) "xbrATjiKR_uKtAGN3-GrRw"
["index"]=>
string(7) "article"
["caused_by"]=>
array(3) {
["type"]=>
string(15) "parse_exception"
["reason"]=>
string(170) "Cannot parse '{
"query" : {
"match" : {
"sch_id" : 45
}
}
}': Encountered " ": "" at line 1, column 13.
Was expecting:
"TO" ...
"
i just don't know what am i doing wrong because i didn't use any reserved word in the query but it shows me the error above
can someone show me my mistake or tell me an alternative way for this?
CodePudding user response:
I still don't know how the query in this this library works. so i used Guzzle instead. Here is my solution for anyone having the same problem.
$uri = 'http://localhost:9200/article/_search/';
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $uri, [
'headers' => [
'Accept' => 'application/json',
'Accept-Language' => 'en_US',
'Content-Type' => 'application/json',
],
'body' => '{
"size" : 30,
"query" : {
"match" : {
"sch_id" : 45
}
}
}',
]
);
$data = json_decode($response->getBody(), true);
