【发布时间】:2020-09-30 02:02:00
【问题描述】:
我添加了一些产品,例如“lcd apple iphone 11”“lcd apple iphone x”“lcd apple iphone xs”“lcd apple iphone xr”“lcd samsung s8”“lcd samsung s8+”“lcd apple iphone xs max” 'lcd apple iphone xr 电池' 我们上次添加了 iphone xr 产品
我已创建弹性搜索索引products_idx1 并输入product。
当我搜索 apple iphone xr 之类的产品时,它会返回 iphone xr 但不会排在首位。
我想要什么 确切的结果应该在前,部分结果应该在确切的结果之后。我想根据准确度结果对结果进行排序。
这是我在 php elasticsearch 中的代码
<?php
use Elasticsearch\ClientBuilder;
require 'vendor/autoload.php';
$client = ClientBuilder::create()->build();
$values =['name','name.prefix','name.suffix','sku'];
$params =
[
'client'=>['verify'=>1,'connect_timeout'=>5],
'from'=> 0,
'size'=>25,
'body' =>[
'query' => [
'bool'=>
[
'should'=> [[
'multi_match'=> ['query'=>'apple iphone xr','type'=>'cross_fields','fields'=>$values,'operator'=>'AND']
],
['match'=>['all'=>['query'=>'apple iphone xr','operator'=>'AND','fuzziness'=>'AUTO'] ]]
]
]
],
'sort'=>['_score'=>['order'=>'desc']],
],
'index'=>'products_idx1'
];
$response = $client->search($params);
echo "<pre>";print_r($response);
【问题讨论】:
标签: sorting elasticsearch resultset exact-match