我正在尝试从我的elasticsearch服务器执行建议术语查询。
以下代码是我正在尝试的内容:
//curl -X GET http://localhost:9200/{INDEX}/{TYPE}/_suggest?q= ...
function suggest($type, $q, $size=5) {
$suggestion = array('my-suggestion' => array('text' => $q,'term' => array('size' => $size, 'field' => 'title')));
return $this->call($type . '/_suggest?' . http_build_query(array('suggest' => $suggestion)));
}
返回404错误。以下是它构建的URL的示例:
http://localhost:9200/{index}/{type}/_suggest?suggest%5Bmy-suggestion%5D%5Btext%5D=test&suggest%5Bmy-suggestion%5D%5Bterm%5D%5Bsize%5D=5&suggest%5Bmy-suggestion%5D%5Bterm%5D%5Bfield%5D=title
此处概述了建议查询的具体内容:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html
以下来自同一个库的工作正常:
//curl -X GET http://localhost:9200/{INDEX}/{TYPE}/_search?q= ...
function query($type, $q, $start=0, $limit=10, $sort=null) {
if ($sort){
$sort = json_encode($sort);
return $this->call($type . '/_search?' . http_build_query(array('q' => $q, 'from' => $start, 'size' => $limit,"sort" => $sort)));
}
else
return $this->call($type . '/_search?' . http_build_query(array('q' => $q, 'from' => $start, 'size' => $limit)));
}