我只是通過彈性搜索的方式工作,需要一些幫助與自動完成功能。彈性搜索自動完成與輔助搜索順序
基本上,我有自動完成功能工作,但我想添加使用我的人口領域降序次要排序順序。但是,當我插入一個排序參數給我的查詢時,它給了我一個400錯誤信息。你能看看我的映射和查詢,看看它們是否設置正確,並建議我需要做些什麼來完成這項工作?
很多謝謝。
映射:
PUT /ff_search_locations2?pretty
{
"mappings": {
"1": {
"_all": {
"enabled": false
},
"properties": {
"city": {
"type": "text"
},
"county": {
"type": "text"
},
"region": {
"type": "text"
},
"country": {
"type": "text"
},
"url": {
"type": "text"
},
"combined": {
"type": "completion"
},
"city_lc": {
"type": "text"
},
"population": {
"type": "text"
},
"location": {
"type": "geo_point"
}
}
}
}
}
我的工作查詢:
POST /ff_search_locations2/_suggest?pretty&pretty
{
"1": {
"prefix": "london",
"completion": {
"field": "combined"
}
}
}
我已經試過:
POST /ff_search_locations2/_suggest?pretty&pretty
{
"1": {
"prefix": "london",
"completion": {
"field": "combined"
}
},
"sort": { "population": { "order": "desc" }}
}
和返回的錯誤:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "suggester with name [population] not supported"
}
],
"type": "illegal_argument_exception",
"reason": "suggester with name [population] not supported"
},
"status": 400
}
我使用生成索引的PHP代碼:
error_reporting(-1);
ini_set('display_errors', 'On');
$db = "my_db";
$link = mysqli_connect("localhost", "user", "pass", "$db") or die(mysql_error());
$result = mysqli_query($link, "SELECT * FROM search_locations6 ORDER BY Population DESC") or die(mysql_error());
while($row = mysqli_fetch_array($result))
{
$ii++;
$i++;
$data_array = array("city" => $row['city'],"county" => $row['county'],"region" => $row['region'],"country" => $row['country'],"url" => $row['url'],"combined" => $row['combined'],"city_lc" => $row['city_lc'],"population" => $row['Population'],"location" => array("lat" => $row['lat'],"lon" => $row['long']));
//doing it in chunks, don't feel like changing heap sizes... etc.
if($i < 10000)
{
$json_data = '{"index":{"_id":"'.$ii.'"}}';
$json_data .= "\n";
$json_data .= json_encode($data_array);
$json_data .= "\n";
file_put_contents('bulk.php', $json_data, FILE_APPEND);
}
else
{
exec('curl --fail --silent --show-error -XPOST \'localhost:9200/ff_search_locations2/1/_bulk?pretty&refresh\' --data-binary "@bulk.php"');
unlink('bulk.php');
unset($i);
}
}
參考我應該早發現[鏈接](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) –