所以我在codeigniter中使用這個庫進行彈性搜索。我想退回大小為 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);
}
但是現在它顯示一個錯誤
["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" ...
"
我只是不知道我做錯了什么,因為我沒有在查詢中使用任何保留字,但它向我顯示了上面的錯誤
有人可以告訴我我的錯誤或告訴我另一種方法嗎?
uj5u.com熱心網友回復:
我仍然不知道這個庫中的查詢是如何作業的。所以我用 Guzzle 代替。這是我為遇到同樣問題的人提供的解決方案。
$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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/423043.html
標籤:
