无法分析elasticsearch和Codeigniter中的查询



所以我在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" ...
"

我只是不知道我做错了什么,因为我在查询中没有使用任何保留字,但它显示了上面的错误

有人能告诉我我的错误,或者告诉我另一种方法吗?

我仍然不知道这个库中的查询是如何工作的。所以我用了Guzzle。这是我为任何有同样问题的人提供的解决方案。

$uri = 'http://localhost:9200/article/_search/';
$client = new GuzzleHttpClient();
$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);

最新更新