Laravel 在ElasticSearch中仅获取特定分数匹配文档
我只想得到那些符合特定分数的文档,而不是所有文档。e、 g我想获得ElasticSearch中的所有文档,这些文档的最低分数为max_分数的25%。 假设有10个文档,其中4个文档的_分数小于最大分数的25%,而6个文档的_分数大于等于最大分数的25%,所以这里我想得到6个文档的_分数大于或等于最大分数的25% 我和拉威尔一起工作,我就是这样得到的Laravel 在ElasticSearch中仅获取特定分数匹配文档,laravel,
elasticsearch,Laravel,
elasticsearch,我只想得到那些符合特定分数的文档,而不是所有文档。e、 g我想获得ElasticSearch中的所有文档,这些文档的最低分数为max_分数的25%。 假设有10个文档,其中4个文档的_分数小于最大分数的25%,而6个文档的_分数大于等于最大分数的25%,所以这里我想得到6个文档的_分数大于或等于最大分数的25% 我和拉威尔一起工作,我就是这样得到的 $halohasList = []; $hosts = [ "host" => Constant::ESHost
$halohasList = [];
$hosts = [
"host" => Constant::ESHost
];
$client = ClientBuilder::create()->setHosts($hosts)->build();
$params = [
"index" => "halohas",
"type" => "haloha",
"body" => [
"query" => [
"bool" => [
"filter" => [
"match" => [
"haloha_id" => $userHaloha->haloha_id
]
],
// "must_not" => [
// "term" => [
// "_id" => $userHaloha->_id
// ]
// ],
"must" => [
[
"match" => [
"text" => [
"query" => $userHaloha->filtered_text,
"fuzziness" => "auto",
"max_expansions" => 2
]
]
]
],
"should" => [
"term" => [
"mood" => [
"value" => $userHaloha->mood
]
]
]
]
]
]
];
$halohas = $client->search($params);
// dd($halohas['hits']['hits']);
$maxScore = $halohas['hits']['max_score'];
$halohas = $halohas['hits']['hits'];
$scoreToCompare = 0.25 * $maxScore; //25% of max score
foreach ($halohas as $haloha) {
if ($haloha['_score'] >= $scoreToCompare)
$halohasList[] = $haloha;
}
这段代码运行得很好,但是您可以看到,仅仅因为循环,这并不是实现我想要的东西的最佳方式。
我知道ElasticSearch中存在min_分数,那么有没有办法摆脱这个循环,并使用min_分数的hep来实现这一点?i、 e获取最大分数值并将其放入最小分数,然后获取所有所需的文档
以下是我的查询的JSON版本:-
{
"query": {
"bool": {
"filter": [
{
"match": {
"haloha_id": "5f2f33c2c6f0fc27e725ee8a"
}
}
],
"must": [
{
"match": {
"text": {
"query": "passing smile each other ",
"fuzziness": "auto"
}
}
}
],
"should": [
{
"term": {
"mood": {
"value": 0
}
}
}
]
}
}
}
我希望专家们能帮助我,谢谢