elasticsearch 具有辅助搜索顺序的弹性搜索自动完成,elasticsearch,autocomplete,elasticsearch,Autocomplete" /> elasticsearch 具有辅助搜索顺序的弹性搜索自动完成,elasticsearch,autocomplete,elasticsearch,Autocomplete" />

elasticsearch 具有辅助搜索顺序的弹性搜索自动完成

elasticsearch 具有辅助搜索顺序的弹性搜索自动完成,elasticsearch,autocomplete,elasticsearch,Autocomplete,我只是通过弹性搜索工作,需要一些自动完成功能的帮助 基本上,我有自动完成功能,但我想使用我的填充字段来添加二级排序顺序。但是,当我向查询中插入排序参数时,它会给我一条400错误消息。您能看一下我的映射和查询,看看它们是否设置正确,并建议我需要做些什么来实现这一点吗 非常感谢 映射: PUT /ff_search_locations2?pretty { "mappings": { "1": { "_all": { "enabled": false

我只是通过弹性搜索工作,需要一些自动完成功能的帮助

基本上,我有自动完成功能,但我想使用我的填充字段来添加二级排序顺序。但是,当我向查询中插入排序参数时,它会给我一条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);
    }
}
错误报告(-1);
ini_设置(“显示错误”、“打开”);
$db=“my_db”;
$link=mysqli_connect(“localhost”、“user”、“pass”、“$db”)或die(mysql_error());
$result=mysqli_query($link,“SELECT*fromsearch_locations6 ORDER BY Population DESC”)或die(mysql_error());
while($row=mysqli\u fetch\u数组($result))
{
$ii++;
$i++;
$data_数组=数组(“城市”=>$row['city'],“县”=>$row['city'],“地区”=>$row['region'],“国家”=>$row['COUNDED'],“联合”=>$row['COMPONED'],“城市”=>$row['city'UC'],“人口”=>$row['人口],“地点”=>数组(“lat”=>$row['lat'],“lon”=>$row['lon']);
//分块进行,不想改变堆大小…等等。
如果($i<10000)
{
$json_data='{“索引”:{“_id”:“.$ii.'}}”;
$json_数据=“\n”;
$json_data.=json_encode($data_数组);
$json_数据=“\n”;
文件内容('bulk.php',$json\u数据,文件附加);
}
其他的
{
exec('curl--fail--silent--show error-XPOST'localhost:9200/ff_search\u locations2/1/_bulk?pretty&refresh\'--data binary“@bulk.php”);
取消链接('bulk.php');
未结算(一美元);
}
}

建议查询不支持排序顺序。建议的全部要点是速度,向混合中添加排序将减慢速度

您可以向查询中添加
权重
,以提高排名,但不能添加辅助排序索引。如果您正在寻找辅助排序,我建议您可以使用
search

编辑:查看索引代码,您可以为您的
组合
字段添加
权重
,作为
总体
字段

`$data_array = array("city" => $row['city'],"county" => $row['county'],"region" => $row['region'],"country" => $row['country'],"url" => $row['url'],"combined" => array("input" => $row['combined'], "weight" => $row['Population']),"city_lc" => $row['city_lc'],"population" => $row['Population'],"location" => array("lat" => $row['lat'],"lon" => $row['long']));`

成功了!如果你能更新你的答案,比如说。。。将人口作为权重值添加到完成类型中,如下所示:
code
$data\u array=array(“城市”=>$row['city'],“县”=>$row['country'],“地区”=>$row['region'],“国家”=>$row['country'],“url”=>$row['url'],“组合”=>数组(“输入”=>$row['combined'],“权重”=>$row['populat'Population'],“城市”=>$row['city'],“population”=>$row['population'],“location”=>array(“lat”=>$row['lat'],“lon”=>$row['long']);
code
然后我会将其标记为正确答案。感谢您输入索引代码。更新了我的答案。我应该早就找到了参考资料